test_utils.py 1.7KB

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