diff --git a/src/pleiades/core/data_manager.py b/src/pleiades/core/data_manager.py index 0ae644d..19926b0 100644 --- a/src/pleiades/core/data_manager.py +++ b/src/pleiades/core/data_manager.py @@ -73,9 +73,7 @@ def get_file_path(self, category: DataCategory, filename: str) -> Path: file_path = Path(filename) if file_path.suffix not in self._VALID_EXTENSIONS[category]: - raise ValueError( - f"Invalid file extension for {category}. " f"Allowed extensions: {self._VALID_EXTENSIONS[category]}" - ) + raise ValueError(f"Invalid file extension for {category}. " f"Allowed extensions: {self._VALID_EXTENSIONS[category]}") try: with resources.path(f"pleiades.data.{self._get_category_path(category)}", filename) as path: diff --git a/src/pleiades/core/models.py b/src/pleiades/core/models.py index 50f1c37..1591ed2 100644 --- a/src/pleiades/core/models.py +++ b/src/pleiades/core/models.py @@ -231,9 +231,7 @@ def areal_density(self) -> float: if self.thickness_unit == "mm": thickness_cm /= 10.0 - return ( - thickness_cm * self.density * CONSTANTS.avogadro_number / self.atomic_mass.value / 1e24 - ) # Convert to atoms/barn + return thickness_cm * self.density * CONSTANTS.avogadro_number / self.atomic_mass.value / 1e24 # Convert to atoms/barn # Unit conversion functions diff --git a/src/pleiades/sammy/backends/docker.py b/src/pleiades/sammy/backends/docker.py index 5f7609b..95f6050 100644 --- a/src/pleiades/sammy/backends/docker.py +++ b/src/pleiades/sammy/backends/docker.py @@ -48,9 +48,7 @@ def prepare_environment(self, files: SammyFiles) -> None: raise EnvironmentPreparationError("Docker not found in PATH") # Verify docker image exists - result = subprocess.run( - ["docker", "image", "inspect", self.config.image_name], capture_output=True, text=True - ) + result = subprocess.run(["docker", "image", "inspect", self.config.image_name], capture_output=True, text=True) if result.returncode != 0: raise EnvironmentPreparationError(f"Docker image not found: {self.config.image_name}") diff --git a/src/pleiades/sammy/backends/local.py b/src/pleiades/sammy/backends/local.py index 0a3ca97..edc9cfc 100644 --- a/src/pleiades/sammy/backends/local.py +++ b/src/pleiades/sammy/backends/local.py @@ -81,10 +81,7 @@ def execute_sammy(self, files: SammyFiles) -> SammyExecutionResult: if not success: logger.error(f"SAMMY execution failed for {execution_id}") - error_message = ( - f"SAMMY execution failed with return code {process.returncode}. " - "Check console output for details." - ) + error_message = f"SAMMY execution failed with return code {process.returncode}. " "Check console output for details." else: logger.info(f"SAMMY execution completed successfully for {execution_id}") error_message = None diff --git a/src/pleiades/sammy/factory.py b/src/pleiades/sammy/factory.py index f4ba5df..23134a8 100644 --- a/src/pleiades/sammy/factory.py +++ b/src/pleiades/sammy/factory.py @@ -105,9 +105,7 @@ def list_available_backends() -> Dict[BackendType, bool]: return available @classmethod - def create_runner( - cls, backend_type: str, working_dir: Path, output_dir: Optional[Path] = None, **kwargs - ) -> SammyRunner: + def create_runner(cls, backend_type: str, working_dir: Path, output_dir: Optional[Path] = None, **kwargs) -> SammyRunner: """ Create a SAMMY runner with the specified backend and configuration. @@ -295,9 +293,7 @@ def process_config(cfg): backend_config = config.get(backend_type, {}) # Create runner using create_runner - return cls.create_runner( - backend_type=backend_type, working_dir=working_dir, output_dir=output_dir, **backend_config - ) + return cls.create_runner(backend_type=backend_type, working_dir=working_dir, output_dir=output_dir, **backend_config) except Exception as e: if not isinstance(e, (ConfigurationError, BackendNotAvailableError)): @@ -347,9 +343,7 @@ def auto_select( preferred = BackendType(preferred_backend.lower()) if available[preferred]: logger.info(f"Using preferred backend: {preferred.value}") - return cls.create_runner( - backend_type=preferred.value, working_dir=working_dir, output_dir=output_dir, **kwargs - ) + return cls.create_runner(backend_type=preferred.value, working_dir=working_dir, output_dir=output_dir, **kwargs) else: logger.warning(f"Preferred backend {preferred.value} not available, " "trying alternatives") except ValueError: @@ -367,9 +361,7 @@ def auto_select( if available[backend]: try: logger.info(f"Attempting to use {backend.value} backend") - return cls.create_runner( - backend_type=backend.value, working_dir=working_dir, output_dir=output_dir, **kwargs - ) + return cls.create_runner(backend_type=backend.value, working_dir=working_dir, output_dir=output_dir, **kwargs) except Exception as e: logger.warning(f"Failed to configure {backend.value} backend: {str(e)}") errors.append(f"{backend.value}: {str(e)}") diff --git a/tests/unit/pleiades/sammy/backends/test_docker.py b/tests/unit/pleiades/sammy/backends/test_docker.py index 76f0591..549f8bf 100644 --- a/tests/unit/pleiades/sammy/backends/test_docker.py +++ b/tests/unit/pleiades/sammy/backends/test_docker.py @@ -124,9 +124,7 @@ def test_execute_sammy_success(self, docker_config, mock_sammy_files, mock_subpr assert "Normal finish to SAMMY" in result.console_output assert result.error_message is None - def test_execute_sammy_failure( - self, docker_config, mock_sammy_files, mock_subprocess_docker_fail, mock_docker_command - ): + def test_execute_sammy_failure(self, docker_config, mock_sammy_files, mock_subprocess_docker_fail, mock_docker_command): """Should handle SAMMY execution failure in container.""" _ = mock_docker_command # implicitly used via fixture _ = mock_subprocess_docker_fail # implicitly used via fixture @@ -139,9 +137,7 @@ def test_execute_sammy_failure( assert not result.success assert "Docker execution failed" in result.error_message - def test_collect_outputs( - self, docker_config, mock_sammy_files, mock_subprocess_docker, mock_docker_command, mock_sammy_results - ): + def test_collect_outputs(self, docker_config, mock_sammy_files, mock_subprocess_docker, mock_docker_command, mock_sammy_results): """Should collect output files from container.""" _ = mock_docker_command # implicitly used via fixture _ = mock_subprocess_docker # implicitly used via fixture diff --git a/tests/unit/pleiades/sammy/test_config.py b/tests/unit/pleiades/sammy/test_config.py index 516aa6f..0478e84 100644 --- a/tests/unit/pleiades/sammy/test_config.py +++ b/tests/unit/pleiades/sammy/test_config.py @@ -24,9 +24,7 @@ def test_create_with_valid_paths(self, temp_working_dir): def test_create_with_defaults(self, temp_working_dir): """Should create config with default values.""" - config = LocalSammyConfig( - working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy") - ) + config = LocalSammyConfig(working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy")) assert config.shell_path == Path("/bin/bash") def test_validate_sammy_in_path(self, temp_working_dir, monkeypatch): @@ -37,18 +35,14 @@ def mock_which(path): monkeypatch.setattr("shutil.which", mock_which) - config = LocalSammyConfig( - working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy") - ) + config = LocalSammyConfig(working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy")) assert config.validate() def test_validate_sammy_not_in_path(self, temp_working_dir, monkeypatch): """Should raise error if SAMMY not in PATH.""" monkeypatch.setattr("shutil.which", lambda _: None) - config = LocalSammyConfig( - working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy") - ) + config = LocalSammyConfig(working_dir=temp_working_dir, output_dir=temp_working_dir / "output", sammy_executable=Path("sammy")) with pytest.raises(ConfigurationError) as exc: config.validate() assert "not found" in str(exc.value) @@ -171,9 +165,7 @@ def test_validate_invalid_url(self, temp_working_dir): def test_empty_url(self, temp_working_dir): """Should raise error for empty URL.""" - config = NovaSammyConfig( - working_dir=temp_working_dir, output_dir=temp_working_dir / "output", url="", api_key="valid_api_key" - ) + config = NovaSammyConfig(working_dir=temp_working_dir, output_dir=temp_working_dir / "output", url="", api_key="valid_api_key") with pytest.raises(ConfigurationError) as exc: config.validate() assert "NOVA service URL cannot be empty" in str(exc.value) diff --git a/tests/unit/pleiades/sammy/test_factory.py b/tests/unit/pleiades/sammy/test_factory.py index 6ca5a0d..2898c25 100644 --- a/tests/unit/pleiades/sammy/test_factory.py +++ b/tests/unit/pleiades/sammy/test_factory.py @@ -73,9 +73,7 @@ def _mock_run(*args, **kwargs): @pytest.fixture def mock_subprocess_run_docker_fail(monkeypatch): """Mock subprocess.run to simulate docker info failure.""" - monkeypatch.setattr( - subprocess, "run", lambda *args, **kwargs: subprocess.CompletedProcess(args=args, returncode=1, **kwargs) - ) + monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: subprocess.CompletedProcess(args=args, returncode=1, **kwargs)) # Mock SammyRunner creation for runner tests @@ -100,9 +98,7 @@ def test_list_available_backends_all_available(self, mock_which, mock_subprocess BackendType.NOVA: True, } - def test_list_available_backends_none_available( - self, monkeypatch, mock_which_unavailable, mock_subprocess_run_docker_fail - ): + def test_list_available_backends_none_available(self, monkeypatch, mock_which_unavailable, mock_subprocess_run_docker_fail): """No backends should be available.""" _ = mock_which_unavailable, mock_subprocess_run_docker_fail # implicitly used by the fixture # remove NOVA env vars to simulate unavailability @@ -218,9 +214,7 @@ def test_auto_select_local(self, mock_which, mock_subprocess_run, mock_sammy_run assert isinstance(runner, LocalSammyRunner) assert "Attempting to use local backend" in caplog.text - def test_auto_select_docker( - self, monkeypatch, mock_which_unavailable, mock_subprocess_run, mock_sammy_runner, tmp_path, caplog - ): + def test_auto_select_docker(self, monkeypatch, mock_which_unavailable, mock_subprocess_run, mock_sammy_runner, tmp_path, caplog): """Should auto-select docker backend if local unavailable.""" _ = mock_which_unavailable, mock_subprocess_run, mock_sammy_runner # implicitly used by the fixture # remove NOVA env vars to simulate unavailability @@ -240,9 +234,7 @@ def test_auto_select_preferred(self, mock_which, mock_subprocess_run, mock_sammy assert isinstance(runner, DockerSammyRunner) assert "Using preferred backend: docker" in caplog.text - def test_auto_select_none_available( - self, monkeypatch, mock_which_unavailable, mock_subprocess_run_docker_fail, tmp_path, caplog - ): + def test_auto_select_none_available(self, monkeypatch, mock_which_unavailable, mock_subprocess_run_docker_fail, tmp_path, caplog): """Should raise error if no backends available.""" _ = mock_which_unavailable, mock_subprocess_run_docker_fail # implicitly used by the fixture # remove NOVA env vars to simulate unavailability