Ejemplo n.º 1
0
def test_values_count_as_list():
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    spec = builder.single_field('field', builder.values(data,
                                                        count=[2, 3])).build()
    supplier = Loader(spec).get('field')

    first = supplier.next(0)
    assert isinstance(first, list) and len(first) == 2
    second = supplier.next(1)
    assert isinstance(second, list) and len(second) == 3
Ejemplo n.º 2
0
def test_nested_range_lists_simple():
    data = [
        [0, 10],
        [20, 30]
    ]
    spec = builder.single_field("field:range", data).build()
    supplier = Loader(spec).get('field')

    first = supplier.next(0)
    assert 0 <= first <= 10
    second = supplier.next(1)
    assert 20 <= second <= 30
Ejemplo n.º 3
0
def test_nested_range_lists_mixed_types_and_step():
    data = [
        [0, 10, 2],
        [20.0, 30.0]
    ]
    spec = builder.single_field("field:range", data).build()
    supplier = Loader(spec).get('field')

    first = supplier.next(0)
    assert first % 2 == 0
    assert 0 <= first <= 10
    second = supplier.next(1)
    assert 20.0 <= second <= 30.0
Ejemplo n.º 4
0
def test_config_ref_for_values():
    """ verifies that the values ref inherits the config from the config_ref """
    spec = builder.single_field("name?config_ref=quoteit", ["bob", "joe", "ann", "sue"]) \
        .add_ref("quoteit", builder.config_ref(quote="\"")) \
        .build()
    supplier = Loader(spec).get('name')
    assert supplier.next(0) == '"bob"'
Ejemplo n.º 5
0
def test_values_list_order():
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    spec = builder.single_field('field', data).build()
    supplier = Loader(spec).get('field')

    values = [supplier.next(i) for i in range(10)]
    assert values == data
Ejemplo n.º 6
0
def test_geo_spec_pair_default_order():
    spec = _geo_pair_spec(precision=1)
    supplier = Loader(spec).get('pair')
    value = supplier.next(0)
    parts = value.split(',')
    _verify_long(parts[0], -1)
    _verify_lat(parts[1], -1)
Ejemplo n.º 7
0
def test_range_wrap_around():
    data = [1, 3]
    spec = builder.single_field("field:range", data).build()
    supplier = Loader(spec).get('field')

    vals = [supplier.next(i) for i in range(4)]
    assert vals == [1, 2, 3, 1]
Ejemplo n.º 8
0
def test_unicode_range_single_range_as_hex():
    field_spec = builder.unicode_range(data=[0x3040, 0x309f], count=5)
    spec = builder.single_field("text", field_spec).build()
    supplier = Loader(spec).get('text')
    first = supplier.next(0)
    for c in first:
        assert 0x3040 <= ord(c) <= 0x309f
Ejemplo n.º 9
0
def test_geo_spec_pair_lat_first():
    spec = _geo_pair_spec(precision=2, lat_first="yes")
    supplier = Loader(spec).get('pair')
    value = supplier.next(0)
    parts = value.split(',')
    _verify_long(parts[1], -2)
    _verify_lat(parts[0], -2)
Ejemplo n.º 10
0
def test_unicode_multiple_ranges():
    data = [['0x0590', '0x05ff'], ['0x3040', '0x309f']]
    field_spec = builder.unicode_range(data=data, min=3, max=7)
    spec = builder.single_field("text", field_spec).build()

    supplier = Loader(spec).get('text')
    first = supplier.next(0)
    assert 3 <= len(first) <= 7
    for c in first:
        assert 0x0590 <= ord(c) <= 0x05ff or 0x3040 <= ord(c) <= 0x309f
Ejemplo n.º 11
0
def test_rand_range():
    spec = builder.spec_builder() \
        .add_field("field", builder.rand_range([100.9, 109.9], cast="int")) \
        .build()
    supplier = Loader(spec).get('field')

    first = supplier.next(0)
    assert str(first).isnumeric()
    # occasionally gets rounded down to 100
    assert 100 <= first <= 110
Ejemplo n.º 12
0
def test_char_class_multiple_classes():
    exclude = "CUSTOM"
    spec = _char_class_spec(data=["lower", "digits", "CUSTOM"],
                            exclude=exclude)

    supplier = Loader(spec).get('name')
    value = supplier.next(0)
    assert isinstance(value, str)
    for char in value:
        assert char in string.ascii_lowercase or char in string.digits
Ejemplo n.º 13
0
def test_nested_range_lists_mixed_types_and_step_cast():
    data = [
        [0.5, 2.5, 0.5],
        [20.01234, 30.56789]
    ]
    spec = builder.single_field("field:range?cast=str&precision=2", data).build()
    supplier = Loader(spec).get('field')

    assert supplier.next(0) == '0.5'
    assert supplier.next(1) == '20.01'
Ejemplo n.º 14
0
def test_unicode_range_single_range_as_hex_strings():
    field_spec = builder.unicode_range(data=[0x3040, 0x309f],
                                       mean=5,
                                       stddev=2,
                                       min=2,
                                       max=7)
    spec = builder.single_field("text", field_spec).build()
    supplier = Loader(spec).get('text')
    first = supplier.next(0)
    assert 2 <= len(first) <= 7
    for c in first:
        assert 0x3040 <= ord(c) <= 0x309f
Ejemplo n.º 15
0
def test_geo_spec_pair_reduced_ranges_bbox():
    start_lat = -90
    end_lat = -45.0
    start_long = 90.0
    end_long = 180.0

    spec = _geo_pair_spec(bbox=[start_long, start_lat, end_long, end_lat])

    supplier = Loader(spec).get('pair')
    value = supplier.next(0)
    parts = value.split(',')
    _verify_in_range_and_has_precision(parts[0], start_long, end_long, -4)
    _verify_in_range_and_has_precision(parts[1], start_lat, end_lat, -4)
Ejemplo n.º 16
0
def test_geo_pair_as_list():
    start_lat = -45.0
    end_lat = 45.0
    start_long = 50.0
    end_long = 60.0

    spec = _geo_pair_spec(bbox=[start_long, start_lat, end_long, end_lat],
                          as_list=True)

    supplier = Loader(spec).get('pair')
    value = supplier.next(0)
    assert isinstance(value, list)
    _verify_in_range_and_has_precision(value[0], start_long, end_long, -4)
    _verify_in_range_and_has_precision(value[1], start_lat, end_lat, -4)
Ejemplo n.º 17
0
def test_geo_spec_pair_reduced_ranges():
    start_lat = 0.0
    end_lat = 75.0
    start_long = -180.0
    end_long = -90.0
    spec = _geo_pair_spec(start_lat=start_lat,
                          end_lat=end_lat,
                          start_long=start_long,
                          end_long=end_long)

    supplier = Loader(spec).get('pair')
    value = supplier.next(0)
    parts = value.split(',')
    _verify_in_range_and_has_precision(parts[0], start_long, end_long, -4)
    _verify_in_range_and_has_precision(parts[1], start_lat, end_lat, -4)
Ejemplo n.º 18
0
def test_single_nested():
    # Geo
    # - Place
    # - Coord
    geo_spec = builder.spec_builder() \
        .add_field("place_id:uuid", {}) \
        .add_field("coordinates", builder.geo_pair(as_list=True))
    spec = builder.spec_builder() \
        .add_field("id:uuid", {}) \
        .add_field("geo", builder.nested(fields=geo_spec.build())) \
        .build()
    supplier = Loader(spec).get('geo')

    first = supplier.next(0)
    assert isinstance(first, dict)
    assert list(first.keys()) == ['place_id', 'coordinates']
Ejemplo n.º 19
0
def test_multi_nested():
    # User
    # - Geo
    # - - Place
    # - - Coord
    geo_spec = builder.spec_builder() \
        .add_field("place_id:uuid", {}) \
        .add_field("coordinates", builder.geo_pair(as_list=True))
    user_spec = builder.spec_builder() \
        .add_field("user_id:uuid", {}) \
        .add_field("geo", builder.nested(fields=geo_spec.build()))
    spec = builder.spec_builder() \
        .add_field("id:uuid", {}) \
        .add_field("user", builder.nested(fields=user_spec.build())) \
        .build()
    supplier = Loader(spec).get('user')

    first = supplier.next(0)
    assert isinstance(first, dict)
    assert list(first.keys()) == ['user_id', 'geo']

    second = first['geo']
    assert isinstance(second, dict)
    assert list(second.keys()) == ['place_id', 'coordinates']
Ejemplo n.º 20
0
def _test_geo_spec_falls_in_range(spec, key, start, end, exponent):
    supplier = Loader(spec).get(key)
    value = supplier.next(0)
    _verify_in_range_and_has_precision(value, start, end, exponent)