version_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import os
  2. import unittest
  3. pg_header = os.path.join('src_c', '_pygame.h')
  4. class VersionTest(unittest.TestCase):
  5. @unittest.skipIf(not os.path.isfile(pg_header),
  6. "Skipping because we cannot find _pygame.h")
  7. def test_pg_version_consistency(self):
  8. from pygame import version
  9. pgh_major = -1
  10. pgh_minor = -1
  11. pgh_patch = -1
  12. import re
  13. major_exp_search = re.compile('define\s+PG_MAJOR_VERSION\s+([0-9]+)').search
  14. minor_exp_search = re.compile('define\s+PG_MINOR_VERSION\s+([0-9]+)').search
  15. patch_exp_search = re.compile('define\s+PG_PATCH_VERSION\s+([0-9]+)').search
  16. with open(pg_header) as f:
  17. for line in f:
  18. if pgh_major == -1:
  19. m = major_exp_search(line)
  20. if m: pgh_major = int(m.group(1))
  21. if pgh_minor == -1:
  22. m = minor_exp_search(line)
  23. if m: pgh_minor = int(m.group(1))
  24. if pgh_patch == -1:
  25. m = patch_exp_search(line)
  26. if m: pgh_patch = int(m.group(1))
  27. self.assertEqual(pgh_major, version.vernum[0])
  28. self.assertEqual(pgh_minor, version.vernum[1])
  29. self.assertEqual(pgh_patch, version.vernum[2])
  30. if __name__ == '__main__':
  31. unittest.main()