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