From 87f0e0abbb9bf80c4137c1699df4b367b3ec06f2 Mon Sep 17 00:00:00 2001 From: David Rajaratnam Date: Mon, 6 May 2024 21:53:04 +1000 Subject: [PATCH] Added example of FactBase.asp_str(sorted=True) --- tests/test_orm_factbase.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/test_orm_factbase.py b/tests/test_orm_factbase.py index aa3491e..d9943a1 100644 --- a/tests/test_orm_factbase.py +++ b/tests/test_orm_factbase.py @@ -589,25 +589,16 @@ class Meta: # Test the asp output string with the sorted flag # -------------------------------------------------------------------------- def test_factbase_aspstr_sorted(self): - class A(Predicate): + class A(Predicate, name="bb"): a = IntegerField - class Meta: - name = "bb" - - class B(Predicate): + class B(Predicate, name="aa"): a = IntegerField - class Meta: - name = "aa" - - class C(Predicate): + class C(Predicate, name="aa"): a = IntegerField b = IntegerField - class Meta: - name = "aa" - def tostr(facts): return ".\n".join([str(f) for f in facts]) @@ -713,6 +704,20 @@ class Meta: self.assertIn(expected_sig_predC, result) self.assertIn(expected_sig_predA, result) + # -------------------------------------------------------------------------- + # Test the asp output string with sorting and incomparable terms + # -------------------------------------------------------------------------- + def test_factbase_aspstr_sorted_incomparable(self): + class A(Predicate): + x = field(SimpleField) + + fb = FactBase([A(1), A(2), A("b")]) + q = fb.query(A).ordered() + self.assertTrue(list(q.all()) == [A(1), A(2), A("b")]) + tmpstr1 = ".\n".join(f"{x}" for x in q.all()) + ".\n" + tmpstr2 = fb.asp_str(sorted=True) + self.assertTrue(tmpstr1 == tmpstr2) + # ------------------------------------------------------------------------------ # Test QueryAPI version 1 (called via FactBase.select() and FactBase.delete())