test_00_globals.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. # Copyright 2013 Eygene A. Ryabinkin
  3. import unittest
  4. from offlineimap import globals
  5. class Opt:
  6. def __init__(self):
  7. self.one = "baz"
  8. self.two = 42
  9. self.three = True
  10. class TestOfflineimapGlobals(unittest.TestCase):
  11. @classmethod
  12. def setUpClass(cls):
  13. cls.o = Opt()
  14. globals.set_options(cls.o)
  15. def test_initial_state(self):
  16. for k in self.o.__dict__.keys():
  17. self.assertTrue(getattr(self.o, k) ==
  18. getattr(globals.options, k))
  19. def test_object_changes(self):
  20. self.o.one = "one"
  21. self.o.two = 119
  22. self.o.three = False
  23. return self.test_initial_state()
  24. def test_modification(self):
  25. with self.assertRaises(AttributeError):
  26. globals.options.two = True
  27. def test_deletion(self):
  28. with self.assertRaises(RuntimeError):
  29. del globals.options.three
  30. def test_nonexistent_key(self):
  31. with self.assertRaises(AttributeError):
  32. raise AttributeError
  33. def test_double_init(self):
  34. with self.assertRaises(ValueError):
  35. globals.set_options(True)
  36. if __name__ == "__main__":
  37. suite = unittest.TestLoader().loadTestsFromTestCase(TestOfflineimapGlobals)
  38. unittest.TextTestRunner(verbosity=2).run(suite)