forked from trueagi-io/hyperon-experimental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_modules.py
38 lines (30 loc) · 1.66 KB
/
test_modules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import unittest
from test_common import *
from hyperon import *
class ModulesTest(HyperonTestCase):
def test_python_file_mod_format(self):
"""
Tests that a MeTTa module, implemented as a '.py', file will be correctly identified when the
module system searches in the include directory, and then that it will be sucessfully loaded
"""
runner = MeTTa(env_builder=Environment.custom_env(working_dir=os.getcwd(), disable_config=True, is_test=True))
#Make sure the `import!` operation finds the pyfile_test_mod.py file, recognizes it as a
# MeTTa module using the PythonFileModuleFormat, and loads the MeTTa module it sucessfully
result = runner.run("!(import! &self pyfile_test_mod)")
#Validate that we didn't get an error loading nor importing the module
self.assertFalse(atom_is_error(result[0][0]))
#Validate that we can access an atom from the module, and it's the atom we expect
result = runner.parse_all("pi_test")
self.assertEqual(result[0].get_object().content, 3.14159)
def test_include(self):
metta = MeTTa(env_builder=Environment.custom_env(working_dir=os.getcwd(), disable_config=True, is_test=True))
result = metta.run("""
(three isprime)
!(match &self ($x isprime) $x)
!(include test_include)
!(match &self ($x isprime) $x)
""")
self.assertTrue(areEqualNoOrder(result[0], [S("three")]))
self.assertTrue(areEqualNoOrder(result[2], [S("three"), S("five"), S("seven")]))
result = metta.run("!(match &self ($x notprime) $x)")
self.assertEqual(result[0], [S("six")])