Skip to content

Commit

Permalink
fix find_and_parse rename
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikboeck committed Jun 15, 2024
1 parent 60fa1aa commit bafb773
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 111 deletions.
4 changes: 2 additions & 2 deletions tests/test_00_parasite/test_00_never.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def test_never_default() -> None:


def test_never_find() -> None:
assert p.never().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.never().find_and_parse_safe({"key": "value"}, "key").is_err()
assert p.never()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.never()._find_and_parse_safe({"key": "value"}, "key").is_err()
8 changes: 4 additions & 4 deletions tests/test_00_parasite/test_01_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_any_default() -> None:


def test_any_optional() -> None:
assert p.any().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.any().optional().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.any().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.any().optional()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))

assert p.any().required().find_and_parse_safe({}, "key").is_err()
assert p.any().required().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.any().required()._find_and_parse_safe({}, "key").is_err()
assert p.any().required()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
8 changes: 4 additions & 4 deletions tests/test_00_parasite/test_02_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_null_default() -> None:


def test_null_optional() -> None:
assert p.null().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.null().optional().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
assert p.null().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.null().optional()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.null().required().find_and_parse_safe({}, "key").is_err()
assert p.null().required().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
assert p.null().required()._find_and_parse_safe({}, "key").is_err()
assert p.null().required()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
24 changes: 12 additions & 12 deletions tests/test_00_parasite/test_03_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ def test_boolean_default() -> None:


def test_boolean_find() -> None:
assert p.boolean().find_and_parse_safe({}, "key").is_err()
assert p.boolean().find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean()._find_and_parse_safe({}, "key").is_err()
assert p.boolean()._find_and_parse_safe({"key": True}, "key") == Ok(Some(True))


def test_boolean_optional() -> None:
assert p.boolean().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.boolean().optional().find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.boolean().optional()._find_and_parse_safe({"key": True}, "key") == Ok(Some(True))

assert p.boolean().required().find_and_parse_safe({}, "key").is_err()
assert p.boolean().required().find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().required()._find_and_parse_safe({}, "key").is_err()
assert p.boolean().required()._find_and_parse_safe({"key": True}, "key") == Ok(Some(True))


def test_boolean_nullable() -> None:
assert p.boolean().nullable().find_and_parse_safe({}, "key").is_err()
assert p.boolean().nullable().find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
assert p.boolean().nullable()._find_and_parse_safe({}, "key").is_err()
assert p.boolean().nullable()._find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.boolean().non_nullable().find_and_parse_safe({}, "key").is_err()
assert p.boolean().non_nullable().find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert p.boolean().non_nullable()._find_and_parse_safe({}, "key").is_err()
assert p.boolean().non_nullable()._find_and_parse_safe({"key": True}, "key") == Ok(Some(True))
assert p.boolean().non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_boolean_leaniant() -> None:
Expand Down
36 changes: 18 additions & 18 deletions tests/test_00_parasite/test_04_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ def test_number_default() -> None:


def test_number_find() -> None:
assert p.number().find_and_parse_safe({}, "key").is_err()
assert p.number().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number()._find_and_parse_safe({}, "key").is_err()
assert p.number()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))


def test_number_optional() -> None:
assert p.number().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.number().optional().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().optional().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.number().optional()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().optional()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))

assert p.number().required().find_and_parse_safe({}, "key").is_err()
assert p.number().required().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().required().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().required()._find_and_parse_safe({}, "key").is_err()
assert p.number().required()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().required()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))


def test_number_nullable() -> None:
assert p.number().nullable().find_and_parse_safe({}, "key").is_err()
assert p.number().nullable().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().nullable().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.number().non_nullable().find_and_parse_safe({}, "key").is_err()
assert p.number().non_nullable().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().non_nullable().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert p.number().nullable()._find_and_parse_safe({}, "key").is_err()
assert p.number().nullable()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().nullable()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.number().non_nullable()._find_and_parse_safe({}, "key").is_err()
assert p.number().non_nullable()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert p.number().non_nullable()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert p.number().non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_number_integer() -> None:
Expand Down
28 changes: 14 additions & 14 deletions tests/test_00_parasite/test_05_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ def test_string_default() -> None:


def test_string_find() -> None:
assert p.string().find_and_parse_safe({}, "key").is_err()
assert p.string().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.string()._find_and_parse_safe({}, "key").is_err()
assert p.string()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))


def test_string_optional() -> None:
assert p.string().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.string().optional().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.string().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.string().optional()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))

assert p.string().required().find_and_parse_safe({}, "key").is_err()
assert p.string().required().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.string().required()._find_and_parse_safe({}, "key").is_err()
assert p.string().required()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))


def test_string_nullable() -> None:
assert p.string().nullable().find_and_parse_safe({}, "key").is_err()
assert p.string().nullable().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.string().nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.string().non_nullable().find_and_parse_safe({}, "key").is_err()
assert p.string().non_nullable().find_and_parse_safe({"key": "value"},
"key") == Ok(Some("value"))
assert p.string().non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert p.string().nullable()._find_and_parse_safe({}, "key").is_err()
assert p.string().nullable()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert p.string().nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.string().non_nullable()._find_and_parse_safe({}, "key").is_err()
assert p.string().non_nullable()._find_and_parse_safe({"key": "value"},
"key") == Ok(Some("value"))
assert p.string().non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_string_trim() -> None:
Expand Down
46 changes: 23 additions & 23 deletions tests/test_00_parasite/test_06_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,40 @@ def test_variant_add_variant() -> None:
def test_variant_find() -> None:
v = p.variant().add_variant(p.number()).add_variant(p.string())

assert v.find_and_parse_safe({}, "key").is_err()
assert v.find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v._find_and_parse_safe({}, "key").is_err()
assert v._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))


def test_variant_optional() -> None:
v = p.variant().add_variant(p.number()).add_variant(p.string())

assert v.optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert v.optional().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.optional().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.optional().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert v.optional()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.optional()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.optional()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))

assert v.required().find_and_parse_safe({}, "key").is_err()
assert v.required().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.required().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.required().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.required()._find_and_parse_safe({}, "key").is_err()
assert v.required()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.required()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.required()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))


def test_variant_nullable() -> None:
v = p.variant().add_variant(p.number()).add_variant(p.string())

assert v.nullable().find_and_parse_safe({}, "key").is_err()
assert v.nullable().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.nullable().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.nullable().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert v.non_nullable().find_and_parse_safe({}, "key").is_err()
assert v.non_nullable().find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.non_nullable().find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.non_nullable().find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert v.nullable()._find_and_parse_safe({}, "key").is_err()
assert v.nullable()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.nullable()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.nullable()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert v.non_nullable()._find_and_parse_safe({}, "key").is_err()
assert v.non_nullable()._find_and_parse_safe({"key": 1}, "key") == Ok(Some(1))
assert v.non_nullable()._find_and_parse_safe({"key": 1.0}, "key") == Ok(Some(1.0))
assert v.non_nullable()._find_and_parse_safe({"key": "value"}, "key") == Ok(Some("value"))
assert v.non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_variant_rm_variant() -> None:
Expand Down
44 changes: 22 additions & 22 deletions tests/test_00_parasite/test_07_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@ def test_array_default() -> None:


def test_array_find() -> None:
assert p.array().find_and_parse_safe({}, "key").is_err()
assert p.array().find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array()._find_and_parse_safe({}, "key").is_err()
assert p.array()._find_and_parse_safe({"key": []}, "key") == Ok(Some([]))

assert p.array().find_and_parse_safe({"key": [1, 2, 3]}, "key") == Ok(Some([1, 2, 3]))
assert p.array().find_and_parse_safe({"key": [1.0, 2.0, 3.0]},
"key") == Ok(Some([1.0, 2.0, 3.0]))
assert p.array().find_and_parse_safe({"key": ["hello", "world"]},
"key") == Ok(Some(["hello", "world"]))
assert p.array().find_and_parse_safe({"key": [True, False]}, "key") == Ok(Some([True, False]))
assert p.array().find_and_parse_safe({"key": [[], {}]}, "key") == Ok(Some([[], {}]))
assert p.array().find_and_parse_safe({"key": [(), set()]}, "key") == Ok(Some([(), set()]))
assert p.array().find_and_parse_safe({"key": [set(), frozenset()]},
"key") == Ok(Some([set(), frozenset()]))
assert p.array()._find_and_parse_safe({"key": [1, 2, 3]}, "key") == Ok(Some([1, 2, 3]))
assert p.array()._find_and_parse_safe({"key": [1.0, 2.0, 3.0]},
"key") == Ok(Some([1.0, 2.0, 3.0]))
assert p.array()._find_and_parse_safe({"key": ["hello", "world"]},
"key") == Ok(Some(["hello", "world"]))
assert p.array()._find_and_parse_safe({"key": [True, False]}, "key") == Ok(Some([True, False]))
assert p.array()._find_and_parse_safe({"key": [[], {}]}, "key") == Ok(Some([[], {}]))
assert p.array()._find_and_parse_safe({"key": [(), set()]}, "key") == Ok(Some([(), set()]))
assert p.array()._find_and_parse_safe({"key": [set(), frozenset()]},
"key") == Ok(Some([set(), frozenset()]))


def test_array_optional() -> None:
assert p.array().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.array().optional().find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.array().optional()._find_and_parse_safe({"key": []}, "key") == Ok(Some([]))

assert p.array().required().find_and_parse_safe({}, "key").is_err()
assert p.array().required().find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().required()._find_and_parse_safe({}, "key").is_err()
assert p.array().required()._find_and_parse_safe({"key": []}, "key") == Ok(Some([]))


def test_array_nullable() -> None:
assert p.array().nullable().find_and_parse_safe({}, "key").is_err()
assert p.array().nullable().find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
assert p.array().nullable()._find_and_parse_safe({}, "key").is_err()
assert p.array().nullable()._find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.array().non_nullable().find_and_parse_safe({}, "key").is_err()
assert p.array().non_nullable().find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert p.array().non_nullable()._find_and_parse_safe({}, "key").is_err()
assert p.array().non_nullable()._find_and_parse_safe({"key": []}, "key") == Ok(Some([]))
assert p.array().non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_array_min() -> None:
Expand Down
24 changes: 12 additions & 12 deletions tests/test_00_parasite/test_08_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ def test_object_default() -> None:


def test_object_find() -> None:
assert p.obj().find_and_parse_safe({}, "key").is_err()
assert p.obj().find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj()._find_and_parse_safe({}, "key").is_err()
assert p.obj()._find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))


def test_object_optional() -> None:
assert p.obj().optional().find_and_parse_safe({}, "key") == Ok(Nil)
assert p.obj().optional().find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().optional()._find_and_parse_safe({}, "key") == Ok(Nil)
assert p.obj().optional()._find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))

assert p.obj().required().find_and_parse_safe({}, "key").is_err()
assert p.obj().required().find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().required()._find_and_parse_safe({}, "key").is_err()
assert p.obj().required()._find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))


def test_object_nullable() -> None:
assert p.obj().nullable().find_and_parse_safe({}, "key").is_err()
assert p.obj().nullable().find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().nullable().find_and_parse_safe({"key": None}, "key") == Ok(Some(None))
assert p.obj().nullable()._find_and_parse_safe({}, "key").is_err()
assert p.obj().nullable()._find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().nullable()._find_and_parse_safe({"key": None}, "key") == Ok(Some(None))

assert p.obj().non_nullable().find_and_parse_safe({}, "key").is_err()
assert p.obj().non_nullable().find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().non_nullable().find_and_parse_safe({"key": None}, "key").is_err()
assert p.obj().non_nullable()._find_and_parse_safe({}, "key").is_err()
assert p.obj().non_nullable()._find_and_parse_safe({"key": {}}, "key") == Ok(Some({}))
assert p.obj().non_nullable()._find_and_parse_safe({"key": None}, "key").is_err()


def test_object_init_items() -> None:
Expand Down

0 comments on commit bafb773

Please sign in to comment.