test_utils.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # coding: utf-8
  2. import os
  3. import pytest
  4. from synergine2.utils import ChunkManager
  5. from synergine2_cocos2d.exception import FileNotFound
  6. from synergine2_cocos2d.util import PathManager,get_map_file_path_from_dir
  7. from tests import BaseTest
  8. class TestUtils(BaseTest):
  9. def test_chunk_manager_round(self):
  10. chunk_manager = ChunkManager(4)
  11. data = list(range(100))
  12. chunks = chunk_manager.make_chunks(data)
  13. assert len(chunks) == 4
  14. for chunk in chunks:
  15. assert len(chunk) == 25
  16. def test_chunk_manager_not_round(self):
  17. chunk_manager = ChunkManager(4)
  18. data = list(range(101))
  19. chunks = chunk_manager.make_chunks(data)
  20. assert len(chunks) == 4
  21. for chunk_number, chunk in enumerate(chunks):
  22. if chunk_number == 3:
  23. assert len(chunk) == 26
  24. else:
  25. assert len(chunk) == 25
  26. def test_path_manager(self):
  27. path_manager = PathManager(['tests/fixtures/some_media'])
  28. # file in thirst dir found
  29. assert 'tests/fixtures/some_media/foo.txt' == path_manager.path('foo.txt')
  30. # a non existing file is not found
  31. with pytest.raises(FileNotFound):
  32. path_manager.path('UNKNOWN')
  33. # if add a folder to path manager paths
  34. path_manager.add_included_path('tests/fixtures/some_media2')
  35. # it is prior on path finding
  36. assert 'tests/fixtures/some_media2/foo.txt' == path_manager.path('foo.txt')
  37. def test_get_map_file_path_from_dir(self):
  38. assert get_map_file_path_from_dir('map/003') == 'map/003/003.tmx'
  39. assert get_map_file_path_from_dir('map/003/') == 'map/003/003.tmx'