forked from bartvdbraak/blender
8383a2d4cc
Extensions such as ".tar.gz" are now also supported. Before this patch, ensure_ext('demo.tar.gz', '.tar.gz') would return 'demo.tar.tar.gz'. This results in issues with the `ExportHelper` mix-in class; clicking an existing file in the file dialogue warns about overwriting it (highlighting the input box in red), but then saves to a different file. Also added a unit test for the new behaviour. Reviewers: mont29, campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D1498
42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
# Apache License, Version 2.0
|
|
|
|
# ./blender.bin --background -noaudio --python tests/python/bl_bpy_path.py -- --verbose
|
|
import unittest
|
|
|
|
|
|
class TestBpyPath(unittest.TestCase):
|
|
def test_ensure_ext(self):
|
|
from bpy.path import ensure_ext
|
|
|
|
# Should work with both strings and bytes.
|
|
self.assertEqual(ensure_ext('demo', '.blend'), 'demo.blend')
|
|
self.assertEqual(ensure_ext(b'demo', b'.blend'), b'demo.blend')
|
|
|
|
# Test different cases.
|
|
self.assertEqual(ensure_ext('demo.blend', '.blend'), 'demo.blend')
|
|
self.assertEqual(ensure_ext('demo.BLEND', '.blend'), 'demo.BLEND')
|
|
self.assertEqual(ensure_ext('demo.blend', '.BLEND'), 'demo.blend')
|
|
|
|
# Test empty extensions, compound extensions etc.
|
|
self.assertEqual(ensure_ext('demo', 'blend'), 'demoblend')
|
|
self.assertEqual(ensure_ext('demo', ''), 'demo')
|
|
self.assertEqual(ensure_ext('demo', '.json.gz'), 'demo.json.gz')
|
|
self.assertEqual(ensure_ext('demo.json.gz', '.json.gz'), 'demo.json.gz')
|
|
self.assertEqual(ensure_ext('demo.json', '.json.gz'), 'demo.json.json.gz')
|
|
self.assertEqual(ensure_ext('', ''), '')
|
|
self.assertEqual(ensure_ext('', '.blend'), '.blend')
|
|
|
|
# Test case-sensitive behaviour.
|
|
self.assertEqual(ensure_ext('demo', '.blend', True), 'demo.blend')
|
|
self.assertEqual(ensure_ext('demo.BLEND', '.blend', True), 'demo.BLEND.blend')
|
|
self.assertEqual(ensure_ext('demo', 'Blend', True), 'demoBlend')
|
|
self.assertEqual(ensure_ext('demoBlend', 'blend', True), 'demoBlendblend')
|
|
self.assertEqual(ensure_ext('demo', '', True), 'demo')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
|
|
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
|
|
unittest.main()
|