Fail if two backends claims to handle the same URI schema

This commit is contained in:
Stein Magnus Jodal 2012-10-29 10:31:35 +01:00
parent 7ee43dd208
commit 4a79b559d5
2 changed files with 9 additions and 0 deletions

View File

@ -62,4 +62,7 @@ class Backends(list):
for backend in backends:
uri_schemes = backend.uri_schemes.get()
for uri_scheme in uri_schemes:
assert uri_scheme not in self.by_uri_scheme, (
'URI scheme %s is already handled by %s'
% (uri_scheme, backend.__class__.__name__))
self.by_uri_scheme[uri_scheme] = backend

View File

@ -24,3 +24,9 @@ class CoreActorTest(unittest.TestCase):
self.assertIn('dummy1', result)
self.assertIn('dummy2', result)
def test_backends_with_colliding_uri_schemes_fails(self):
self.backend2.uri_schemes.get.return_value = ['dummy1', 'dummy2']
self.assertRaisesRegexp(
AssertionError, 'URI scheme dummy1 is already handled by Mock',
Core, audio=None, backends=[self.backend1, self.backend2])