You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core.py 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import unittest
  2. import os
  3. import kosmorrolib.core as core
  4. from datetime import date
  5. from dateutil.relativedelta import relativedelta
  6. class CoreTestCase(unittest.TestCase):
  7. def test_flatten_list(self):
  8. self.assertEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], core.flatten_list([0, 1, 2, [3, 4, [5, 6], 7], 8, [9]]))
  9. def test_get_env(self):
  10. self.assertEqual(0, len(core.get_env()))
  11. os.environ['SOME_RANDOM_VAR'] = 'an awesome value'
  12. self.assertEqual(0, len(core.get_env()))
  13. os.environ['KOSMORRO_GREAT_VARIABLE'] = 'value'
  14. env = core.get_env()
  15. self.assertEqual(1, len(env))
  16. self.assertEqual('value', env.great_variable)
  17. os.environ['KOSMORRO_ANOTHER_VARIABLE'] = 'another value'
  18. env = core.get_env()
  19. self.assertEqual(2, len(env))
  20. self.assertEqual('value', env.great_variable)
  21. self.assertEqual('another value', env.another_variable)
  22. self.assertEqual("{'great_variable': 'value', 'another_variable': 'another value'}", str(env))
  23. def test_date_arg_parsing(self):
  24. self.assertEqual(core.get_date("+1y 2m3d"), date.today() + relativedelta(years=1, months=2, days=3))
  25. self.assertEqual(core.get_date("-1y2d"), date.today() - relativedelta(years=1, days=2))
  26. self.assertEqual(core.get_date("1111-11-13"), date(1111, 11, 13))
  27. if __name__ == '__main__':
  28. unittest.main()