Skip to content

Commit

Permalink
refactored unit_test data access
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiCheng45 committed Jan 16, 2024
1 parent 9f2bf7c commit 3c2d3ba
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 76 deletions.
15 changes: 3 additions & 12 deletions MDANSE/Tests/UnitTests/Analysis/test_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@
import tempfile
import os
from os import path

import pytest
from icecream import ic
import numpy as np

from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Framework.UserDefinitionStore import UD_STORE

from ..Data.data import short_traj

sys.setrecursionlimit(100000)
ic.disable()

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")


@pytest.fixture(scope="module")
Expand Down
25 changes: 6 additions & 19 deletions MDANSE/Tests/UnitTests/Analysis/test_meansquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@
import tempfile
import os
from os import path
import pytest
from icecream import ic
import numpy as np
import h5py
from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData
from MDANSE.Framework.Jobs.IJob import IJob
from ..Data.data import short_traj


sys.setrecursionlimit(100000)
ic.disable()
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData

# Mean Square Displacements can accept many parameters, most of them optional
# settings['trajectory']=('hdf_trajectory',{})
Expand All @@ -33,14 +27,7 @@
# settings['running_mode']=('running_mode',{})


@pytest.fixture(scope="module")
def trajectory():
trajectory = HDFTrajectoryInputData(short_traj)
trajectory = short_traj
yield trajectory


def test_basic_meansquare(trajectory):
def test_basic_meansquare():
temp_name = tempfile.mktemp()
parameters = {}
parameters["frames"] = (0, 10, 1)
Expand All @@ -54,7 +41,7 @@ def test_basic_meansquare(trajectory):
os.remove(temp_name + ".h5")


def test_parallel_meansquare(trajectory):
def test_parallel_meansquare():
temp_name = tempfile.mktemp()
parameters = {}
parameters["frames"] = (0, 10, 1)
Expand All @@ -79,7 +66,7 @@ def test_parallel_meansquare(trajectory):
os.remove(temp_name2 + ".h5")


def test_atom_selection(trajectory):
def test_atom_selection():
temp_name = tempfile.mktemp()
parameters = {}
parameters["frames"] = (0, 10, 1)
Expand Down
15 changes: 3 additions & 12 deletions MDANSE/Tests/UnitTests/Analysis/test_qvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@
import tempfile
import os
from os import path

import pytest
from icecream import ic
import numpy as np

from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData
from MDANSE.Framework.QVectors.IQVectors import IQVectors
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Framework.UserDefinitionStore import UD_STORE

from ..Data.data import mol_traj as short_traj

sys.setrecursionlimit(100000)
ic.disable()

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")


@pytest.fixture(scope="module")
Expand Down
12 changes: 4 additions & 8 deletions MDANSE/Tests/UnitTests/Analysis/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
IInstrumentResolution,
)
from MDANSE.Framework.Jobs.IJob import IJob
from ..Data.data import mol_traj as short_traj


sys.setrecursionlimit(100000)
ic.disable()

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")


@pytest.fixture(scope="module")
Expand Down
12 changes: 4 additions & 8 deletions MDANSE/Tests/UnitTests/Analysis/test_scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
from icecream import ic
from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData
from MDANSE.Framework.Jobs.IJob import IJob
from ..Data.data import mol_traj as short_traj


sys.setrecursionlimit(100000)
ic.disable()

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")


@pytest.fixture(scope="module")
Expand Down
11 changes: 3 additions & 8 deletions MDANSE/Tests/UnitTests/Analysis/test_thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
import h5py
from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData
from MDANSE.Framework.Jobs.IJob import IJob
from ..Data.data import short_traj


sys.setrecursionlimit(100000)
ic.disable()

_, just_filename = path.split(short_traj)

# now we have the following variables related to the trajectory:
# 1. short_traj (str) - full path to the trajectory
# 2. just_filename (str) - filename of the trajectory
# 3. trajectory (pytest.fixture) - returns an instance of HDFTrajectoryInputData
short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"short_trajectory_after_changes.h5")


@pytest.fixture(scope="module")
Expand Down
Empty file.
File renamed without changes.
6 changes: 0 additions & 6 deletions MDANSE/Tests/UnitTests/Data/data.py

This file was deleted.

Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/molecules/test_chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "co2gas_md3.h5")
os.path.dirname(os.path.realpath(__file__)), "..", "Data", "co2gas_md3.h5")


@pytest.fixture(scope="module")
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/molecules/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


short_traj = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "co2gas_md3.h5")
os.path.dirname(os.path.realpath(__file__)), "..", "Data", "co2gas_md3.h5")


@pytest.fixture(scope="module")
Expand Down
3 changes: 2 additions & 1 deletion MDANSE/Tests/UnitTests/molecules/test_rdkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@


fname = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "CO2GAS-dump-1.pdb")
os.path.dirname(os.path.realpath(__file__)), "..", "Data",
"CO2GAS-dump-1.pdb")


@pytest.fixture()
Expand Down

0 comments on commit 3c2d3ba

Please sign in to comment.