test_supertux.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. # Flexlay - A Generic 2D Game Editor
  3. # Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. import io
  18. import os
  19. import unittest
  20. import unittest.mock
  21. from flexlay.util.config import Config
  22. from flexlay.math import Point, Pointf, Size
  23. from supertux.gameobj_factor import supertux_gameobj_factory
  24. from supertux.level import Level
  25. test_levelfile = os.path.join(os.path.dirname(__file__), "test.stl")
  26. class SuperTuxTestCase(unittest.TestCase):
  27. def setUp(self) -> None:
  28. Config.create("supertux-editor")
  29. def tearDown(self) -> None:
  30. Config.current = None
  31. def test_level_load(self) -> None:
  32. level = Level.from_file(test_levelfile)
  33. self.assertEqual(level.name, "Welcome to Antarctica")
  34. def test_level_save(self) -> None:
  35. level = Level.from_file(test_levelfile)
  36. # with open("/tmp/test.stl", "w") as out:
  37. with io.StringIO() as out:
  38. level.save_io(out)
  39. # print(out.getvalue())
  40. def test_level_new(self) -> None:
  41. level = Level.from_size(400, 300)
  42. self.assertEqual(level.name, "No Name")
  43. def test_gameobj_factory_create_object_brushes(self) -> None:
  44. supertux_gameobj_factory.create_object_brushes()
  45. def test_gameobj_factory_create_gameobj_at(self) -> None:
  46. for identifier, (_, _) in supertux_gameobj_factory.objects.items():
  47. try:
  48. _ = supertux_gameobj_factory.create_gameobj_at(identifier, Pointf(0, 0))
  49. except Exception:
  50. print(f"Exception received: {identifier}")
  51. raise
  52. def test_level_resize(self) -> None:
  53. level = Level.from_file(test_levelfile)
  54. level.sectors[0].resize(Size(10, 10), Point(10, 10))
  55. if __name__ == '__main__':
  56. unittest.main()
  57. # EOF #