| 1 |
from os import listdir |
| 2 |
import glob, os.path, py, re |
| 3 |
|
| 4 |
this_dir = os.path.realpath(os.path.dirname(__file__)) |
| 5 |
pypy_dir = os.path.realpath(os.path.join(this_dir, '..', '..')) |
| 6 |
|
| 7 |
from pypy.tool.getdocstrings import quote, triplequotes |
| 8 |
from pypy.tool.getdocstrings import mk_std_filelist |
| 9 |
|
| 10 |
class TestDocStringInserter: |
| 11 |
def setup_method(self, method): |
| 12 |
self.fd1 = file(this_dir+'/fordocstrings1', 'r') |
| 13 |
|
| 14 |
def teardown_method(self, method): |
| 15 |
self.fd1.close() |
| 16 |
|
| 17 |
def test_mkfilelist(self): |
| 18 |
l = mk_std_filelist() |
| 19 |
l.sort() |
| 20 |
type_files = os.path.join(pypy_dir, "objspace/std/*type.py") |
| 21 |
not_wanted = ["typetype.py"] |
| 22 |
check = [] |
| 23 |
for path in glob.glob(type_files): |
| 24 |
module = os.path.split(path)[1] |
| 25 |
if module not in not_wanted: |
| 26 |
check.append(module) |
| 27 |
check.sort() |
| 28 |
assert l == check |
| 29 |
|
| 30 |
def test_gottestfile(self): |
| 31 |
s = self.fd1.read() |
| 32 |
|
| 33 |
s1 = 'from pypy.objspace.std.stdtypedef import *\n\n\n# ____________________________________________________________\n\nbasestring_typedef = StdTypeDef("basestring",\n )\n' |
| 34 |
|
| 35 |
assert s == s1 |
| 36 |
|
| 37 |
|
| 38 |
def test_compile_typedef(self): |
| 39 |
match = 'basestring' |
| 40 |
s = self.fd1.read() |
| 41 |
|
| 42 |
typedef = re.compile(r"(?P<whitespace>\s*)" |
| 43 |
+ r"(?P<typeassign>" + match |
| 44 |
+ "_typedef = StdTypeDef+\s*\(\s*" |
| 45 |
+ quote + match + quote + ",)", |
| 46 |
re.DOTALL |
| 47 |
) |
| 48 |
|
| 49 |
tdsearch = typedef.search(s).group('typeassign') |
| 50 |
assert tdsearch |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|