From 959df600f97ff3616d5275459775579f3410b07d Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 25 Sep 2024 16:08:28 -0500 Subject: [PATCH] styling --- smartsim/_core/generation/generator.py | 8 ++++---- smartsim/experiment.py | 3 ++- tests/test_generator.py | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/smartsim/_core/generation/generator.py b/smartsim/_core/generation/generator.py index 0d7c91899..8107a83d1 100644 --- a/smartsim/_core/generation/generator.py +++ b/smartsim/_core/generation/generator.py @@ -28,9 +28,9 @@ import os import pathlib import pickle -import time import subprocess import sys +import time import typing as t from collections import namedtuple from datetime import datetime @@ -175,9 +175,9 @@ def generate_job(self, job: Job, job_index: int) -> Job_Path: err_file = self._build_err_file_path(log_path, job.entity.name) cmd_list = self._build_commands(job, job_path, log_path) - + self._execute_commands(cmd_list) - + with open( self._build_log_file_path(log_path), mode="w", encoding="utf-8" ) as log_file: @@ -234,7 +234,7 @@ def _execute_commands(cls, cmd_list: CommandList) -> None: """ for cmd in cmd_list: subprocess.run(cmd.command) - + @staticmethod def _mkdir_file(file_path: pathlib.Path) -> Command: cmd = Command(["mkdir", "-p", str(file_path)]) diff --git a/smartsim/experiment.py b/smartsim/experiment.py index 8e85fec3f..77ad021de 100644 --- a/smartsim/experiment.py +++ b/smartsim/experiment.py @@ -38,12 +38,13 @@ from smartsim._core import dispatch from smartsim._core.config import CONFIG from smartsim._core.control import interval as _interval +from smartsim._core.control import preview_renderer from smartsim._core.control.launch_history import LaunchHistory as _LaunchHistory from smartsim._core.utils import helpers as _helpers from smartsim.error import errors from smartsim.status import TERMINAL_STATUSES, InvalidJobStatus, JobStatus -from ._core import Generator, Manifest, previewrenderer +from ._core import Generator, Manifest from ._core.generation.generator import Job_Path from .entity import TelemetryConfiguration from .error import SmartSimError diff --git a/tests/test_generator.py b/tests/test_generator.py index 8a673b424..4c25ccd05 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -38,7 +38,7 @@ from smartsim._core.commands import Command, CommandList from smartsim._core.generation.generator import Generator from smartsim.builders import Ensemble -from smartsim.entity import Application +from smartsim.entity import entity from smartsim.entity.files import EntityFiles from smartsim.launchable import Job from smartsim.settings import LaunchSettings @@ -47,7 +47,7 @@ pytestmark = pytest.mark.group_a -_ID_GENERATOR = (str(i) for i in itertools.count()) +ids = set() _ID_GENERATOR = (str(i) for i in itertools.count()) @@ -92,7 +92,7 @@ def __init__(self): self.files = None self.file_parameters = None - def as_program_arguments(self): + def as_executable_sequence(self): return ("echo", "Hello", "World!") def files(): @@ -226,7 +226,11 @@ def test_build_commands( "smartsim._core.generation.Generator._write_tagged_files" ) as mock_write_tagged_files, ): - generator_instance._build_commands(mock_job, pathlib.Path(test_dir) / generator_instance.run_directory, pathlib.Path(test_dir) / generator_instance.log_directory) + generator_instance._build_commands( + mock_job, + pathlib.Path(test_dir) / generator_instance.run_directory, + pathlib.Path(test_dir) / generator_instance.log_directory, + ) mock_copy_files.assert_called_once() mock_symlink_files.assert_called_once() mock_write_tagged_files.assert_called_once() @@ -243,6 +247,7 @@ def test_execute_commands(generator_instance: Generator): generator_instance._execute_commands(cmd_list) run_process.assert_called_once() + def test_mkdir_file(generator_instance: Generator, test_dir: str): """Test Generator._mkdir_file returns correct type and value""" cmd = generator_instance._mkdir_file(pathlib.Path(test_dir)) @@ -385,7 +390,9 @@ def test_generate_ensemble_copy( jobs_dir = pathlib.Path(test_dir) / run_dir[0] / "jobs" job_dir = jobs_dir.iterdir() for ensemble_dir in job_dir: - copy_folder_path = jobs_dir / ensemble_dir / Generator.run_directory / "to_copy_dir" + copy_folder_path = ( + jobs_dir / ensemble_dir / Generator.run_directory / "to_copy_dir" + ) assert copy_folder_path.is_dir() ids.clear() @@ -415,6 +422,7 @@ def test_generate_ensemble_symlink( assert sym_file_path.is_dir() assert sym_file_path.is_symlink() assert os.fspath(sym_file_path.resolve()) == osp.realpath(get_gen_symlink_dir) + ids.clear() def test_generate_ensemble_configure(