qubes/tests: add some tests for qubes.property
This commit is contained in:
parent
b442fb0fab
commit
74c3126b80
@ -11,7 +11,7 @@ import qubes.vm
|
|||||||
|
|
||||||
import qubes.tests
|
import qubes.tests
|
||||||
|
|
||||||
class TC_10_Label(qubes.tests.QubesTestCase):
|
class TC_00_Label(qubes.tests.QubesTestCase):
|
||||||
def test_000_constructor(self):
|
def test_000_constructor(self):
|
||||||
label = qubes.Label(1, '#cc0000', 'red')
|
label = qubes.Label(1, '#cc0000', 'red')
|
||||||
|
|
||||||
@ -40,13 +40,113 @@ class TC_10_Label(qubes.tests.QubesTestCase):
|
|||||||
self.assertEqual(label.icon_dispvm, 'dispvm-red')
|
self.assertEqual(label.icon_dispvm, 'dispvm-red')
|
||||||
|
|
||||||
|
|
||||||
|
class TC_10_property(qubes.tests.QubesTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
try:
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1')
|
||||||
|
except:
|
||||||
|
self.skipTest('TestHolder class definition failed')
|
||||||
|
self.holder = TestHolder(None)
|
||||||
|
|
||||||
|
def test_000_init(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_001_hash(self):
|
||||||
|
hash(self.holder.__class__.testprop1)
|
||||||
|
|
||||||
|
def test_002_eq(self):
|
||||||
|
self.assertEquals(qubes.property('testprop2'),
|
||||||
|
qubes.property('testprop2'))
|
||||||
|
|
||||||
|
def test_010_set(self):
|
||||||
|
self.holder.testprop1 = 'testvalue'
|
||||||
|
self.assertEventFired(self.holder, 'property-pre-set:testprop1')
|
||||||
|
self.assertEventFired(self.holder, 'property-set:testprop1')
|
||||||
|
|
||||||
|
def test_020_get(self):
|
||||||
|
self.holder.testprop1 = 'testvalue'
|
||||||
|
self.assertEqual(self.holder.testprop1, 'testvalue')
|
||||||
|
|
||||||
|
def test_021_get_unset(self):
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
self.holder.testprop1
|
||||||
|
|
||||||
|
def test_022_get_default(self):
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1', default='defaultvalue')
|
||||||
|
holder = TestHolder(None)
|
||||||
|
|
||||||
|
self.assertEqual(holder.testprop1, 'defaultvalue')
|
||||||
|
|
||||||
|
def test_023_get_default_func(self):
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1', default=(lambda self: 'defaultvalue'))
|
||||||
|
holder = TestHolder(None)
|
||||||
|
|
||||||
|
self.assertEqual(holder.testprop1, 'defaultvalue')
|
||||||
|
holder.testprop1 = 'testvalue'
|
||||||
|
self.assertEqual(holder.testprop1, 'testvalue')
|
||||||
|
|
||||||
|
def test_030_set_setter(self):
|
||||||
|
def setter(self2, prop, value):
|
||||||
|
self.assertIs(self2, holder)
|
||||||
|
self.assertIs(prop, TestHolder.testprop1)
|
||||||
|
self.assertEquals(value, 'testvalue')
|
||||||
|
return 'settervalue'
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1', setter=setter)
|
||||||
|
holder = TestHolder(None)
|
||||||
|
|
||||||
|
holder.testprop1 = 'testvalue'
|
||||||
|
self.assertEqual(holder.testprop1, 'settervalue')
|
||||||
|
|
||||||
|
def test_031_set_type(self):
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1', type=int)
|
||||||
|
holder = TestHolder(None)
|
||||||
|
|
||||||
|
holder.testprop1 = '5'
|
||||||
|
self.assertEqual(holder.testprop1, 5)
|
||||||
|
self.assertNotEqual(holder.testprop1, '5')
|
||||||
|
|
||||||
|
def test_090_delete(self):
|
||||||
|
self.holder.testprop1 = 'testvalue'
|
||||||
|
try:
|
||||||
|
if self.holder.testprop1 != 'testvalue':
|
||||||
|
self.skipTest('testprop1 value is wrong')
|
||||||
|
except AttributeError:
|
||||||
|
self.skipTest('testprop1 value is wrong')
|
||||||
|
|
||||||
|
del self.holder.testprop1
|
||||||
|
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
self.holder.testprop
|
||||||
|
|
||||||
|
def test_091_delete_default(self):
|
||||||
|
class TestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
|
||||||
|
testprop1 = qubes.property('testprop1', default='defaultvalue')
|
||||||
|
holder = TestHolder(None)
|
||||||
|
holder.testprop1 = 'testvalue'
|
||||||
|
|
||||||
|
try:
|
||||||
|
if holder.testprop1 != 'testvalue':
|
||||||
|
self.skipTest('testprop1 value is wrong')
|
||||||
|
except AttributeError:
|
||||||
|
self.skipTest('testprop1 value is wrong')
|
||||||
|
|
||||||
|
del holder.testprop1
|
||||||
|
|
||||||
|
self.assertEqual(holder.testprop1, 'defaultvalue')
|
||||||
|
|
||||||
|
|
||||||
class TestHolder(qubes.PropertyHolder):
|
class TestHolder(qubes.PropertyHolder):
|
||||||
testprop1 = qubes.property('testprop1', order=0)
|
testprop1 = qubes.property('testprop1', order=0)
|
||||||
testprop2 = qubes.property('testprop2', order=1, save_via_ref=True)
|
testprop2 = qubes.property('testprop2', order=1, save_via_ref=True)
|
||||||
testprop3 = qubes.property('testprop3', order=2, default='testdefault')
|
testprop3 = qubes.property('testprop3', order=2, default='testdefault')
|
||||||
testprop4 = qubes.property('testprop4', order=3)
|
testprop4 = qubes.property('testprop4', order=3)
|
||||||
|
|
||||||
class TC_00_PropertyHolder(qubes.tests.QubesTestCase):
|
class TC_20_PropertyHolder(qubes.tests.QubesTestCase):
|
||||||
def assertXMLEqual(self, xml1, xml2):
|
def assertXMLEqual(self, xml1, xml2):
|
||||||
self.assertEqual(xml1.tag, xml2.tag)
|
self.assertEqual(xml1.tag, xml2.tag)
|
||||||
self.assertEqual(xml1.text, xml2.text)
|
self.assertEqual(xml1.text, xml2.text)
|
||||||
@ -104,7 +204,7 @@ class TestVM(qubes.vm.BaseVM):
|
|||||||
class TestApp(qubes.events.Emitter):
|
class TestApp(qubes.events.Emitter):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TC_11_VMCollection(qubes.tests.QubesTestCase):
|
class TC_30_VMCollection(qubes.tests.QubesTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# XXX passing None may be wrong in the future
|
# XXX passing None may be wrong in the future
|
||||||
self.vms = qubes.VMCollection(TestApp())
|
self.vms = qubes.VMCollection(TestApp())
|
||||||
@ -204,5 +304,5 @@ class TC_11_VMCollection(qubes.tests.QubesTestCase):
|
|||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
class TC_20_Qubes(qubes.tests.QubesTestCase):
|
class TC_90_Qubes(qubes.tests.QubesTestCase):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user