diff --git a/.vscode/launch.json b/.vscode/launch.json index 46d4532..c6cff8f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,9 +4,12 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - - - + { + "name": "Python: Module", + "type": "python", + "request": "launch", + "module": "MDAF" + }, { "name": "Python: Current File", "type": "python", diff --git a/MDAF/MDAF.py b/MDAF/MDAF.py index d190ebb..bd96093 100644 --- a/MDAF/MDAF.py +++ b/MDAF/MDAF.py @@ -157,6 +157,8 @@ def writerepresentation(funcpath, charas): file.write(newContent) def representfunc(funcpath, forced = False): + if (funcpath.find('@') == 0): funcpath = path.dirname(__file__) + '/TestFunctions/' + funcpath[1:] + #defining the function name funcname = path.splitext(path.basename(funcpath))[0] # loading the function to be represented @@ -217,6 +219,8 @@ def representfunc(funcpath, forced = False): def doe(heuristicpath, testfunctionpaths, args): + for i,path in enumerate(testfunctionpaths): if (path.find('@') == 0): testfunctionpaths[i] = path.dirname(__file__) + '/TestFunctions/' + testfunctionpaths[1:] + if (heuristicpath.find('@') == 0): heuristicpath = path.dirname(__file__) + '/TestFunctions/' + heuristicpath[1:] #defining the function's name funcnames = [path.splitext(path.basename(funcpath))[0] for funcpath in testfunctionpaths] diff --git a/MDAF/__pycache__/MDAF.cpython-39.pyc b/MDAF/__pycache__/MDAF.cpython-39.pyc new file mode 100644 index 0000000..e140d5d Binary files /dev/null and b/MDAF/__pycache__/MDAF.cpython-39.pyc differ diff --git a/MDAF/__pycache__/__init__.cpython-39.pyc b/MDAF/__pycache__/__init__.cpython-39.pyc index 8a31932..da1d00d 100644 Binary files a/MDAF/__pycache__/__init__.cpython-39.pyc and b/MDAF/__pycache__/__init__.cpython-39.pyc differ diff --git a/tests/__pycache__/Bukin2.cpython-39.pyc b/tests/__pycache__/Bukin2.cpython-39.pyc index d845b42..abeae18 100644 Binary files a/tests/__pycache__/Bukin2.cpython-39.pyc and b/tests/__pycache__/Bukin2.cpython-39.pyc differ diff --git a/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc b/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc index fc1ce98..1635b6a 100644 Binary files a/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc and b/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc differ diff --git a/tests/test_flows.py b/tests/test_flows.py index 71285f5..7ff674d 100644 --- a/tests/test_flows.py +++ b/tests/test_flows.py @@ -9,20 +9,39 @@ from MDAF.MDAF import doe # Testing the test function representation workflow class Test_representfunc(unittest.TestCase): - def testoutput(self): + def testexternalfuncs(self): """ Test that the function can calculate the representation and write to the function docstring """ funcpath = 'tests/Bukin2.py' - funcpath_backup = 'tests/Bukin2.py.old' + #funcpath_backup = 'tests/Bukin2.py.old' + results = representfunc(funcpath, forced = True) with open(funcpath,"r") as file: content = file.read() reprCheck = bool(content.find('#_# Represented: 1')) - os.remove(funcpath) - os.replace(funcpath_backup, funcpath) + #os.remove(funcpath) + #os.replace(funcpath_backup, funcpath) + self.assertTrue(reprCheck) + self.assertIsInstance(results, dict) + + def testinternalfuncs(self): + """ + Test that the function can calculate the representation and write to the function docstring + """ + funcpath = '@Bukin2.py' + #funcpath_backup = 'tests/Bukin2.py.old' + + results = representfunc(funcpath, forced = True) + + with open(funcpath,"r") as file: + content = file.read() + reprCheck = bool(content.find('#_# Represented: 1')) + + #os.remove(funcpath) + #os.replace(funcpath_backup, funcpath) self.assertTrue(reprCheck) self.assertIsInstance(results, dict) @@ -39,7 +58,7 @@ class Test_flaccoInstall(unittest.TestCase): # Testing the DOE execution workflow class Test_DOE(unittest.TestCase): - def testoutput(self): + def testexternalfuncs(self): """ Test that it can execute a DOE and output the dictionarry of the results """ @@ -48,6 +67,17 @@ class Test_DOE(unittest.TestCase): args = {"t": 1000, "p": 0.95, "objs": 0} data = doe (heuristicpath, testfunctionpaths, args) self.assertIsInstance(data, dict) + + def testinternalfuncs(self): + """ + Test that it can execute a DOE and output the dictionarry of the results + """ + testfunctionpaths = ["@Bukin2.py"] + heuristicpath = "@SimmulatedAnnealing.py" + args = {"t": 1000, "p": 0.95, "objs": 0} + data = doe (heuristicpath, testfunctionpaths, args) + print(data) + self.assertIsInstance(data, dict) # Testing the surrogate modelling workflow