utils.py 790 B

123456789101112131415161718192021222324
  1. import unittest
  2. import sys
  3. from os.path import isfile, isdir, exists, dirname
  4. test_dir = dirname(__file__)
  5. def assert_is_file(path):
  6. assert exists(path), "%s does not exist"
  7. assert isfile(path), "%s exists but is not a directory."
  8. def assert_is_dir(path):
  9. assert exists(path), "%s does not exist"
  10. assert isdir(path), "%s exists but is not a directory."
  11. def skip_on_windows(function):
  12. """Decorator to skip a test on Windows."""
  13. return unittest.skipIf(sys.platform.startswith("win"),
  14. "Test for non-Windows platforms")(function)
  15. def only_on_windows(function):
  16. """Decorator to skip a test on Windows."""
  17. return unittest.skipUnless(sys.platform.startswith("win"),
  18. "Test requires Windows")(function)