openwebrx/test/property/test_property_stack.py

44 lines
1.3 KiB
Python
Raw Normal View History

2020-03-22 21:51:49 +01:00
from unittest import TestCase
from unittest.mock import Mock
from owrx.property import PropertyLayer, PropertyStack
2020-03-22 21:51:49 +01:00
class PropertyStackTest(TestCase):
2020-03-22 21:51:49 +01:00
def testLayer(self):
om = PropertyStack()
pm = PropertyLayer()
2020-03-22 21:51:49 +01:00
pm["testkey"] = "testvalue"
om.addLayer(1, pm)
self.assertEqual(om["testkey"], "testvalue")
def testHighPriority(self):
om = PropertyStack()
low_pm = PropertyLayer()
high_pm = PropertyLayer()
2020-03-22 21:51:49 +01:00
low_pm["testkey"] = "low value"
high_pm["testkey"] = "high value"
om.addLayer(1, low_pm)
om.addLayer(0, high_pm)
self.assertEqual(om["testkey"], "high value")
def testPriorityFallback(self):
om = PropertyStack()
low_pm = PropertyLayer()
high_pm = PropertyLayer()
2020-03-22 21:51:49 +01:00
low_pm["testkey"] = "low value"
om.addLayer(1, low_pm)
om.addLayer(0, high_pm)
self.assertEqual(om["testkey"], "low value")
def testLayerRemoval(self):
om = PropertyStack()
low_pm = PropertyLayer()
high_pm = PropertyLayer()
2020-03-22 21:51:49 +01:00
low_pm["testkey"] = "low value"
high_pm["testkey"] = "high value"
om.addLayer(1, low_pm)
om.addLayer(0, high_pm)
self.assertEqual(om["testkey"], "high value")
om.removeLayer(high_pm)
self.assertEqual(om["testkey"], "low value")