Beispiel #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"]
Beispiel #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"]
Beispiel #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"
Beispiel #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"]
Beispiel #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
Beispiel #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]
Beispiel #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"]
Beispiel #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"
Beispiel #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
Beispiel #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"
Beispiel #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"]
Beispiel #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"]
Beispiel #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]
Beispiel #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"
Beispiel #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"
Beispiel #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"]
Beispiel #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"]
Beispiel #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"]
Beispiel #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'])]))
Beispiel #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"
Beispiel #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"]
Beispiel #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'])]
        )
    )
Beispiel #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"]
Beispiel #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"]
Beispiel #25
0
def test_top_level_string_single_match():
    assert losser.query("^title$", {"title": "my title"}) == "my title"
Beispiel #26
0
def test_boolean():
    assert losser.query([], False) == False
Beispiel #27
0
def test_none():
    assert losser.query([], None) == None
Beispiel #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"
Beispiel #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"
Beispiel #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"]
Beispiel #31
0
def test_boolean():
    assert losser.query([], False) == False
Beispiel #32
0
def test_string():
    assert losser.query([], "foo") == "foo"
Beispiel #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"]
Beispiel #34
0
def test_string_with_strip():
    assert losser.query([], " foo  ", strip=True) == "foo"
Beispiel #35
0
def test_top_level_string_single_match():
    assert losser.query("^title$", {"title": "my title"}) == "my title"
Beispiel #36
0
def test_string_with_strip():
    assert losser.query([], " foo  ", strip=True) == "foo"
Beispiel #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"]
Beispiel #38
0
def test_string():
    assert losser.query([], "foo") == "foo"
Beispiel #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"]
Beispiel #40
0
def test_none():
    assert losser.query([], None) == None
Beispiel #41
0
def test_number():
    assert losser.query([], 42) == 42
Beispiel #42
0
def test_number():
    assert losser.query([], 42) == 42