File: test_getdocstrings.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (56 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download | duplicates (10)
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
49
50
51
52
53
54
55
56
from os import listdir
import glob, os.path, py, re

this_dir = os.path.realpath(os.path.dirname(__file__))
pypy_dir = os.path.realpath(os.path.join(this_dir, '..', '..'))

from pypy.tool.getdocstrings import quote, triplequotes
from pypy.tool.getdocstrings import mk_std_filelist

class TestDocStringInserter:
    def setup_method(self, method):
        self.fd1 = file(this_dir+'/fordocstrings1', 'r')
 
    def teardown_method(self, method):
        self.fd1.close()

    def test_mkfilelist(self):
        l = mk_std_filelist()
        l.sort()
        type_files = os.path.join(pypy_dir, "objspace/std/*type.py")
        not_wanted = ["typetype.py"]
        check = []
        for path in glob.glob(type_files):
            module = os.path.split(path)[1]
            if module not in not_wanted:
                check.append(module)
        check.sort()
        assert l == check

    def test_gottestfile(self):
        s = self.fd1.read()       # whole file as string

        s1 = 'from pypy.objspace.std.stdtypedef import *\n\n\n# ____________________________________________________________\n\nbasestring_typedef = StdTypeDef("basestring",\n    )\n'
        
        assert s == s1


    def test_compile_typedef(self):
        match = 'basestring'
        s = self.fd1.read()
        
        typedef = re.compile(r"(?P<whitespace>\s*)"
                            + r"(?P<typeassign>" + match
                            + "_typedef = StdTypeDef+\s*\(\s*"
                            + quote + match +  quote + ",)",
                            re.DOTALL
                             )
        
        tdsearch = typedef.search(s).group('typeassign')
        assert tdsearch