コード例 #1
0
 def test_bad_typeerror(self):
     inputs = [
         [{"a", "b"}, int],
         ["a", int],
         [("a", "b"), (int, float)],
     ]
     for input_ in inputs:
         with pytest.raises(TypeError):
             utils.validate_set_members(*input_)
コード例 #2
0
 def test_bad_valueerror(self):
     inputs = [
         [{"a", "b"}, (str, bytes), {"x", "y", "z"}],
         [{"a", "x"}, (str, bytes), {"x", "y", "z"}],
         ["a", (str, bytes), {"x", "y", "z"}],
         ["a", (str, bytes), {
             "x": 24,
             "y": 25,
             "z": 26
         }],
     ]
     for input_ in inputs:
         with pytest.raises(ValueError):
             utils.validate_set_members(*input_)
コード例 #3
0
 def test_good_inputs(self):
     inputs = [
         [{"a", "b"}, (str, bytes), {"a", "b", "c"}],
         ["a", (str, bytes), {"a", "b", "c"}],
         [("a", "b"), (str, bytes), {"a", "b", "c"}],
         [["a", "b"], (str, bytes)],
         [{1, 2}, int, {1, 2, 3}],
         [{1, 2}, (int, float), {1, 2, 3}],
         [1, int, {
             1: "a",
             2: "b",
             3: "c"
         }],
         [{3.14, 42.0}, float],
         [3.14, (int, float)],
     ]
     for input_ in inputs:
         output = utils.validate_set_members(*input_)
         assert isinstance(output, set)
         assert all(isinstance(val, input_[1]) for val in output)
コード例 #4
0
 def test_invalid_inputs(self, vals, val_type, valid_vals, error):
     with error:
         _ = utils.validate_set_members(vals, val_type, valid_vals)
コード例 #5
0
 def test_valid_inputs(self, vals, val_type, valid_vals):
     output = utils.validate_set_members(vals, val_type, valid_vals)
     assert isinstance(output, set)
     assert all(isinstance(val, val_type) for val in output)