test_utils.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 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')