Beispiel #1
0
 def test_validate_str(
     self, provided: Any, optional: bool, required: bool, expected: Optional[str]
 ) -> None:
     """Test _validate_str."""
     assert (
         BaseModel._validate_str(provided, optional=optional, required=required)
         == expected
     )
Beispiel #2
0
 def test_validate_dict(
     self,
     provided: Any,
     optional: bool,
     required: bool,
     expected: Optional[Dict[str, Any]],
 ) -> None:
     """Test _validate_dict."""
     assert (
         BaseModel._validate_dict(provided, optional=optional, required=required)
         == expected
     )
Beispiel #3
0
 def test_validate_dict_value_error(self) -> None:
     """Test _validate_dict raise ValueError."""
     with pytest.raises(ValueError):
         BaseModel._validate_dict(["something"])  # type: ignore
     with pytest.raises(ValueError):
         BaseModel._validate_dict(None, required=True)
     with pytest.raises(ValueError):
         BaseModel._validate_dict({}, required=True)
Beispiel #4
0
 def test_validate_str_value_error(self) -> None:
     """Test _validate_str raise ValueError."""
     with pytest.raises(ValueError):
         BaseModel._validate_str(None, required=True)
     with pytest.raises(ValueError):
         BaseModel._validate_str("", required=True)
Beispiel #5
0
 def test_validate_str_type_error(self, provided: Any) -> None:
     """Test _validate_str raise TypeError."""
     with pytest.raises(TypeError):
         BaseModel._validate_str(provided)
Beispiel #6
0
 def test_validate_path_value_error(self, tmp_path: Path) -> None:
     """Test _validate_path raise ValueError."""
     with pytest.raises(ValueError):
         BaseModel._validate_path(tmp_path / "missing", must_exist=True)
Beispiel #7
0
 def test_validate_path_type_error(self) -> None:
     """Test _validate_path raise TypeError."""
     with pytest.raises(TypeError):
         BaseModel._validate_path(13)
Beispiel #8
0
 def test_validate_path(self, tmp_path: Path) -> None:
     """Test validate_path."""
     assert BaseModel._validate_path(str(tmp_path)) == tmp_path
     assert BaseModel._validate_path(str(tmp_path), must_exist=True) == tmp_path
     assert BaseModel._validate_path(tmp_path) == tmp_path
     assert BaseModel._validate_path(tmp_path, must_exist=True) == tmp_path
Beispiel #9
0
 def test_validate_list_str_type_error(self) -> None:
     """Test _validate_list_str raise TypeError."""
     with pytest.raises(TypeError):
         BaseModel._validate_list_str(["something", None])
     with pytest.raises(TypeError):
         BaseModel._validate_list_str(1)
Beispiel #10
0
 def test_validate_int_value_error(self) -> None:
     """Test _validate_int raise ValueError."""
     with pytest.raises(ValueError):
         BaseModel._validate_int(None, required=True)
     with pytest.raises(ValueError):
         BaseModel._validate_int("something")
Beispiel #11
0
 def test_validate_bool(self, provided: Any, expected: bool) -> None:
     """Test _validate_bool."""
     assert BaseModel._validate_bool(provided) is expected