summaryrefslogtreecommitdiff
path: root/test-chill/unit-tests/test__extract.py
blob: 72cba8a67933bc03012e1d429db1a2bec8a78189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import ast
import unittest

import testchill._extract as _extract
import testchill.util as util

class TestExtraction(unittest.TestCase):
    def setUp(self):
        self._TagExtractor_parse_test_data = [
                (('a',''),                      []),
                (('a','x<a>yy</a>z'),           [('yy', {})]),
                (('a','x<a>yy</a>z<a>ww</a>g'), [('yy', {}), ('ww',{})]),
                (('a','x<a>yy</a>z<b>ww</b>g'), [('yy', {})])
            ]
        self._commented_test_data = [
                (('no comment here','cc'), []),
                (('one comment //xxx\n','cc'), ['xxx']),
                (('two comments //xxx\nunrelated//yyy\n', 'cc'), ['xxx','yyy']),
                (('two comments //xxx\nunrelated//yyy', 'cc'), ['xxx','yyy']),
                (('ss/*x\ny\n*/z','cc'),['x\ny\n']),
                (('ss/*x\ny\n*/z//q\nc','cc'),['x\ny\n','q']),
                (('ss###x#\n','py'),['x#']),
                (('ss"""x"""\n','py'),['x'])
            ]
    
    def test__commented(self):
        def run(txt, ext):
            return list(_extract._TagExtractor._commented(txt, ext))
        for args, res in self._commented_test_data:
            self.assertEqual(run(*args), res)
    
    #def test_extract(self):
    #    def testfunc(tag, txt):
    #        temp = util.mktemp()
    #        with open(temp, 'w') as f:
    #            f.write(txt)
    #        extracted = _extract._TagExtractor.extract_tag(tag, temp)
    #        util.rmtemp()
    #        return extracted
    #        
    #    for args, res in self.test_extract_data:
    #        self.assertEqual(testfunc(*args), res)
    
    def test__TagExtractor_parse(self):
        def testfunc(tag, txt):
            return _extract._TagExtractor._parse(tag, txt)
        for args, exp in self._TagExtractor_parse_test_data:
            self.assertEqual(testfunc(*args), exp)