goldtest.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. """A test base class for tests based on gold file comparison."""
  4. import os
  5. import sys
  6. from tests.coveragetest import CoverageTest
  7. from unittest_mixins import change_dir # pylint: disable=unused-import
  8. from tests.test_farm import clean
  9. # Import helpers, eventually test_farm.py will go away.
  10. from tests.test_farm import ( # pylint: disable=unused-import
  11. compare, contains, doesnt_contain, contains_any,
  12. )
  13. class CoverageGoldTest(CoverageTest):
  14. """A test based on gold files."""
  15. run_in_temp_dir = False
  16. def setUp(self):
  17. super(CoverageGoldTest, self).setUp()
  18. self.chdir(self.root_dir)
  19. # Modules should be importable from the current directory.
  20. sys.path.insert(0, '')
  21. def output_dir(self, the_dir):
  22. """Declare where the output directory is.
  23. The output directory is deleted at the end of the test, unless the
  24. COVERAGE_KEEP_OUTPUT environment variable is set.
  25. """
  26. # To make sure tests are isolated, we always clean the directory at the
  27. # beginning of the test.
  28. clean(the_dir)
  29. if not os.environ.get("COVERAGE_KEEP_OUTPUT"): # pragma: partial
  30. self.addCleanup(clean, the_dir)