Skip to content

Commit

Permalink
Merge pull request #646 from vsbogd/fix-unittests
Browse files Browse the repository at this point in the history
Make unit tests passing if they are started from any folder
  • Loading branch information
Necr0x0Der authored Mar 30, 2024
2 parents 3729f2e + 5f223ca commit bac7cc3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions python/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import os

from hyperon import atoms_are_equivalent

Expand Down Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions python/tests/test_custom_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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)

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions python/tests/test_extend.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bac7cc3

Please sign in to comment.