From 591b58c6d9a4f315dc855d5150381c65a6c710c1 Mon Sep 17 00:00:00 2001 From: Vitaly Bogdanov Date: Sat, 30 Mar 2024 09:00:09 +0300 Subject: [PATCH 1/2] Fix pytest warning Classes prefixed with Test... automatically considered as test classes. --- python/tests/test_custom_space.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/tests/test_custom_space.py b/python/tests/test_custom_space.py index cef927c05..e7ff08aa4 100644 --- a/python/tests/test_custom_space.py +++ b/python/tests/test_custom_space.py @@ -3,7 +3,7 @@ from hyperon import * from test_common import HyperonTestCase -class TestSpace(AbstractSpace): +class CustomSpace(AbstractSpace): def __init__(self, unwrap=True): super().__init__() @@ -66,7 +66,7 @@ class CustomSpaceTest(HyperonTestCase): def test_custom_space(self): - test_space = TestSpace() + test_space = CustomSpace() test_space.test_attrib = "Test Space Payload Attrib" kb = SpaceRef(test_space) @@ -78,7 +78,7 @@ def test_custom_space(self): self.assertEqualNoOrder(kb.get_atoms(), [S("a"), S("b")]) def test_remove(self): - kb = SpaceRef(TestSpace()) + kb = SpaceRef(CustomSpace()) kb.add_atom(S("a")) kb.add_atom(S("b")) kb.add_atom(S("c")) @@ -88,7 +88,7 @@ def test_remove(self): self.assertEqualNoOrder(kb.get_atoms(), [S("a"), S("c")]) def test_replace(self): - kb = SpaceRef(TestSpace()) + kb = SpaceRef(CustomSpace()) kb.add_atom(S("a")) kb.add_atom(S("b")) kb.add_atom(S("c")) @@ -97,7 +97,7 @@ def test_replace(self): self.assertEqualNoOrder(kb.get_atoms(), [S("a"), S("d"), S("c")]) def test_query(self): - kb = SpaceRef(TestSpace()) + kb = SpaceRef(CustomSpace()) kb.add_atom(E(S("A"), S("B"))) kb.add_atom(E(S("C"), S("D"))) # Checking that multiple matches can be returned @@ -110,7 +110,7 @@ def test_atom_containing_space(self): m = MeTTa(env_builder=Environment.test_env()) # Make a little space and add it to the MeTTa interpreter's space - little_space = SpaceRef(TestSpace()) + little_space = SpaceRef(CustomSpace()) little_space.add_atom(E(S("A"), S("B"))) space_atom = G(little_space) m.space().add_atom(E(S("little-space"), space_atom)) @@ -127,7 +127,7 @@ def test_atom_containing_space(self): little_space.add_atom(E(S("big-space"), G(m.space()))) def test_match_nested_custom_space(self): - nested = SpaceRef(TestSpace()) + nested = SpaceRef(CustomSpace()) nested.add_atom(E(S("A"), S("B"))) space_atom = G(nested) @@ -139,7 +139,7 @@ def test_match_nested_custom_space(self): def test_runner_with_custom_space(self): - test_space = TestSpace() + test_space = CustomSpace() test_space.test_attrib = "Test Space Payload Attrib" space = SpaceRef(test_space) From 5f223ca6044e07623e154a64677acee9f9eca7b2 Mon Sep 17 00:00:00 2001 From: Vitaly Bogdanov Date: Sat, 30 Mar 2024 09:08:19 +0300 Subject: [PATCH 2/2] Fix unit tests which loads data from current dir Change current dir to the parent dir of the test. --- python/tests/test_common.py | 4 ++++ python/tests/test_extend.py | 4 ++++ python/tests/test_load.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/python/tests/test_common.py b/python/tests/test_common.py index 418dcef54..ceacc271d 100644 --- a/python/tests/test_common.py +++ b/python/tests/test_common.py @@ -1,4 +1,5 @@ import unittest +import os from hyperon import atoms_are_equivalent @@ -37,6 +38,9 @@ def areEqualMettaRunResults(a, b): return False return True +def change_dir_to_parent_of(file): + os.chdir(os.path.dirname(file)) + class HyperonTestCase(unittest.TestCase): def __init__(self, methodName): diff --git a/python/tests/test_extend.py b/python/tests/test_extend.py index 5736bf324..53edd5ee3 100644 --- a/python/tests/test_extend.py +++ b/python/tests/test_extend.py @@ -1,9 +1,13 @@ import unittest from hyperon import * +from test_common import change_dir_to_parent_of class ExtendTest(unittest.TestCase): + def setUp(self): + change_dir_to_parent_of(__file__) + def test_extend(self): ''' This test verifies that importing from a python-implemnted module along with @register_atoms and @register_tokens works diff --git a/python/tests/test_load.py b/python/tests/test_load.py index 3ffe90a31..4baa7d8a2 100644 --- a/python/tests/test_load.py +++ b/python/tests/test_load.py @@ -6,6 +6,9 @@ class LoadAsciiTest(HyperonTestCase): + def setUp(self): + change_dir_to_parent_of(__file__) + def test_load(self): metta = MeTTa() test_file = "test_load.metta"