PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/tool/test/test_getdocstrings.py

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