Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Several New Unit Tests #490

Merged
merged 122 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
7888493
resolve CHANGELOG conflict
bgunnar5 Aug 4, 2023
ec13acf
Merge branch 'develop' of https://github.com/LLNL/merlin into develop
bgunnar5 Aug 4, 2023
7c59fc2
merge latest changes from develop
bgunnar5 Nov 20, 2023
29573d4
remove a merge conflict statement that was missed
bgunnar5 Nov 20, 2023
f10c896
add pytest coverage library and add sample_index coverage
bgunnar5 Dec 11, 2023
362478e
run fix style and add module header
bgunnar5 Dec 12, 2023
9339b6b
add tests for encryption modules
bgunnar5 Dec 12, 2023
54a31bc
add unit tests for util_sampling
bgunnar5 Dec 12, 2023
be02611
run fix-style and fix typo
bgunnar5 Dec 12, 2023
a015e3c
pull latest changes from develop
bgunnar5 Dec 12, 2023
63d22f0
create directory for context managers and fix issue with an encryptio…
bgunnar5 Dec 12, 2023
b2a9976
add a context manager for spinning up/down the redis server
bgunnar5 Dec 13, 2023
0ef09bc
Merge remote-tracking branch 'origin/develop' into develop
bgunnar5 Dec 13, 2023
35c614a
fix issue with path in one test
bgunnar5 Dec 13, 2023
638a27e
rework CONFIG functionality for testing
bgunnar5 Dec 13, 2023
9b342ab
refactor config fixture so it doesn't depend on redis server to be st…
bgunnar5 Dec 14, 2023
661ab71
split CONFIG fixtures into rabbit and redis configs, run fix-style
bgunnar5 Dec 14, 2023
db1f20a
add unit tests for broker.py
bgunnar5 Dec 14, 2023
896898e
add unit tests for the Config object
bgunnar5 Dec 14, 2023
2a5148c
update CHANGELOG
bgunnar5 Dec 14, 2023
3d7228e
make CONFIG fixtures more flexible for tests
bgunnar5 Dec 18, 2023
525e403
add tests for results_backend.py
bgunnar5 Dec 18, 2023
47a0b4e
fix lint issues for most recent changes
bgunnar5 Dec 18, 2023
91a3f2f
fix filename issue in setup.cfg and move celeryadapter tests to integ…
bgunnar5 Dec 19, 2023
78b019b
add ssl filepaths to mysql config object
bgunnar5 Dec 19, 2023
275fbd4
add unit tests for configfile.py
bgunnar5 Dec 19, 2023
9669bd0
add tests for the utils.py file in config/
bgunnar5 Dec 19, 2023
2a209e5
create utilities file and constants file
bgunnar5 Dec 19, 2023
ddb0588
move create_dir function to utils.py
bgunnar5 Dec 20, 2023
e5bc0fe
add tests for merlin/examples/generator.py
bgunnar5 Dec 20, 2023
681bd71
run fix-style and update changelog
bgunnar5 Dec 20, 2023
fb6058c
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Jan 24, 2024
2a6ec3a
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Jan 25, 2024
b22e3a1
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Feb 14, 2024
4b8fab5
add a 'pip freeze' call in github workflow to view reqs versions
bgunnar5 Feb 14, 2024
714dafe
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Feb 15, 2024
d00aff0
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Mar 12, 2024
9a9f2c0
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Apr 15, 2024
074e031
Merge remote-tracking branch 'upstream-main/develop' into develop
bgunnar5 Apr 15, 2024
124e40f
pull changes from 1.12.0 and 1.12.1
bgunnar5 Apr 25, 2024
3099d4c
re-delete the old config test files
bgunnar5 Apr 25, 2024
37839f6
fix tests/bugs introduced by merging in develop
bgunnar5 Apr 25, 2024
b8185cc
add a unit test file for the dumper module
bgunnar5 Apr 25, 2024
e48fe32
begin work on server tests and modular fixtures
bgunnar5 May 7, 2024
812459f
pull changes from develop
bgunnar5 May 10, 2024
e1f667d
start work on tests for RedisConfig
bgunnar5 May 23, 2024
9997d8e
add tests for RedisConfig object
bgunnar5 Jun 4, 2024
52213f2
add tests for RedisUsers class
bgunnar5 Jun 4, 2024
a59243f
change server fixtures to use redis config files
bgunnar5 Jun 6, 2024
0ef586e
add tests for AppYaml class
bgunnar5 Jun 6, 2024
bde9079
final cleanup of server_utils
bgunnar5 Jun 6, 2024
da94020
fix lint issues
bgunnar5 Jun 6, 2024
2997de6
parametrize setup examples tests
bgunnar5 Jun 6, 2024
2f24577
sort example output
bgunnar5 Jun 6, 2024
5e0a5f7
ensure directory is changed back on no outdir test
bgunnar5 Jun 6, 2024
d8fa77c
sort the specs in examples output
bgunnar5 Jun 6, 2024
8421d74
fix lint issues
bgunnar5 Jun 6, 2024
0543ae4
start writing tests for server config
bgunnar5 Jun 10, 2024
3b0ccde
add pytest coverage library and add sample_index coverage
bgunnar5 Dec 11, 2023
4ad3729
run fix style and add module header
bgunnar5 Dec 12, 2023
089e2bd
add tests for encryption modules
bgunnar5 Dec 12, 2023
2a3bc69
add unit tests for util_sampling
bgunnar5 Dec 12, 2023
30fd21d
run fix-style and fix typo
bgunnar5 Dec 12, 2023
76b3a55
create directory for context managers and fix issue with an encryptio…
bgunnar5 Dec 12, 2023
fa33cb2
add a context manager for spinning up/down the redis server
bgunnar5 Dec 13, 2023
78a298a
fix issue with path in one test
bgunnar5 Dec 13, 2023
5b6878c
rework CONFIG functionality for testing
bgunnar5 Dec 13, 2023
7aaa832
refactor config fixture so it doesn't depend on redis server to be st…
bgunnar5 Dec 14, 2023
acb6d43
split CONFIG fixtures into rabbit and redis configs, run fix-style
bgunnar5 Dec 14, 2023
c1bfc6a
add unit tests for broker.py
bgunnar5 Dec 14, 2023
3300291
add unit tests for the Config object
bgunnar5 Dec 14, 2023
58a3044
update CHANGELOG
bgunnar5 Dec 14, 2023
9f16701
make CONFIG fixtures more flexible for tests
bgunnar5 Dec 18, 2023
17be237
add tests for results_backend.py
bgunnar5 Dec 18, 2023
d54f750
fix lint issues for most recent changes
bgunnar5 Dec 18, 2023
8e9d1e2
fix filename issue in setup.cfg and move celeryadapter tests to integ…
bgunnar5 Dec 19, 2023
6dae836
add ssl filepaths to mysql config object
bgunnar5 Dec 19, 2023
89caa21
add unit tests for configfile.py
bgunnar5 Dec 19, 2023
ed3a660
add tests for the utils.py file in config/
bgunnar5 Dec 19, 2023
45dfa51
create utilities file and constants file
bgunnar5 Dec 19, 2023
598ffb7
move create_dir function to utils.py
bgunnar5 Dec 20, 2023
a8d0d1d
add tests for merlin/examples/generator.py
bgunnar5 Dec 20, 2023
7728893
run fix-style and update changelog
bgunnar5 Dec 20, 2023
6b97b0a
fix tests/bugs introduced by merging in develop
bgunnar5 Apr 25, 2024
57f0446
add a unit test file for the dumper module
bgunnar5 Apr 25, 2024
963fed1
begin work on server tests and modular fixtures
bgunnar5 May 7, 2024
8649ca1
start work on tests for RedisConfig
bgunnar5 May 23, 2024
91ad49b
add tests for RedisConfig object
bgunnar5 Jun 4, 2024
1df0e44
add tests for RedisUsers class
bgunnar5 Jun 4, 2024
921c38b
change server fixtures to use redis config files
bgunnar5 Jun 6, 2024
2cad8cb
add tests for AppYaml class
bgunnar5 Jun 6, 2024
f28cad3
final cleanup of server_utils
bgunnar5 Jun 6, 2024
716dc32
fix lint issues
bgunnar5 Jun 6, 2024
c1b71f0
parametrize setup examples tests
bgunnar5 Jun 6, 2024
bd598f4
sort example output
bgunnar5 Jun 6, 2024
0487a9e
ensure directory is changed back on no outdir test
bgunnar5 Jun 6, 2024
c11e82f
sort the specs in examples output
bgunnar5 Jun 6, 2024
a39e65c
fix lint issues
bgunnar5 Jun 6, 2024
031fb0e
start writing tests for server config
bgunnar5 Jun 10, 2024
ed3b4ea
bake in LC_ALL env variable setting for server cmds
bgunnar5 Jun 11, 2024
9dc2bd8
add tests for parse_redis_output
bgunnar5 Jun 11, 2024
459aa21
fix issue with scope of fixture after rebase
bgunnar5 Jun 26, 2024
a6b52d0
resolve merge conflicts after rebase
bgunnar5 Jun 26, 2024
5945c36
run fix-style
bgunnar5 Jun 26, 2024
6bf1fe6
split up create_server_config and write tests for it
bgunnar5 Sep 5, 2024
cf307bb
add tests for config_merlin_server function
bgunnar5 Sep 5, 2024
6ba91a6
add tests for pull_server_config
bgunnar5 Sep 9, 2024
28e5040
add tests for pull_server_image
bgunnar5 Sep 10, 2024
24470e5
finish writing tests for server_config.py
bgunnar5 Sep 11, 2024
72398e6
add tests for server_commands.py
bgunnar5 Sep 13, 2024
ff4f649
run fix-style
bgunnar5 Sep 13, 2024
7050822
update README for testing directory
bgunnar5 Sep 13, 2024
0c74021
update the temp_output_directory to include python version
bgunnar5 Sep 13, 2024
42c121b
mock the open.write to try to fix github CI
bgunnar5 Sep 13, 2024
f5e8671
ensure config dir is created
bgunnar5 Sep 13, 2024
3ce140e
update CHANGELOG
bgunnar5 Sep 13, 2024
73e4cf5
add print of exception to OSError catch in pull_server_image
bgunnar5 Sep 13, 2024
5b36b41
change name of config_file in test that's failing
bgunnar5 Sep 13, 2024
9782d58
update CHANGELOG
bgunnar5 Sep 13, 2024
6edcc9a
add Ryan and Joe's suggestions
bgunnar5 Oct 21, 2024
91b6c74
update tests to use newly named functions
bgunnar5 Oct 21, 2024
bc1a1ec
fix linter issue
bgunnar5 Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ flux.out
slurm*.out
docs/build/

# Tox files
# Test files
.tox/*
.coverage

# Jupyter
jupyter/.ipynb_checkpoints
Expand Down
30 changes: 27 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to Merlin will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Several new unit tests for the following subdirectories:
- `merlin/common/`
- `merlin/config/`
- `merlin/examples/`
- `merlin/server/`
- Context managers for the `conftest.py` file to ensure safe spin up and shutdown of fixtures
- `RedisServerManager`: context to help with starting/stopping a redis server for tests
- `CeleryWorkersManager`: context to help with starting/stopping workers for tests
- Ability to copy and print the `Config` object from `merlin/config/__init__.py`
- Equality method to the `ContainerFormatConfig` and `ContainerConfig` objects from `merlin/server/server_util.py`

### Changed
- Split the `start_server` and `config_server` functions of `merlin/server/server_commands.py` into multiple functions to make testing easier
- Split the `create_server_config` function of `merlin/server/server_config.py` into two functions to make testing easier
- Combined `set_snapshot_seconds` and `set_snapshot_changes` methods of `RedisConfig` into one method `set_snapshot`

## [1.12.2b1]
### Added
- Conflict handler option to the `dict_deep_merge` function in `utils.py`
Expand Down Expand Up @@ -95,8 +113,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- this required adding a decent amount of test files to help with the tests; these can be found under the tests/unit/study/status_test_files directory
- Pytest fixtures in the `conftest.py` file of the integration test suite
- NOTE: an export command `export LC_ALL='C'` had to be added to fix a bug in the WEAVE CI. This can be removed when we resolve this issue for the `merlin server` command
- Tests for the `celeryadapter.py` module
- New CeleryTestWorkersManager context to help with starting/stopping workers for tests
- Coverage to the test suite. This includes adding tests for:
- `merlin/common/`
- `merlin/config/`
- `merlin/examples/`
- `celeryadapter.py`
- Context managers for the `conftest.py` file to ensure safe spin up and shutdown of fixtures
- `RedisServerManager`: context to help with starting/stopping a redis server for tests
- `CeleryWorkersManager`: context to help with starting/stopping workers for tests
- Ability to copy and print the `Config` object from `merlin/config/__init__.py`

### Changed
- Reformatted the entire `merlin status` command
Expand Down Expand Up @@ -132,7 +157,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `merlin monitor` command will now keep an allocation up if the queues are empty and workers are still processing tasks
- Add the restart keyword to the specification docs
- Cyclical imports and config imports that could easily cause ci issues

## [1.11.1]
### Fixed
- Typo in `batch.py` that caused lsf launches to fail (`ALL_SGPUS` changed to `ALL_GPUS`)
Expand Down
2 changes: 1 addition & 1 deletion merlin/common/sample_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def __setitem__(self, full_address, sub_tree):

# Replace if we already have something at this address.
if delete_me is not None:
self.children.__delitem__(full_address)
SampleIndex.check_valid_addresses_for_insertion(full_address, sub_tree)
self.children.__delitem__(full_address)
self.children[full_address] = sub_tree
return
raise KeyError
Expand Down
9 changes: 4 additions & 5 deletions merlin/common/security/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def _get_key_path():
except AttributeError:
key_filepath = "~/.merlin/encrypt_data_key"

try:
key_filepath = os.path.abspath(os.path.expanduser(key_filepath))
except KeyError as e:
raise ValueError("Error! No password provided for RabbitMQ") from e
return key_filepath
if key_filepath is None:
raise ValueError("Error! No password provided for RabbitMQ")

return os.path.abspath(os.path.expanduser(key_filepath))
koning marked this conversation as resolved.
Show resolved Hide resolved


def _gen_key(key_path):
Expand Down
1 change: 1 addition & 0 deletions merlin/common/util_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import numpy as np


# TODO should we move this to merlin-spellbook?
def scale_samples(samples_norm, limits, limits_norm=(0, 1), do_log=False):
"""Scale samples to new limits, either log10 or linearly.

Expand Down
31 changes: 30 additions & 1 deletion merlin/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"""
Used to store the application configuration.
"""

from copy import copy
from types import SimpleNamespace
from typing import Dict, List, Optional

Expand All @@ -56,6 +56,35 @@ def __init__(self, app_dict):
self.results_backend: Optional[SimpleNamespace]
self.load_app_into_namespaces(app_dict)

def __copy__(self):
"""
A magic method to allow this class to be copied with copy(instance_of_Config).
"""
cls = self.__class__
result = cls.__new__(cls)
copied_attrs = {
"celery": copy(self.__dict__["celery"]),
"broker": copy(self.__dict__["broker"]),
"results_backend": copy(self.__dict__["results_backend"]),
}
result.__dict__.update(copied_attrs)
return result

def __str__(self):
"""
A magic method so we can print the CONFIG class.
"""
formatted_str = "config:"
attrs = {"celery": self.celery, "broker": self.broker, "results_backend": self.results_backend}
for name, attr in attrs.items():
if attr is not None:
items = (f" {k}: {v!r}" for k, v in attr.__dict__.items())
joined_items = "\n".join(items)
formatted_str += f"\n {name}:\n{joined_items}"
else:
formatted_str += f"\n {name}:\n None"
return formatted_str

def load_app_into_namespaces(self, app_dict: Dict) -> None:
"""
Makes the application dictionary into a namespace, sets the attributes of the Config from the namespace values.
Expand Down
14 changes: 4 additions & 10 deletions merlin/config/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def get_rabbit_connection(include_password, conn="amqps"):
password_filepath = CONFIG.broker.password
LOG.debug(f"Broker: password filepath = {password_filepath}")
password_filepath = os.path.abspath(expanduser(password_filepath))
except KeyError as e: # pylint: disable=C0103
raise ValueError("Broker: No password provided for RabbitMQ") from e
except (AttributeError, KeyError) as exc:
raise ValueError("Broker: No password provided for RabbitMQ") from exc

try:
password = read_file(password_filepath)
except IOError as e: # pylint: disable=C0103
raise ValueError(f"Broker: RabbitMQ password file {password_filepath} does not exist") from e
except IOError as exc:
raise ValueError(f"Broker: RabbitMQ password file {password_filepath} does not exist") from exc

try:
port = CONFIG.broker.port
Expand Down Expand Up @@ -205,12 +205,6 @@ def get_connection_string(include_password=True):
except AttributeError:
broker = ""

try:
config_path = CONFIG.celery.certs
config_path = os.path.abspath(os.path.expanduser(config_path))
except AttributeError:
config_path = None

if broker not in BROKERS:
raise ValueError(f"Error: {broker} is not a supported broker.")
return _sort_valid_broker(broker, include_password)
Expand Down
6 changes: 6 additions & 0 deletions merlin/config/results_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ def get_mysql(certs_path=None, mysql_certs=None, include_password=True):
mysql_config["password"] = "******"
mysql_config["server"] = server

# Ensure the ssl_key, ssl_ca, and ssl_cert keys are all set
if mysql_certs == MYSQL_CONFIG_FILENAMES:
for key, cert_file in mysql_certs.items():
if key not in mysql_config:
mysql_config[key] = os.path.join(certs_path, cert_file)

return MYSQL_CONNECTION_STRING.format(**mysql_config)


Expand Down
10 changes: 8 additions & 2 deletions merlin/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ def get_priority(priority: Priority) -> int:
:param priority: The priority value that we want
:returns: The priority value as an integer
"""
if priority not in Priority:
raise ValueError(f"Invalid priority: {priority}")
priority_err_msg = f"Invalid priority: {priority}"
try:
# In python 3.12+ if something is not in the enum it will just return False
if priority not in Priority:
raise ValueError(priority_err_msg)
# In python 3.11 and below, a TypeError is raised when looking for something in an enum that is not there
except TypeError:
raise ValueError(priority_err_msg)

priority_map = determine_priority_map(CONFIG.broker.name.lower())
return priority_map.get(priority, priority_map[Priority.MID]) # Default to MID priority for unknown priorities
12 changes: 10 additions & 2 deletions merlin/examples/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@

EXAMPLES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "workflows")

# TODO modify the example command to eliminate redundancy
# - e.g. running `merlin example flux_local` will produce the same output
# as running `merlin example flux_par` or `merlin example flux_par_restart`.
# This should just be `merlin example flux`.
# - restart and restart delay should be one example
# - feature demo and remote feature demo should be one example
# - all openfoam examples should just be under one openfoam label


def gather_example_dirs():
"""Get all the example directories"""
result = {}
for directory in os.listdir(EXAMPLES_DIR):
for directory in sorted(os.listdir(EXAMPLES_DIR)):
result[directory] = directory
return result

Expand Down Expand Up @@ -82,7 +90,7 @@ def list_examples():
for example_dir in gather_example_dirs():
directory = os.path.join(os.path.join(EXAMPLES_DIR, example_dir), "")
specs = glob.glob(directory + "*.yaml")
for spec in specs:
for spec in sorted(specs):
if "template" in spec:
continue
with open(spec) as f: # pylint: disable=C0103
Expand Down
8 changes: 8 additions & 0 deletions merlin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ def process_server(args: Namespace):
Route to the correct function based on the command
given via the CLI
"""
try:
lc_all_val = os.environ["LC_ALL"]
if lc_all_val != "C":
raise ValueError(f"The 'LC_ALL' environment variable is currently set to {lc_all_val} but it must be set to 'C'.")
except KeyError:
LOG.debug("The 'LC_ALL' environment variable was not set. Setting this to 'C'.")
os.environ["LC_ALL"] = "C" # Necessary for Redis to configure LOCALE

if args.commands == "init":
init_server()
elif args.commands == "start":
Expand Down
Loading
Loading