Exemple #1
0
 def test_slash(self):
     k = Keyword("/")
     s = Symbol("/")
     assert k.name == "/"
     assert s.name == "/"
     assert k.namespace is None
     assert s.namespace is None
Exemple #2
0
 def test_namespaced(self):
     k = Keyword("ns/name")
     s = Symbol("ns/name")
     assert k.name == "name"
     assert s.name == "name"
     assert k.namespace == "ns"
     assert s.namespace == "ns"
Exemple #3
0
def value_symbol(state, p):
    return Symbol(p[0].value)
Exemple #4
0
def regression(name, value):
    class RegressionTest(RegressionBaseTest):

        def test_roundtrip(self):
            in_data = value
            io = StringIO()
            w = Writer(io, "json")
            w.write(in_data)
            r = Reader("json")
            out_data = r.read(StringIO(io.getvalue()))
            self.assertEqual(in_data, out_data)

    globals()["test_" + name + "_json"] = RegressionTest

regression("cache_consistency", ({"Problem?":true},
                                  Symbol("Here"),
                                  Symbol("Here")))
regression("one_pair_frozendict", frozendict({"a":1}))
regression("json_int_max", (2**53+100, 2**63+100))
regression("newline_in_string", "a\nb")
regression("big_decimal", Decimal("190234710272.2394720347203642836434"))

def json_int_boundary(value, expected_type):
    class JsonIntBoundaryTest(unittest.TestCase):

        def test_max_is_number(self):
            for protocol in ("json", "json_verbose"):
                io = StringIO()
                w = Writer(io, protocol)
                w.write([value])
                actual_type = type(json.loads(io.getvalue())[0])
                if not False in [
                        isnan(v) and isnan(d) or isnan(v) == isnan(d)
                        for v, d in zip(val, data)
                ]:
                    return unittest.TestCase.assertEqual(
                        self, filter(lambda x: not isnan(x), val),
                        filter(lambda x: not isnan(x), data))
                else:
                    e.args += (name, "failed")
                    raise

    globals()["test_" + name + "_json"] = ExemplarTest


ARRAY_SIMPLE = (1, 2, 3)
ARRAY_MIXED = (0, 1, 2.0, true, false, 'five', Keyword("six"), Symbol("seven"),
               '~eight', None)
ARRAY_NESTED = (ARRAY_SIMPLE, ARRAY_MIXED)
SMALL_STRINGS = ("", "a", "ab", "abc", "abcd", "abcde", "abcdef")
POWERS_OF_TWO = tuple(map(lambda x: pow(2, x), range(66)))
INTERESTING_INTS = tuple(
    mapcat(lambda x: ints_centered_on(x, 2), POWERS_OF_TWO))

SYM_STRS = ["a", "ab", "abc", "abcd", "abcde", "a1", "b2", "c3", "a_b"]
SYMBOLS = tuple(map(Symbol, SYM_STRS))
KEYWORDS = tuple(map(Keyword, SYM_STRS))

UUIDS = (UUID('5a2cbea3-e8c6-428b-b525-21239370dd55'),
         UUID('d1dc64fa-da79-444b-9fa4-d4412f427289'),
         UUID('501a978e-3a3e-4060-b3be-1cf2bd4b1a38'),
         UUID('b3ba141a-a776-48e4-9fae-a28ea8571f58'))
Exemple #6
0
                if not False in [
                        isnan(v) and isnan(d) or isnan(v) == isnan(d)
                        for v, d in zip(val, data)
                ]:
                    return unittest.TestCase.assertEqual(
                        self, filter(lambda x: not isnan(x), val),
                        filter(lambda x: not isnan(x), data))
                else:
                    e.args += (name, "failed")
                    raise

    globals()["test_" + name + "_json"] = ExemplarTest


ARRAY_SIMPLE = (1, 2, 3)
ARRAY_MIXED = (0, 1, 2.0, true, false, 'five', Keyword("six"), Symbol("seven"),
               '~eight', None)
ARRAY_NESTED = (ARRAY_SIMPLE, ARRAY_MIXED)
SMALL_STRINGS = ("", "a", "ab", "abc", "abcd", "abcde", "abcdef")
POWERS_OF_TWO = tuple(map(lambda x: pow(2, x), range(66)))
INTERESTING_INTS = tuple(
    mapcat(lambda x: ints_centered_on(x, 2), POWERS_OF_TWO))

SYM_STRS = ["a", "ab", "abc", "abcd", "abcde", "a1", "b2", "c3", "a_b"]
SYMBOLS = tuple(map(Symbol, SYM_STRS))
KEYWORDS = tuple(map(Keyword, SYM_STRS))

UUIDS = (UUID('5a2cbea3-e8c6-428b-b525-21239370dd55'),
         UUID('d1dc64fa-da79-444b-9fa4-d4412f427289'),
         UUID('501a978e-3a3e-4060-b3be-1cf2bd4b1a38'),
         UUID('b3ba141a-a776-48e4-9fae-a28ea8571f58'))
Exemple #7
0
 def __call__(self, value):
     return Symbol(value.replace("_", "-"))
Exemple #8
0
 def __getattr__(self, value):
     return Symbol(value.replace("_", "-"))
Exemple #9
0
 def __call__(self, value):
     return Symbol("?" + value)
Exemple #10
0
 def __getattr__(self, value):
     return Symbol("?" + value)
Exemple #11
0
    def __getattr__(self, value):
        return Symbol(value.replace("_", "-"))

    def __call__(self, value):
        return Symbol(value.replace("_", "-"))


def cmap(**kwargs):
    prefix = kwargs.pop("prefix", None)
    maybe_prefix = (lambda x: x) if prefix is None else (
        lambda x: prefix + "/" + x)

    return {Keyword(maybe_prefix(k)): v for k, v in kwargs.iteritems()}


K = KeywordUnicorn()
S = SymbolUnicorn()
V = VariableUnicorn()

E = Symbol("?e")
_ = Symbol("_")
FIND = Keyword("find")
WHERE = Keyword("where")
IN = Keyword("in")
D = Symbol("$")
GT = Symbol(">")
GTE = Symbol(">=")
LT = Symbol("<")
LTE = Symbol("<=")
NE = Symbol("!=")
Exemple #12
0
 def test_named(self):
     k = Keyword("blah")
     s = Symbol("blah")
     assert k.name == "blah"
     assert s.name == "blah"