Exemple #1
0
    def test_empty(self):
        from dictknife import diff

        d = {}
        q = {"a": {"b": {"c": "d"}}}
        actual = self._callFUT(d, q)
        self.assertFalse(list(diff(actual, {"a": {"b": {"c": "d"}}})))
Exemple #2
0
    def test_it(self):
        from dictknife import diff

        d = {
            "title": "Goodbye!",
            "author": {"givenName": "John", "familyName": "Doe"},
            "tags": ["example", "sample"],
            "content": "This will be unchanged",
        }

        q = {
            "title": "Hello!",
            "phoneNumber": "+01-123-456-7890",
            "author": {"familyName": None},
            "tags": ["example"],
        }

        expected = {
            "title": "Hello!",
            "author": {"givenName": "John"},
            "tags": ["example"],
            "content": "This will be unchanged",
            "phoneNumber": "+01-123-456-7890",
        }

        actual = self._callFUT(d, q)
        self.assertFalse(list(diff(expected, actual)))
Exemple #3
0
from urllib import parse as p
from dictknife import diff


def is_ascii(u):
    try:
        u.encode("ascii")
        return True
    except:
        return False


def f(s):
    s = s.replace("_", ",")
    return "/".join([
        x if not x or is_ascii(x[0]) else p.quote(x) for x in s.split("/")
    ]).lower()


with open("/tmp/names.txt") as rf:
    rawdata = rf.readlines()

data = sorted(rawdata, key=f)
for line in diff(rawdata, data):
    print(line)
from urllib import parse as p
from dictknife import diff


def is_ascii(u):
    try:
        u.encode("ascii")
        return True
    except:
        return False


def f(s):
    s = s.replace("_", ",")
    return "/".join([x if not x or is_ascii(x[0]) else p.quote(x) for x in s.split("/")]).lower()


with open("/tmp/names.txt") as rf:
    rawdata = rf.readlines()

data = sorted(rawdata, key=f)
for line in diff(rawdata, data):
    print(line)

Exemple #5
0
    def assert_defs(self, actual, expected):
        from dictknife import diff

        self.assertEqual("\n".join(diff(expected, actual)), "")