test_00_globals.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # Copyright 2013 Eygene A. Ryabinkin
  3. from offlineimap import globals
  4. import unittest
  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(klass):
  13. klass.o = Opt()
  14. globals.set_options (klass.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. a = globals.options.nosuchoption
  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)