def test_slash(self): k = Keyword("/") s = Symbol("/") assert k.name == "/" assert s.name == "/" assert k.namespace is None assert s.namespace is None
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"
def field(ident, db_type, doc, cardinality="one"): return { K.db.ident: Keyword(ident), Keyword("db/valueType"): Keyword("db.type/" + db_type), Keyword("db/cardinality"): Keyword("db.cardinality/" + cardinality), Keyword("db/doc"): doc, }
def _request(action, datoms): io = StringIO() writer = Writer(io) writer.write({Keyword("content"): datoms}) r = post("http://127.0.0.1:8080/" + action, data=io.getvalue().encode('utf-8'), headers={ 'Content-Type': "application/transit+json; charset=utf-8", }) try: reader = Reader() data = reader.read(StringIO(r.content)) except: print "ILLEGAL RESPONSE: " try: print r.content except UnboundLocalError: print "NO RESPONSE" pass if not r: raise DatomicError(data[Keyword("content")]) else: return data[Keyword("content")]
def value_keyword_ns(state, p): return Keyword(p[1].value)
def make_hash_exemplar(n): exemplar("map_%s_nested" % (n, ), { Keyword("f"): hash_of_size(n), Keyword("s"): hash_of_size(n) })
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'))
def array_of_symbools(m, n=None): if n is None: n = m seeds = map(lambda x: Keyword("key" + str(x).zfill(4)), range(0, m)) return take(n, cycle(seeds))
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()}
def __call__(self, value): return Keyword(value)
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("!=")
def test_named(self): k = Keyword("blah") s = Symbol("blah") assert k.name == "blah" assert s.name == "blah"