def test_generate_strategy_with_one_json_string(tmpdir): """Checks that generate strategy works for one json string type in file""" path = tmpdir.mkdir("sub").join("hello.txt") path.write('[{"type": "string", "maxLength": 0, "minLength": 0}]') size = "50" strategy = generate.generate_experiment_strategy(path, size) assert len(strategy) != 0
def test_generate_strategy_with_one_json(tmpdir): """Checks that generate strategy works for one json object in file""" path = tmpdir.mkdir("sub").join("hello.txt") path.write('[{"type": "array", "items": {"type": "number"}}]') size = "50" strategy = generate.generate_experiment_strategy(path, size) assert (str(strategy[0]) == "lists(floats(allow_infinity=False, \ allow_nan=False).filter(lambda n: <unknown>), max_size=50, min_size=50)")
def test_generate_strategy_with_one_json_object(tmpdir): """Checks that generate strategy works for one json object type in file""" path = tmpdir.mkdir("sub").join("hello.txt") path.write('[{"type": "object", "patternProperties": \ {"^[0-9]+$": {"type": "integer"}},"minProperties": 0, "maxProperties": 0}]') size = "50" strategy = generate.generate_experiment_strategy(path, size) assert len(strategy) != 0
def test_detect_level_only(tmpdir): """Checks that generate strategy works for multiple level""" path = tmpdir.mkdir('sub').join("hello.txt") path.write('[{"type": "array", "items": {"type": "number"}}\n\ ,{"type": "array", "items": {"type": "number"}}]') size = "50" level = 2 position = [0, 0] strategy = generate.generate_experiment_strategy(path, size, level, position) assert str(strategy[0]) == "lists(just(50))"
def test_detect_level_and_position(tmpdir): """Checks that generate strategy works for multiple level""" path = tmpdir.mkdir("sub").join("hello.txt") path.write( '[{"type": "array", "items": [{"type": "number"}, {"type": "number"}]}\n\ ,{"type": "array", "items": [{"type": "number"}, {"type": "number"}]}]' ) size = "50" level = 2 position = [0, 0] strategy = generate.generate_experiment_strategy(path, size, level, position) assert ( str(strategy[1]) == "builds(<function _operator.add>, tuples(floats(allow_infinity=False, allow_nan=False).filter(lambda n: <unknown>), floats(allow_infinity=False, allow_nan=False).filter(lambda n: <unknown>)).map(list), lists(recursive(one_of(one_of(one_of(one_of(none(), booleans()), integers()), floats(allow_infinity=False, allow_nan=False).map(lambda x: <unknown>)), text()), lambda strategy: st.lists(strategy, max_size=3), max_leaves=100)))" # pylint: disable=C0301 )