A library that computes the ephemerides.
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.
 
 

51 lines
1.5 KiB

  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(
  9. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  10. core.flatten_list([0, 1, 2, [3, 4, [5, 6], 7], 8, [9]]),
  11. )
  12. def test_get_env(self):
  13. self.assertEqual(0, len(core.get_env()))
  14. os.environ["SOME_RANDOM_VAR"] = "an awesome value"
  15. self.assertEqual(0, len(core.get_env()))
  16. os.environ["KOSMORRO_GREAT_VARIABLE"] = "value"
  17. env = core.get_env()
  18. self.assertEqual(1, len(env))
  19. self.assertEqual("value", env.great_variable)
  20. os.environ["KOSMORRO_ANOTHER_VARIABLE"] = "another value"
  21. env = core.get_env()
  22. self.assertEqual(2, len(env))
  23. self.assertEqual("value", env.great_variable)
  24. self.assertEqual("another value", env.another_variable)
  25. self.assertEqual(
  26. "{'great_variable': 'value', 'another_variable': 'another value'}", str(env)
  27. )
  28. def test_date_arg_parsing(self):
  29. self.assertEqual(
  30. core.get_date("+1y 2m3d"),
  31. date.today() + relativedelta(years=1, months=2, days=3),
  32. )
  33. self.assertEqual(
  34. core.get_date("-1y2d"), date.today() - relativedelta(years=1, days=2)
  35. )
  36. self.assertEqual(core.get_date("1111-11-13"), date(1111, 11, 13))
  37. if __name__ == "__main__":
  38. unittest.main()