mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
Use dictionary to compare registry
The registry is a dictionary, so comparing items() has a couple of problems: 1. The order of a dictionary is unstable, so it may not turn out as expected. 2. items() returns a list in Python 2, but a dict_items in Python 3, which makes the comparison fail.
This commit is contained in:
parent
6492081b64
commit
f219370be2
1 changed files with 5 additions and 5 deletions
|
@ -11,16 +11,16 @@ class ComponentRegistryTest(unittest.TestCase):
|
|||
def test_simple_register(self):
|
||||
self.registry.register(name="testcomponent", component=MockComponent)
|
||||
self.assertEqual(
|
||||
self.registry._registry.items(),
|
||||
[("testcomponent", MockComponent)]
|
||||
self.registry._registry,
|
||||
{"testcomponent": MockComponent}
|
||||
)
|
||||
|
||||
def test_register_two_components(self):
|
||||
self.registry.register(name="testcomponent", component=MockComponent)
|
||||
self.registry.register(name="testcomponent2", component=MockComponent)
|
||||
self.assertEqual(
|
||||
self.registry._registry.items(),
|
||||
[("testcomponent", MockComponent), ("testcomponent2", MockComponent)]
|
||||
self.registry._registry,
|
||||
{"testcomponent": MockComponent, "testcomponent2": MockComponent}
|
||||
)
|
||||
|
||||
def test_prevent_registering_twice(self):
|
||||
|
@ -31,7 +31,7 @@ class ComponentRegistryTest(unittest.TestCase):
|
|||
def test_simple_unregister(self):
|
||||
self.registry.register(name="testcomponent", component=MockComponent)
|
||||
self.registry.unregister(name="testcomponent")
|
||||
self.assertEqual(self.registry._registry.items(), [])
|
||||
self.assertEqual(self.registry._registry, {})
|
||||
|
||||
def test_raises_on_failed_unregister(self):
|
||||
with self.assertRaises(component.NotRegistered):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue