Parcourir la source

synergine2_cocos2d/util.py: Handle trailing '/'

Tom Low-Shang il y a 6 ans
Parent
révision
3418c5494f
2 fichiers modifiés avec 7 ajouts et 2 suppressions
  1. 2 1
      synergine2_cocos2d/util.py
  2. 5 1
      tests/test_utils.py

+ 2 - 1
synergine2_cocos2d/util.py Voir le fichier

@@ -10,7 +10,8 @@ from synergine2_cocos2d.exception import FileNotFound
10 10
 
11 11
 def get_map_file_path_from_dir(map_dir_path: str) -> str:
12 12
     # TODO: path is temp here
13
-    return '{}.tmx'.format(os.path.join(map_dir_path, os.path.basename(map_dir_path)))
13
+    return '{}.tmx'.format(os.path.join(map_dir_path,
14
+        os.path.basename(map_dir_path.rstrip('/'))))
14 15
 
15 16
 
16 17
 class PathManager(object):

+ 5 - 1
tests/test_utils.py Voir le fichier

@@ -5,7 +5,7 @@ import pytest
5 5
 
6 6
 from synergine2.utils import ChunkManager
7 7
 from synergine2_cocos2d.exception import FileNotFound
8
-from synergine2_cocos2d.util import PathManager
8
+from synergine2_cocos2d.util import PathManager,get_map_file_path_from_dir
9 9
 from tests import BaseTest
10 10
 
11 11
 
@@ -44,3 +44,7 @@ class TestUtils(BaseTest):
44 44
         path_manager.add_included_path('tests/fixtures/some_media2')
45 45
         # it is prior on path finding
46 46
         assert 'tests/fixtures/some_media2/foo.txt' == path_manager.path('foo.txt')
47
+
48
+    def test_get_map_file_path_from_dir(self):
49
+        assert get_map_file_path_from_dir('map/003') == 'map/003/003.tmx'
50
+        assert get_map_file_path_from_dir('map/003/') == 'map/003/003.tmx'