Skip to content

Commit

Permalink
Black/isort formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daveraja committed May 6, 2024
1 parent 87f0e0a commit 49d4d3a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
8 changes: 5 additions & 3 deletions clorm/orm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ class DateField(StringField):
``FactBase```. Defaults to ``False``.
"""

def __init__(self, default: Any = MISSING, index: Any = MISSING) -> None:
self._index = index if index is not MISSING else False

Expand Down Expand Up @@ -1390,10 +1391,11 @@ def _process_cmplx_value(v):
'Invalid default value "{}" for {}'.format(default, type(self).__name__)
)
else:

def _process_default():
return _process_value(default())
self._default = (True, _process_default)

self._default = (True, _process_default)

@staticmethod
@abc.abstractmethod
Expand Down Expand Up @@ -2800,7 +2802,7 @@ def _generate_dynamic_predicate_functions(class_name: str, namespace: Dict) -> N

template = PREDICATE_TEMPLATE.format(pdefn=pdefn)
predicate_functions = expand_template(template, **expansions)
# print(f"INIT {class_name}:\n\n{predicate_functions}\n\n")
# print(f"INIT {class_name}:\n\n{predicate_functions}\n\n")

ldict: Dict[str, Any] = {}
exec(predicate_functions, gdict, ldict)
Expand Down Expand Up @@ -3179,6 +3181,7 @@ def _cltopy(v):
# A Metaclass for the Predicate base class
# ------------------------------------------------------------------------------


@__dataclass_transform__(field_descriptors=(field,))
class _PredicateMeta(type):
if TYPE_CHECKING:
Expand Down Expand Up @@ -3460,7 +3463,6 @@ def __gt__(self, other):
"""Overloaded boolean operator."""
raise NotImplementedError("Predicate.__gt__() must be overriden")


@abc.abstractmethod
def __hash__(self):
"""Overload the hash function."""
Expand Down
1 change: 1 addition & 0 deletions clorm/orm/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def _try_to_convert(tup, possiblepath):
return (args[0], _try_to_convert(args[1], args[0]))
return args


class StandardComparator(Comparator):
class Preference(enum.IntEnum):
LOW = 0
Expand Down
4 changes: 2 additions & 2 deletions clorm/orm/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def add_spaces(num, text):
end = line.find(r"%}", start)
if end == -1:
raise ValueError("Bad template expansion in {line}")
keyword = line[start + 2:end]
keyword = line[start + 2 : end]
text = add_spaces(start, kwargs[keyword])
line = line[0:start] + text + line[end + 2:]
line = line[0:start] + text + line[end + 2 :]
outlines.append(line)
return "\n".join(outlines)

Expand Down
1 change: 1 addition & 0 deletions tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def check_errmsg_contains(contmsg, ctx):
#
# ------------------------------------------------------------------------------


def to_tuple(value):
"""Recursively convert a predicate/normal tuple into a Python tuple"""
if isinstance(value, tuple) or (isinstance(value, Predicate) and value.meta.is_tuple):
Expand Down
7 changes: 0 additions & 7 deletions tests/test_orm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,12 +1022,10 @@ class Blah(object):
clresult = td.pytocl((1, "blah"))
self.assertEqual(clresult, clob)


# --------------------------------------------------------------------------
# Test that we define the new comparison operators in the template
# --------------------------------------------------------------------------
def test_predicate_comparison_operator_creation(self):

class P(Predicate, name="p"):
a = IntegerField
b = ConstantField
Expand Down Expand Up @@ -1224,7 +1222,6 @@ class T(Predicate):
self.assertTrue(p1.tuple_ != tuple1)
self.assertFalse(tuple(p1.tuple_) != tuple1)


# --------------------------------------------------------------------------
# Testing comparison between tuple fields where the corresponding python tuples
# can contain incomparible objects.
Expand All @@ -1250,8 +1247,6 @@ class Q(Predicate):
self.assertFalse(ptuple("a", "b") < qtuple(1, 2))
self.assertFalse(ptuple("a", "b") <= qtuple(1, 2))



# --------------------------------------------------------------------------
# Test predicates with default fields
# --------------------------------------------------------------------------
Expand Down Expand Up @@ -2184,7 +2179,6 @@ class P(Predicate):
self.assertTrue((neg_p2.raw < p2.raw) == (neg_p2 < p2))
self.assertTrue((p1.raw < p2.raw) == (p1 < p2))


# --------------------------------------------------------------------------
# Test a simple predicate with a field that has a function default
# --------------------------------------------------------------------------
Expand Down Expand Up @@ -2552,7 +2546,6 @@ class AComplex(ComplexTerm):
self.assertTrue(f3 > f2)
self.assertEqual(f3, f4)


# --------------------------------------------------------------------------
# Test unifying a symbol with a predicate
# --------------------------------------------------------------------------
Expand Down
24 changes: 14 additions & 10 deletions tests/test_orm_factbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
ConstantField,
FactBase,
IntegerField,
SimpleField,
Predicate,
SimpleField,
StringField,
alias,
asc,
Expand Down Expand Up @@ -1708,6 +1708,7 @@ def test_api_bad_join_statement(self):
# Test some special cases involving passing a Python tuple instead of using the clorm tuple.
# ------------------------------------------------------------------------------------------


class QueryWithTupleTestCase(unittest.TestCase):
def setUp(self):
class F(Predicate):
Expand All @@ -1723,20 +1724,26 @@ class G(Predicate):

self.factbase = FactBase(
[
F((1, "a"), "i"), F((2, "b"), "j"), F((3, "a"), "k"),
G(("a", "a"), "x"), G((2, "b"), "y"), G(("e", "e"), "z")
F((1, "a"), "i"),
F((2, "b"), "j"),
F((3, "a"), "k"),
G(("a", "a"), "x"),
G((2, "b"), "y"),
G(("e", "e"), "z"),
]
)


# --------------------------------------------------------------------------
# Some tuple predicate instance comparisons
# --------------------------------------------------------------------------
def test_basic_clorm_tuple_in_comparison(self):
G = self.G
fb = self.factbase
cltuple = G.atuple.meta.complex
expected = [G((2, "b"), "y"), G(("a", "a"), "x"), ]
expected = [
G((2, "b"), "y"),
G(("a", "a"), "x"),
]

# NOTE: the version with python tuples fails to find the matching tuples because we can
# no longer directly compare python tuples with clorm tuples.
Expand All @@ -1750,7 +1757,6 @@ def test_basic_clorm_tuple_in_comparison(self):
q2 = fb.query(G).where(in_(G.atuple, cltuples)).ordered()
self.assertEqual(list(q2.all()), expected)


# --------------------------------------------------------------------------
# Complex query where the join is on a tuple object
# --------------------------------------------------------------------------
Expand All @@ -1764,7 +1770,6 @@ def test_api_join_on_clorm_tuple(self):
expected = [(G((2, "b"), "y"), F((2, "b"), "j"))]
self.assertEqual(list(q.all()), expected)


# --------------------------------------------------------------------------
# Complex query with a where containing a tuple
# --------------------------------------------------------------------------
Expand All @@ -1791,11 +1796,10 @@ def test_api_sorting_with_incomparable_elements(self):
fb = self.factbase

q = fb.query(G).order_by(G.atuple)
expected = [
G((2, "b"), "y"), G(("a", "a"), "x"), G(("e", "e"), "z")
]
expected = [G((2, "b"), "y"), G(("a", "a"), "x"), G(("e", "e"), "z")]
self.assertEqual(list(q.all()), expected)


# ------------------------------------------------------------------------------
# Tests for additional V2 select join statements
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 49d4d3a

Please sign in to comment.