Skip to content

Commit

Permalink
Improve test units clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Nov 2, 2023
1 parent 77b45ef commit 9618f47
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion disdrodb/tests/test_l0/test_check_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from disdrodb.l0.standards import available_sensor_names

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")


@pytest.mark.parametrize("sensor_name", available_sensor_names())
Expand Down
12 changes: 6 additions & 6 deletions disdrodb/tests/test_l0/test_check_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from disdrodb.l0.standards import available_sensor_names
from disdrodb.utils.yaml import read_yaml

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")


def test_check_metadata_geolocation():
Expand Down Expand Up @@ -355,27 +355,27 @@ def test_read_yaml():

# Test reading a valid YAML file
valid_yaml_attrs = {"key1": "value1", "key2": "value2"}
yaml_temp_path = os.path.join(PATH_TEST_FOLDERS_FILES, "test_check_metadata", "valid.yaml")
yaml_temp_path = os.path.join(TEST_DATA_DIR, "test_check_metadata", "valid.yaml")
assert read_yaml(yaml_temp_path) == valid_yaml_attrs

# Test reading a non-existent YAML file
yaml_temp_path_non_existent = os.path.join(PATH_TEST_FOLDERS_FILES, "test_check_metadata", "non_existent.yaml")
yaml_temp_path_non_existent = os.path.join(TEST_DATA_DIR, "test_check_metadata", "non_existent.yaml")
with pytest.raises(FileNotFoundError):
read_yaml(yaml_temp_path_non_existent)

# Test reading a YAML file with invalid syntax
yaml_temp_path_nvalid = os.path.join(PATH_TEST_FOLDERS_FILES, "test_check_metadata", "invalid.yaml")
yaml_temp_path_nvalid = os.path.join(TEST_DATA_DIR, "test_check_metadata", "invalid.yaml")
with pytest.raises(yaml.YAMLError):
read_yaml(yaml_temp_path_nvalid)


def test_identify_missing_metadata_coords():
yaml_temp_path_valid = [os.path.join(PATH_TEST_FOLDERS_FILES, "test_check_metadata", "valid_coords.yaml")]
yaml_temp_path_valid = [os.path.join(TEST_DATA_DIR, "test_check_metadata", "valid_coords.yaml")]

function_return = identify_missing_metadata_coords(yaml_temp_path_valid)
assert function_return is None

yaml_temp_path_invalid = [os.path.join(PATH_TEST_FOLDERS_FILES, "test_check_metadata", "invalid_coords.yaml")]
yaml_temp_path_invalid = [os.path.join(TEST_DATA_DIR, "test_check_metadata", "invalid_coords.yaml")]

with pytest.raises(TypeError):
identify_missing_metadata_coords(yaml_temp_path_invalid)
32 changes: 16 additions & 16 deletions disdrodb/tests/test_l0/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from disdrodb import __root_path__
from disdrodb.l0 import io

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")


def create_fake_metadata_file(
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_check_raw_dir_input(tmp_path):


def test_check_directory_exist():
assert io._check_directory_exist(PATH_TEST_FOLDERS_FILES) is None
assert io._check_directory_exist(TEST_DATA_DIR) is None


def _infer_disdrodb_tree_path():
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_get_l0a_fpath():

# Set paths
path_campaign_name = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_structure",
"DISDRODB",
"Processed",
Expand Down Expand Up @@ -347,7 +347,7 @@ def test_get_l0b_fpath():

# Set paths
path_campaign_name = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_structure",
"DISDRODB",
"Processed",
Expand Down Expand Up @@ -385,7 +385,7 @@ def test_check_glob_pattern():


def test_get_raw_file_list():
path_test_directory = os.path.join(PATH_TEST_FOLDERS_FILES, "test_l0a_processing", "files")
path_test_directory = os.path.join(TEST_DATA_DIR, "test_l0a_processing", "files")

station_name = "STATION_NAME"

Expand Down Expand Up @@ -418,7 +418,7 @@ def test_get_raw_file_list():
####--------------------------------------------------------------------------.

folder_name = "folder_creation_deletion_test"
path_file_temp = os.path.join(PATH_TEST_FOLDERS_FILES, "test_folders_files_creation", folder_name)
path_file_temp = os.path.join(TEST_DATA_DIR, "test_folders_files_creation", folder_name)


def test_create_directory(tmp_path):
Expand Down Expand Up @@ -467,7 +467,7 @@ def test_check_raw_dir():

# Set paths
raw_dir = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_structure",
"DISDRODB",
"Raw",
Expand All @@ -482,15 +482,15 @@ def test_check_campaign_name():
campaign_name = "CAMPAIGN_NAME"
data_source = "DATA_SOURCE"
path_raw = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_structure",
"DISDRODB",
"Raw",
data_source,
campaign_name,
)
path_process = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_creation",
"DISDRODB",
"Processed",
Expand All @@ -506,15 +506,15 @@ def test_copy_station_metadata():
data_source = "DATA_SOURCE"
station_name = "STATION_NAME"
raw_dir = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_structure",
"DISDRODB",
"Raw",
data_source,
campaign_name,
)
processed_dir = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_creation",
"DISDRODB",
"Processed",
Expand Down Expand Up @@ -552,15 +552,15 @@ def test_copy_station_metadata():
# verbose=False

# raw_dir = os.path.join(
# PATH_TEST_FOLDERS_FILES,
# TEST_DATA_DIR,
# "test_folders_files_structure",
# "DISDRODB",
# "Raw",
# data_source,
# campaign_name,
# )
# processed_dir = os.path.join(
# PATH_TEST_FOLDERS_FILES,
# TEST_DATA_DIR,
# "test_folders_files_creation",
# "DISDRODB",
# "Processed",
Expand Down Expand Up @@ -601,7 +601,7 @@ def test_copy_station_metadata():
# verbose=False

# processed_dir = os.path.join(
# PATH_TEST_FOLDERS_FILES,
# TEST_DATA_DIR,
# "test_folders_files_creation",
# "DISDRODB",
# "Processed",
Expand Down Expand Up @@ -638,7 +638,7 @@ def test__read_l0a():

# save dataframe to parquet file
path_parquet_file = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_creation",
"fake_data_sample.parquet",
)
Expand All @@ -661,7 +661,7 @@ def test_read_l0a_dataframe():

# save dataframe to parquet file
path_parquet_file = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_creation",
f"fake_data_sample_{i}.parquet",
)
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/tests/test_l0/test_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from disdrodb import __root_path__
from disdrodb.l0 import issue

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")

####--------------------------------------------------------------------------.
#### Checks
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/tests/test_l0/test_l0a_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
strip_string_spaces,
)

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")

# NOTE:
# The following fixtures are not defined in this file, but are used and injected by Pytest:
Expand Down Expand Up @@ -535,7 +535,7 @@ def test_write_l0a():

# Write parquet file
path_parquet_file = os.path.join(
PATH_TEST_FOLDERS_FILES,
TEST_DATA_DIR,
"test_folders_files_creation",
"fake_data_sample.parquet",
)
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/tests/test_l0/test_l0b_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
set_variable_attributes,
)

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")


# NOTE:
Expand Down
12 changes: 6 additions & 6 deletions disdrodb/tests/test_l0/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
write_default_metadata,
)

PATH_TEST_FOLDERS_FILES = os.path.join(__root_path__, "disdrodb", "tests", "data")
TEST_DATA_DIR = os.path.join(__root_path__, "disdrodb", "tests", "data")


def create_fake_station_file(
base_dir, data_source="data_source", campaign_name="campaign_name", station_name="station_name"
):
subfolder_path = base_dir / "DISDRODB" / "Raw" / data_source / campaign_name / "data" / station_name
subfolder_path = base_dir / "Raw" / data_source / campaign_name / "data" / station_name
if not os.path.exists(subfolder_path):
subfolder_path.mkdir(parents=True)

subfolder_path = base_dir / "DISDRODB" / "Raw" / data_source / campaign_name / "metadata"
subfolder_path = base_dir / "Raw" / data_source / campaign_name / "metadata"
if not os.path.exists(subfolder_path):
subfolder_path.mkdir(parents=True)

Expand All @@ -51,13 +51,13 @@ def create_fake_station_file(


def test_create_campaign_default_metadata(tmp_path):
base_dir = os.path.join(tmp_path, "DISDRODB")
base_dir = tmp_path / "DISDRODB"
campaign_name = "test_campaign"
data_source = "test_data_source"
station_name = "test_station"

create_fake_station_file(
base_dir=tmp_path, data_source=data_source, campaign_name=campaign_name, station_name=station_name
base_dir=base_dir, data_source=data_source, campaign_name=campaign_name, station_name=station_name
)

create_campaign_default_metadata(base_dir=base_dir, data_source=data_source, campaign_name=campaign_name)
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_write_default_metadata(tmp_path):


def test_read_metadata():
raw_dir = os.path.join(PATH_TEST_FOLDERS_FILES, "test_folders_files_creation")
raw_dir = os.path.join(TEST_DATA_DIR, "test_folders_files_creation")
station_name = "123"

metadata_folder_path = os.path.join(raw_dir, "metadata")
Expand Down

0 comments on commit 9618f47

Please sign in to comment.