bl_pyapi_bpy_path.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Apache License, Version 2.0
  2. # ./blender.bin --background -noaudio --python tests/python/bl_pyapi_bpy_path.py -- --verbose
  3. import unittest
  4. class TestBpyPath(unittest.TestCase):
  5. def test_ensure_ext(self):
  6. from bpy.path import ensure_ext
  7. # Should work with both strings and bytes.
  8. self.assertEqual(ensure_ext('demo', '.blend'), 'demo.blend')
  9. self.assertEqual(ensure_ext(b'demo', b'.blend'), b'demo.blend')
  10. # Test different cases.
  11. self.assertEqual(ensure_ext('demo.blend', '.blend'), 'demo.blend')
  12. self.assertEqual(ensure_ext('demo.BLEND', '.blend'), 'demo.BLEND')
  13. self.assertEqual(ensure_ext('demo.blend', '.BLEND'), 'demo.blend')
  14. # Test empty extensions, compound extensions etc.
  15. self.assertEqual(ensure_ext('demo', 'blend'), 'demoblend')
  16. self.assertEqual(ensure_ext('demo', ''), 'demo')
  17. self.assertEqual(ensure_ext('demo', '.json.gz'), 'demo.json.gz')
  18. self.assertEqual(ensure_ext('demo.json.gz', '.json.gz'), 'demo.json.gz')
  19. self.assertEqual(ensure_ext('demo.json', '.json.gz'), 'demo.json.json.gz')
  20. self.assertEqual(ensure_ext('', ''), '')
  21. self.assertEqual(ensure_ext('', '.blend'), '.blend')
  22. # Test case-sensitive behaviour.
  23. self.assertEqual(ensure_ext('demo', '.blend', True), 'demo.blend')
  24. self.assertEqual(ensure_ext('demo.BLEND', '.blend', True), 'demo.BLEND.blend')
  25. self.assertEqual(ensure_ext('demo', 'Blend', True), 'demoBlend')
  26. self.assertEqual(ensure_ext('demoBlend', 'blend', True), 'demoBlendblend')
  27. self.assertEqual(ensure_ext('demo', '', True), 'demo')
  28. if __name__ == '__main__':
  29. import sys
  30. sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
  31. unittest.main()