test_python.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. """Tests of coverage/python.py"""
  4. import os
  5. import sys
  6. from coverage.python import get_zip_bytes
  7. from tests.coveragetest import CoverageTest
  8. class GetZipBytesTest(CoverageTest):
  9. """Tests of `get_zip_bytes`."""
  10. run_in_temp_dir = False
  11. def test_get_encoded_zip_files(self):
  12. # See igor.py, do_zipmods, for the text of these files.
  13. zip_file = "tests/zipmods.zip"
  14. sys.path.append(zip_file) # So we can import the files.
  15. for encoding in ["utf8", "gb2312", "hebrew", "shift_jis", "cp1252"]:
  16. filename = zip_file + "/encoded_" + encoding + ".py"
  17. filename = filename.replace("/", os.sep)
  18. zip_data = get_zip_bytes(filename)
  19. zip_text = zip_data.decode(encoding)
  20. self.assertIn('All OK', zip_text)
  21. # Run the code to see that we really got it encoded properly.
  22. __import__("encoded_"+encoding)