Exemplo n.º 1
0
 def test_resolve_multiple_truthy(self):
     truthy = MagicMock(return_value=True)
     switch = Switch(
         [Case(truthy) >> sentinel.exact1,
          Case(truthy) >> sentinel.exact2])
     self.assertEqual(switch(sentinel.any), sentinel.exact1)
     truthy.assert_called_once_with(sentinel.any)
Exemplo n.º 2
0
 def test_resolve_multiple_falsy(self):
     falsy = MagicMock(return_value=False)
     switch = Switch(
         [Case(falsy) >> sentinel.exact1,
          Case(falsy) >> sentinel.exact2])
     with self.assertRaises(ValueError):
         switch(sentinel.any)
     falsy.assert_has_calls([call(sentinel.any), call(sentinel.any)])
Exemplo n.º 3
0
 def test_resolve_multiple_truthy_falsy(self):
     truthy = MagicMock(return_value=True)
     falsy = MagicMock(return_value=False)
     switch = Switch([
         Case(falsy) >> sentinel.exact1,
         Case(falsy) >> sentinel.exact2,
         Case(truthy) >> sentinel.exact3,
         Case(truthy) >> sentinel.exact4
     ])
     self.assertEqual(switch(sentinel.any), sentinel.exact3)
     falsy.assert_has_calls([call(sentinel.any), call(sentinel.any)])
     truthy.assert_called_once_with(sentinel.any)
Exemplo n.º 4
0
 def test_switch_without_cases(self):
     switch = Switch(cases=[], expr=sentinel.expr)
     with self.assertRaises(ValueError):
         switch()
Exemplo n.º 5
0
 def test_switch_without_expr(self):
     switch = Switch([Case(lambda x: True) >> sentinel.smth])
     with self.assertRaises(ValueError):
         switch()
Exemplo n.º 6
0
 def test_switch_with_2_expr(self):
     switch = Switch()(
         sentinel.expr1) | Case(lambda x: True) >> sentinel.smth
     with self.assertRaises(ValueError):
         switch(sentinel.expr2)
Exemplo n.º 7
0
 def test_switch_with_expr(self):
     truthy = MagicMock(return_value=True)
     switch = Switch()(sentinel.expr) | Case(truthy) >> sentinel.smth
     self.assertEqual(switch(), sentinel.smth)
     truthy.assert_called_once_with(sentinel.expr)
Exemplo n.º 8
0
 def test_switch_multiple_cases(self):
     switch = (Switch()
               | Case(lambda x: False) >> sentinel.exact1
               | Case(lambda x: True) >> sentinel.exact2)
     self.assertEqual(switch(sentinel.any), sentinel.exact2)
Exemplo n.º 9
0
 def test_switch_single_case(self):
     switch = Switch() | Case(lambda x: True) >> sentinel.exact
     self.assertEqual(switch(sentinel.any), sentinel.exact)
Exemplo n.º 10
0
 def test_resolve_single_falsy(self):
     falsy = MagicMock(return_value=False)
     switch = Switch([Case(falsy) >> sentinel.exact])
     with self.assertRaises(ValueError):
         switch(sentinel.any)
     falsy.assert_called_once_with(sentinel.any)