Skip to content

Commit

Permalink
Update test paths - included TESTS_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcurbelo committed Sep 2, 2024
1 parent 0657e1c commit 0eb16c6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 66 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/go-rxr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,18 @@ jobs:
- name: Check out the code
uses: actions/checkout@v3

- name: Move code up one directory level
run: |
mv ${GITHUB_WORKSPACE}/GO-RXR/* ${GITHUB_WORKSPACE}
rmdir ${GITHUB_WORKSPACE}/GO-RXR
- name: Set environment variable for root directory
run: echo "ROOT_DIR=$(pwd)" >> $GITHUB_ENV

- name: Print ROOT_DIR
run: echo "ROOT_DIR is $ROOT_DIR"

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10.14'

- name: Install package
run: |
pip install .
- name: Run tests
run: |
python -m unittest discover -s TESTS -p "test_*.py"
python -m unittest discover -s TESTS -p "test_*.py"
5 changes: 2 additions & 3 deletions TESTS/run_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Add the parent directory to the system path
sys.path.append(parent_dir)

from UTILS import ROOT_DIR
from UTILS import TESTS_DIR

def load_tests_from_file(test_file):
# Load the test suite from the given file
Expand All @@ -33,5 +33,4 @@ def discover_and_run_tests(test_dir):

if __name__ == "__main__":

test_dir = ROOT_DIR + '/TESTS'
discover_and_run_tests(test_dir)
discover_and_run_tests(TESTS_DIR)
12 changes: 4 additions & 8 deletions TESTS/test_data_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
material_structure as ms,
data_structure as ds,
global_optimization as go,
ROOT_DIR,
ROOT_DIR, TESTS_DIR,
)
from UTILS.global_optimization import changeSampleParams
from GUI_GO import checkscript
Expand All @@ -26,14 +26,10 @@ class TestDataFitting(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR
self.filename = 'Pim4uc_test.h5'
self.my_path = self.root_dir + '/TESTS/test_data/' + self.filename
self.script_path = self.root_dir + '/TESTS/test_data/test_script.txt'

print('self.root_dir', self.root_dir)
print('self.my_path', self.my_path)
print('self.script_path', self.script_path)
self.my_path = self.tests_dir + '/test_data/' + self.filename
self.script_path = self.tests_dir + '/test_data/test_script.txt'

def test_ChangeSampleParams_element(self):

Expand Down
13 changes: 5 additions & 8 deletions TESTS/test_data_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import unittest
from UTILS.data_structure import *
from UTILS import ROOT_DIR
from UTILS import TESTS_DIR


# Define epsilon using np.finfo(float).eps
Expand All @@ -24,17 +24,14 @@ class TestMaterialStructure(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR

self.filename1 = 'Pim7uc.all'
self.my_path1 = self.root_dir + '/TESTS/test_data/' + self.filename1
self.my_path1 = self.tests_dir + '/test_data/' + self.filename1

self.filename2 = 'Pim7uc.pkl'
self.my_path2 = self.root_dir + '/TESTS/test_data/' + self.filename2




self.my_path2 = self.tests_dir + '/test_data/' + self.filename2

def test_getTitleInfo(self):
# testing function that retrieves information from ReMagX data names
tests = ['1_A_800.0_S', '57_A_515.2_P','42-43_A_55.5_S-P_Asymm', '75_E499.93_Th20.0_S',
Expand Down
20 changes: 10 additions & 10 deletions TESTS/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importlib.reload(ms)
import numpy as np

from UTILS import ROOT_DIR
from UTILS import TESTS_DIR

# Define epsilon using np.finfo(float).eps
EPS = np.sqrt(np.finfo(float).eps)
Expand All @@ -28,31 +28,31 @@ class TestDensityProfile(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR

self.filename1 = 'simple_density.pkl'
self.my_path1 = self.root_dir + '/TESTS/test_data/' + self.filename1
self.my_path1 = self.tests_dir + '/test_data/' + self.filename1

self.filename2 = 'var_density.pkl'
self.my_path2 = self.root_dir + '/TESTS/test_data/' + self.filename2
self.my_path2 = self.tests_dir + '/test_data/' + self.filename2

self.filename3 = 'surfaceImpurity_density.pkl'
self.my_path3 = self.root_dir + '/TESTS/test_data/' + self.filename3
self.my_path3 = self.tests_dir + '/test_data/' + self.filename3

self.filename4 = 'unitCell_density.pkl'
self.my_path4 = self.root_dir + '/TESTS/test_data/' + self.filename4
self.my_path4 = self.tests_dir + '/test_data/' + self.filename4

self.filename5 = 'linked_density.pkl'
self.my_path5 = self.root_dir + '/TESTS/test_data/' + self.filename5
self.my_path5 = self.tests_dir + '/test_data/' + self.filename5

self.filename6 = 'mag_density.pkl'
self.my_path6 = self.root_dir + '/TESTS/test_data/' + self.filename6
self.my_path6 = self.tests_dir + '/test_data/' + self.filename6

self.filename7 = 'dummy_density.pkl'
self.my_path7 = self.root_dir + '/TESTS/test_data/' + self.filename7
self.my_path7 = self.tests_dir + '/test_data/' + self.filename7

self.filename8 = 'negative_density.pkl'
self.my_path8 = self.root_dir + '/TESTS/test_data/' + self.filename8
self.my_path8 = self.tests_dir + '/test_data/' + self.filename8


def test_simple_profile(self):
Expand Down
8 changes: 4 additions & 4 deletions TESTS/test_material_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UTILS.material_model as mm
import numpy as np
import UTILS.material_structure as ms
from UTILS import ROOT_DIR
from UTILS import TESTS_DIR
import unittest

# This test script can be executed by inputting
Expand All @@ -21,13 +21,13 @@ class TestMaterialModel(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR

self.filename1 = 'optical_energy.txt'
self.my_path1 = self.root_dir + '/TESTS/test_data/' + self.filename1
self.my_path1 = self.tests_dir + '/test_data/' + self.filename1

self.filename2 = 'optical_theta.txt'
self.my_path2 = self.root_dir + '/TESTS/test_data/' + self.filename2
self.my_path2 = self.tests_dir + '/test_data/' + self.filename2


def test_form_factors_E(self):
Expand Down
12 changes: 6 additions & 6 deletions TESTS/test_material_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import UTILS.material_structure as ms
import pickle
import UTILS.data_structure as ds
from UTILS import ROOT_DIR
from UTILS import TESTS_DIR

# This test script can be executed by inputting
# -> python -m unittest -v test_material_structure.py
Expand All @@ -22,19 +22,19 @@ class TestMaterialStructure(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR

self.filename1 = 'optical_energy.txt'
self.my_path1 = self.root_dir + '/TESTS/test_data/' + self.filename1
self.my_path1 = self.tests_dir + '/test_data/' + self.filename1

self.filename2 = 'ALS_test.pkl'
self.my_path2 = self.root_dir + '/TESTS/test_data/' + self.filename2
self.my_path2 = self.tests_dir + '/test_data/' + self.filename2

self.filename3 = '7uc_sample_test.h5'
self.my_path3 = self.root_dir + '/TESTS/test_data/' + self.filename3
self.my_path3 = self.tests_dir + '/test_data/' + self.filename3

self.filename4 = 'LSMO_test.h5'
self.my_path4 = self.root_dir + '/TESTS/test_data/' + self.filename4
self.my_path4 = self.tests_dir + '/test_data/' + self.filename4


def test_adaptive_layer_segmentation(self):
Expand Down
12 changes: 6 additions & 6 deletions TESTS/test_reflectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np
import UTILS.material_structure as ms
from UTILS import ROOT_DIR
from UTILS import TESTS_DIR
import unittest

# This test script can be executed by inputting
Expand All @@ -27,19 +27,19 @@ class TestReflectivity(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

self.root_dir = ROOT_DIR
self.tests_dir = TESTS_DIR

self.filename1 = 'Si-Al-10A-550.txt'
self.my_path1 = self.root_dir + '/TESTS/test_data/' + self.filename1
self.my_path1 = self.tests_dir + '/test_data/' + self.filename1

self.filename2 = 'Si-Al-50A-550.txt'
self.my_path2 = self.root_dir + '/TESTS/test_data/' + self.filename2
self.my_path2 = self.tests_dir + '/test_data/' + self.filename2

self.filename3 = 'AgBr-AlAs-50A-550.txt'
self.my_path3 = self.root_dir + '/TESTS/test_data/' + self.filename3
self.my_path3 = self.tests_dir + '/test_data/' + self.filename3

self.filename4 = 'AgBr-AlAs-50A-550_pi.txt'
self.my_path4 = self.root_dir + '/TESTS/test_data/' + self.filename4
self.my_path4 = self.tests_dir + '/test_data/' + self.filename4


def test_single_element_sigma(self):
Expand Down
16 changes: 5 additions & 11 deletions UTILS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
import os
import sys

# Get the root directory of the project
ROOT_DIR = os.getenv("ROOT_DIR", os.getcwd())
# Get the current working directory as the root directory
CURRENT_DIR = os.getcwd()

# Debugging output to see the initial ROOT_DIR value
print(f"Initial ROOT_DIR: {ROOT_DIR}")
ROOT_DIR = os.path.abspath(CURRENT_DIR)

# Adjust ROOT_DIR if necessary
while os.path.basename(ROOT_DIR) != 'GO-RXR':
ROOT_DIR = os.path.dirname(ROOT_DIR)
# Check if we have reached the root of the filesystem
if ROOT_DIR == os.path.dirname(ROOT_DIR):
print("Root directory not found")
break

# Debugging output to see the final ROOT_DIR value
print(f"Final ROOT_DIR: {ROOT_DIR}")

DATA_DIR = os.path.join(ROOT_DIR, 'DATA')

# Debugging output to see the DATA_DIR value
print(f"DATA_DIR: {DATA_DIR}")
TESTS_DIR = os.path.join(ROOT_DIR, 'TESTS')

# Append the root directory to the Python path
sys.path.append(ROOT_DIR)

0 comments on commit 0eb16c6

Please sign in to comment.