PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/tool/test/test_getdocstrings.py

https://bitbucket.org/bwesterb/pypy
Python | 56 lines | 38 code | 18 blank | 0 comment | 4 complexity | f787134a48af1ca1a40481d7dcc520d5 MD5 | raw file
  1. from os import listdir
  2. import glob, os.path, py, re
  3. this_dir = os.path.realpath(os.path.dirname(__file__))
  4. pypy_dir = os.path.realpath(os.path.join(this_dir, '..', '..'))
  5. from pypy.tool.getdocstrings import quote, triplequotes
  6. from pypy.tool.getdocstrings import mk_std_filelist
  7. class TestDocStringInserter:
  8. def setup_method(self, method):
  9. self.fd1 = file(this_dir+'/fordocstrings1', 'r')
  10. def teardown_method(self, method):
  11. self.fd1.close()
  12. def test_mkfilelist(self):
  13. l = mk_std_filelist()
  14. l.sort()
  15. type_files = os.path.join(pypy_dir, "objspace/std/*type.py")
  16. not_wanted = ["typetype.py"]
  17. check = []
  18. for path in glob.glob(type_files):
  19. module = os.path.split(path)[1]
  20. if module not in not_wanted:
  21. check.append(module)
  22. check.sort()
  23. assert l == check
  24. def test_gottestfile(self):
  25. s = self.fd1.read() # whole file as string
  26. s1 = 'from pypy.objspace.std.stdtypedef import *\n\n\n# ____________________________________________________________\n\nbasestring_typedef = StdTypeDef("basestring",\n )\n'
  27. assert s == s1
  28. def test_compile_typedef(self):
  29. match = 'basestring'
  30. s = self.fd1.read()
  31. typedef = re.compile(r"(?P<whitespace>\s*)"
  32. + r"(?P<typeassign>" + match
  33. + "_typedef = StdTypeDef+\s*\(\s*"
  34. + quote + match + quote + ",)",
  35. re.DOTALL
  36. )
  37. tdsearch = typedef.search(s).group('typeassign')
  38. assert tdsearch