Ejemplo n.º 1
0
 def test_delete_hierachy_last():
     """Deleting such that all obj, default and fallback are None should fail."""
     slot = Slot(dtype=str)
     plug = Plug(slot, default='default', obj='obj')
     del plug.obj
     with pytest.raises(TypeError):
         del plug.default
Ejemplo n.º 2
0
 def test_init_with_slot_default():
     """Instatiating a Plug with a slot's default value should succeed."""
     slot = Slot(dtype=int, default=10)
     Plug(slot)
Ejemplo n.º 3
0
 class SlotHolder:
     """Holds a single Slot"""
     my_slot = Slot(str)
Ejemplo n.º 4
0
 class MyPlugboard(Plugboard):
     """Custom Plugboard"""
     my_slot = Slot(dtype=int, default=15)
Ejemplo n.º 5
0
 def test_slot_set_no_default():
     """Assigning a new slot without any other but the slot default value set should fail."""
     slot = Slot(dtype=object, default='fallback')
     plug = Plug(slot)
     with pytest.raises(TypeError):
         plug.slot = slot(dtype=str)
Ejemplo n.º 6
0
 def test_slot_set_consistent():
     """Assigning a new slot with the correct dtype should succeed."""
     slot = Slot(dtype=object)
     plug = Plug(slot, obj='default')
     plug.slot = Slot(dtype=str)
Ejemplo n.º 7
0
 def test_not_optional():
     """If neither default, nor slot default are set, object should not be optional."""
     slot = Slot(dtype=str)
     plug = Plug(slot, obj='obj')
     assert not plug.optional
Ejemplo n.º 8
0
 def test_default_set_inconsistent():
     """Setting default inconsistently should fail."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     with pytest.raises(TypeError):
         plug.default = 15
Ejemplo n.º 9
0
 def test_init_unknown_args():
     """When unknown arguments are passed, Slot should raise TypeError when instatiating"""
     with pytest.raises(TypeError):
         Slot(monkey='banana')
Ejemplo n.º 10
0
 def test_obj_hierachy_obj():
     """Accessing obj with slot default, plug default and obj set should return obj."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot, obj='obj', default='default')
     assert plug.obj == 'obj'
Ejemplo n.º 11
0
 def test_init_inconsistent_default():
     """Instatiating a Plug with obj not set as slot's dtype should fail."""
     slot = Slot(dtype=str)
     with pytest.raises(TypeError):
         Plug(slot, default=15)
Ejemplo n.º 12
0
 def test_init_consistent_default():
     """Instatiating a Plug with default set as the correct slot's dtype should succeed."""
     slot = Slot(dtype=int)
     Plug(slot, default=15)
Ejemplo n.º 13
0
 def test_init_consistent_obj():
     """Instatiating a Plug with obj set as the correct slot's dtype should succeed."""
     slot = Slot(dtype=int)
     Plug(slot, obj=15)
Ejemplo n.º 14
0
 def test_init_no_slot_default():
     """Instatiating a Plug without a slot's default value should fail."""
     slot = Slot(dtype=int)
     with pytest.raises(TypeError):
         Plug(slot)
Ejemplo n.º 15
0
 def test_init_inconsistent_args():
     """If arguments are inconsistent, Slot should raise TypeError when instatiating"""
     with pytest.raises(TypeError):
         Slot(dtype=str, default=5)
Ejemplo n.º 16
0
 def test_obj_del():
     """Deleting obj with slot default should succeed."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     plug.obj = 'obj'
     del plug.obj
Ejemplo n.º 17
0
 def test_default_set():
     """Setting default consistently should succeed."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     plug.default = 'default'
Ejemplo n.º 18
0
 def test_default_hierachy_obj():
     """Accessing default with slot default, default and obj set should return default."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot, default='default')
     assert plug.default == 'default'
Ejemplo n.º 19
0
 def test_default_del():
     """Deleting default with slot default should succeed."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     plug.default = 'default'
     del plug.default
Ejemplo n.º 20
0
 def test_fallback_hierachy_default():
     """Accessing fallback with slot default and plug default set should return slot default."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot, default='default')
     assert plug.fallback == 'fallback'
Ejemplo n.º 21
0
 def test_optional():
     """If default is set, object should be optional."""
     slot = Slot(dtype=str)
     plug = Plug(slot, default='default', obj='obj')
     assert plug.optional
Ejemplo n.º 22
0
 def test_fallback_hierachy_fallback():
     """Accessing fallback with only slot default set should return slot default."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     assert plug.fallback == 'fallback'
Ejemplo n.º 23
0
 def test_slot_set_inconsistent():
     """Assigning a new slot without the correct dtype should fail."""
     slot = Slot(dtype=object)
     plug = Plug(slot, obj='default')
     with pytest.raises(TypeError):
         plug.slot = slot(dtype=int)
Ejemplo n.º 24
0
 def test_hierachy_none():
     """Accessing any of default and fallback with only obj set should return None."""
     slot = Slot(dtype=str)
     plug = Plug(slot, obj='obj')
     assert plug.default is None
     assert plug.fallback is None
Ejemplo n.º 25
0
 class SlotHolder:
     """Holds a single Slot"""
     my_slot = Slot(default=42)
Ejemplo n.º 26
0
 def test_delete_hierachy():
     """Deleting obj with default set should return default."""
     slot = Slot(dtype=str)
     plug = Plug(slot, default='default', obj='obj')
     del plug.obj
     assert plug.obj == 'default'
Ejemplo n.º 27
0
 class SlotHolder:
     """Holds a single Slot"""
     my_slot = Slot(dtype=int)
Ejemplo n.º 28
0
 def test_obj_set():
     """Setting obj consistently should succeed."""
     slot = Slot(dtype=str, default='fallback')
     plug = Plug(slot)
     plug.obj = 'obj'
Ejemplo n.º 29
0
 def test_init():
     """Slot should successfully instatiate in any case"""
     Slot()
Ejemplo n.º 30
0
 class SlotHolder:
     """Holds a single Slot"""
     my_slot = Slot(dtype=int, default=15)