Exemplo n.º 1
0
def test_top_level_string_multiple_matches():
    d = collections.OrderedDict(
        title="my dataset",
        last_updated="recently",
        update_frequency="quite often",
    )
    losser.query("update", d) == ["recently", "quite often"]
Exemplo n.º 2
0
def test_top_level_string_multiple_matches():
    d = collections.OrderedDict(
        title="my dataset",
        last_updated="recently",
        update_frequency="quite often",
    )
    losser.query("update", d) == ["recently", "quite often"]
Exemplo n.º 3
0
def test_unicode_string():
    string_transformations = [lambda x: x[:3]]
    result = losser.query([],
                          u" fübar  ",
                          strip=True,
                          string_transformations=string_transformations)
    assert result == u"füb"
Exemplo n.º 4
0
def test_dict_of_lists():
    d = collections.OrderedDict((
        ("foo", [1, 2, 3]),
        ("bar", [4, 5, 6]),
        ("foobar", ["a", "b", "c"]),
    ))
    assert losser.query("foo", d) == [1, 2, 3, "a", "b", "c"]
Exemplo n.º 5
0
def test_top_level_string_no_matches():
    d = collections.OrderedDict(
        title="my dataset",
        last_updated="recently",
        update_frequency="quite often",
    )
    assert losser.query("maintainer", d) is None
Exemplo n.º 6
0
def test_terminal_value_is_list_of_scalars():
    """If the pattern path terminates at a list that list is returned as is."""
    d = collections.OrderedDict(title="my dataset",
                                last_updated="recently",
                                update_frequency="quite often",
                                resources=[1, 2, 3])
    assert losser.query("^resources$", d) == [1, 2, 3]
Exemplo n.º 7
0
def test_dict_of_lists():
    d = collections.OrderedDict((
        ("foo", [1, 2, 3]),
        ("bar", [4, 5, 6]),
        ("foobar", ["a", "b", "c"]),
    ))
    assert losser.query("foo", d) == [1, 2, 3, "a", "b", "c"]
Exemplo n.º 8
0
def test_string_with_strip_and_transform():
    string_transformations = [lambda x: x[:3]]
    result = losser.query([],
                          " foobar  ",
                          strip=True,
                          string_transformations=string_transformations)
    assert result == "foo"
Exemplo n.º 9
0
def test_top_level_string_no_matches():
    d = collections.OrderedDict(
        title="my dataset",
        last_updated="recently",
        update_frequency="quite often",
    )
    assert losser.query("maintainer", d) is None
Exemplo n.º 10
0
def test_sub_dict_with_one_match():
    d = collections.OrderedDict(title="my dataset",
                                extras=dict(
                                    foo="bar",
                                    something_else="some other thing",
                                ))
    pattern = ["^extras$", "foo"]
    assert losser.query(pattern, d) == "bar"
Exemplo n.º 11
0
def test_sub_dict_with_multiple_matches():
    d = collections.OrderedDict(title="my dataset",
                                extras=dict(
                                    foo="bar",
                                    foo_again="bah",
                                ))
    pattern = ["^extras$", "foo"]
    assert losser.query(pattern, d) == ["bar", "bah"]
Exemplo n.º 12
0
def test_list_of_dicts():
    d = collections.OrderedDict(
        title="my dataset",
        resources=[dict(format="CSV"), dict(format="JSON"), dict(foo="bar")],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d)
    assert result == ["CSV", "JSON"]
Exemplo n.º 13
0
def test_terminal_value_is_list_of_scalars():
    """If the pattern path terminates at a list that list is returned as is."""
    d = collections.OrderedDict(
        title="my dataset",
        last_updated="recently",
        update_frequency="quite often",
        resources=[1, 2, 3]
    )
    assert losser.query("^resources$", d) == [1, 2, 3]
Exemplo n.º 14
0
def test_case_sensitive_matching():
    d = collections.OrderedDict(title="my dataset",
                                extras=dict(
                                    Title="the right title",
                                    title="the wrong title",
                                    something_else="some other thing",
                                ))
    pattern = ["^extras$", "Title"]
    assert losser.query(pattern, d, case_sensitive=True) == "the right title"
Exemplo n.º 15
0
def test_sub_dict_with_one_match():
    d = collections.OrderedDict(
        title="my dataset",
        extras=dict(
            foo="bar",
            something_else="some other thing",
        )
    )
    pattern = ["^extras$", "foo"]
    assert losser.query(pattern, d) == "bar"
Exemplo n.º 16
0
def test_sub_dict_with_multiple_matches():
    d = collections.OrderedDict(
        title="my dataset",
        extras=dict(
            foo="bar",
            foo_again="bah",
        )
    )
    pattern = ["^extras$", "foo"]
    assert losser.query(pattern, d) == ["bar", "bah"]
Exemplo n.º 17
0
def test_list_of_dicts():
    d = collections.OrderedDict(
        title="my dataset",
        resources=[dict(format="CSV"),
                   dict(format="JSON"),
                   dict(foo="bar")],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d)
    assert result == ["CSV", "JSON"]
Exemplo n.º 18
0
def test_deduplicate():
    """Test the deduplicate option."""
    d = collections.OrderedDict(
        title="my dataset",
        resources=[dict(format="CSV"), dict(format="CSV"),
                   dict(format="JSON")],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d,  deduplicate=True)
    assert result == ["CSV", "JSON"]
Exemplo n.º 19
0
def test_sub_dict_multiple_matches_returns_multiple_results():
    d = collections.OrderedDict(title="my dataset",
                                extras=dict(
                                    foo="bar",
                                    foo_again="bah",
                                ))
    pattern = ["^extras$", "foo"]
    nose.tools.assert_equals(
        losser.query(pattern, d, return_multiple_columns=True),
        collections.OrderedDict([('extras_foo', ['bar']),
                                 ('extras_foo_again', ['bah'])]))
Exemplo n.º 20
0
def test_case_sensitive_matching():
    d = collections.OrderedDict(
        title="my dataset",
        extras=dict(
            Title="the right title",
            title="the wrong title",
            something_else="some other thing",
        )
    )
    pattern = ["^extras$", "Title"]
    assert losser.query(pattern, d, case_sensitive=True) == "the right title"
Exemplo n.º 21
0
def test_deduplicate():
    """Test the deduplicate option."""
    d = collections.OrderedDict(
        title="my dataset",
        resources=[
            dict(format="CSV"),
            dict(format="CSV"),
            dict(format="JSON")
        ],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d, deduplicate=True)
    assert result == ["CSV", "JSON"]
Exemplo n.º 22
0
def test_sub_dict_multiple_matches_returns_multiple_results():
    d = collections.OrderedDict(
        title="my dataset",
        extras=dict(
            foo="bar",
            foo_again="bah",
        )
    )
    pattern = ["^extras$", "foo"]
    nose.tools.assert_equals(
        losser.query(pattern, d, return_multiple_columns=True),
        collections.OrderedDict(
            [('extras_foo', ['bar']), ('extras_foo_again', ['bah'])]
        )
    )
Exemplo n.º 23
0
def test_list_of_dicts_multiple_matches():
    """Test processing a list of dicts when some of the individual dicts have
    multiple matches."""
    d = collections.OrderedDict(
        title="my dataset",
        resources=[
            collections.OrderedDict(
                (("format", "CSV"), ("formatting", "commas"))),
            collections.OrderedDict(
                (("format", "JSON"), ("formatting", "pretty printed"))),
            dict(foo="bar")
        ],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d)
    assert result == ["CSV", "commas", "JSON", "pretty printed"]
Exemplo n.º 24
0
def test_list_of_dicts_multiple_matches():
    """Test processing a list of dicts when some of the individual dicts have
    multiple matches."""
    d = collections.OrderedDict(
        title="my dataset",
        resources=[
            collections.OrderedDict((
                ("format", "CSV"), ("formatting", "commas"))),
            collections.OrderedDict((
                ("format", "JSON"), ("formatting", "pretty printed"))),
            dict(foo="bar")
        ],
    )
    pattern = ["^resources$", "format"]
    result = losser.query(pattern, d)
    assert result == ["CSV", "commas", "JSON", "pretty printed"]
Exemplo n.º 25
0
def test_top_level_string_single_match():
    assert losser.query("^title$", {"title": "my title"}) == "my title"
Exemplo n.º 26
0
def test_boolean():
    assert losser.query([], False) == False
Exemplo n.º 27
0
def test_none():
    assert losser.query([], None) == None
Exemplo n.º 28
0
def test_string_with_strip_and_transform():
    string_transformations = [lambda x: x[:3]]
    result = losser.query([], " foobar  ", strip=True,
                            string_transformations=string_transformations)
    assert result == "foo"
Exemplo n.º 29
0
def test_unicode_string():
    string_transformations = [lambda x: x[:3]]
    result = losser.query([], u" fübar  ", strip=True,
                            string_transformations=string_transformations)
    assert result == u"füb"
Exemplo n.º 30
0
def test_tuples():
    """Test that tuples are treated the same as lists."""
    d = {"foo": ((1, 2, 3), (4, 5, 6), ("a", "b", "c"))}
    result =  losser.query("foo", d)
    assert result == [1, 2, 3, 4, 5, 6, "a", "b", "c"]
Exemplo n.º 31
0
def test_boolean():
    assert losser.query([], False) == False
Exemplo n.º 32
0
def test_string():
    assert losser.query([], "foo") == "foo"
Exemplo n.º 33
0
def test_list_of_lists():
    d = {"foo": [[1, 2, 3], [4, 5, 6], ["a", "b", "c"]]}
    result =  losser.query("foo", d)
    assert result == [1, 2, 3, 4, 5, 6, "a", "b", "c"]
Exemplo n.º 34
0
def test_string_with_strip():
    assert losser.query([], " foo  ", strip=True) == "foo"
Exemplo n.º 35
0
def test_top_level_string_single_match():
    assert losser.query("^title$", {"title": "my title"}) == "my title"
Exemplo n.º 36
0
def test_string_with_strip():
    assert losser.query([], " foo  ", strip=True) == "foo"
Exemplo n.º 37
0
def test_list_of_lists():
    d = {"foo": [[1, 2, 3], [4, 5, 6], ["a", "b", "c"]]}
    result = losser.query("foo", d)
    assert result == [1, 2, 3, 4, 5, 6, "a", "b", "c"]
Exemplo n.º 38
0
def test_string():
    assert losser.query([], "foo") == "foo"
Exemplo n.º 39
0
def test_tuples():
    """Test that tuples are treated the same as lists."""
    d = {"foo": ((1, 2, 3), (4, 5, 6), ("a", "b", "c"))}
    result = losser.query("foo", d)
    assert result == [1, 2, 3, 4, 5, 6, "a", "b", "c"]
Exemplo n.º 40
0
def test_none():
    assert losser.query([], None) == None
Exemplo n.º 41
0
def test_number():
    assert losser.query([], 42) == 42
Exemplo n.º 42
0
def test_number():
    assert losser.query([], 42) == 42