2013-02-05 04:49:56 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2013 Eygene A. Ryabinkin
|
|
|
|
|
|
|
|
import unittest
|
2020-08-29 21:10:16 +02:00
|
|
|
from offlineimap import globals
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
2013-02-05 04:49:56 +01:00
|
|
|
class Opt:
|
2020-08-29 20:27:10 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.one = "baz"
|
|
|
|
self.two = 42
|
|
|
|
self.three = True
|
2013-02-05 04:49:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestOfflineimapGlobals(unittest.TestCase):
|
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(klass):
|
|
|
|
klass.o = Opt()
|
|
|
|
globals.set_options(klass.o)
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_initial_state(self):
|
|
|
|
for k in self.o.__dict__.keys():
|
|
|
|
self.assertTrue(getattr(self.o, k) ==
|
|
|
|
getattr(globals.options, k))
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_object_changes(self):
|
|
|
|
self.o.one = "one"
|
|
|
|
self.o.two = 119
|
|
|
|
self.o.three = False
|
|
|
|
return self.test_initial_state()
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_modification(self):
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
globals.options.two = True
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_deletion(self):
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
del globals.options.three
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_nonexistent_key(self):
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
a = globals.options.nosuchoption
|
2013-02-05 04:49:56 +01:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
def test_double_init(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
globals.set_options(True)
|
2013-02-05 04:49:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-08-29 20:27:10 +02:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestOfflineimapGlobals)
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|