Skip to content

Commit

Permalink
Run linter and extend to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschz committed Nov 16, 2024
1 parent 5d57f10 commit 60c8599
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ jobs:
shell: bash
run: |
pylint reccmp
black --check reccmp
pylint tests
black --check .
26 changes: 18 additions & 8 deletions reccmp/project/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@

import ruamel.yaml

from .config import BuildFile, BuildFileTarget, GhidraConfig, ProjectFile, ProjectFileTarget, RecCmpBuiltTarget, RecCmpTarget, UserFile, UserFileTarget
from .config import (
BuildFile,
BuildFileTarget,
GhidraConfig,
ProjectFile,
ProjectFileTarget,
RecCmpBuiltTarget,
RecCmpTarget,
UserFile,
UserFileTarget,
)

from .common import RECCMP_USER_CONFIG, RECCMP_BUILD_CONFIG, RECCMP_PROJECT_CONFIG
from .error import (
Expand All @@ -21,6 +31,7 @@

logger = logging.getLogger(__file__)


def verify_target_names(
project_targets: dict[str, ProjectFileTarget],
user_targets: dict[str, UserFileTarget],
Expand Down Expand Up @@ -123,7 +134,9 @@ def from_directory(cls, directory: Path) -> "RecCmpBuiltProject":
directory=directory, filename=RECCMP_BUILD_CONFIG
)
if not build_directory:
raise RecCmpProjectNotFoundException(f"Cannot find {RECCMP_BUILD_CONFIG}")
raise RecCmpProjectNotFoundException(
f"Cannot find {RECCMP_BUILD_CONFIG} under {build_directory}"
)
build_config = build_directory / RECCMP_BUILD_CONFIG
logger.debug("Using build config: %s", build_config)
yaml_loader = ruamel.yaml.YAML()
Expand Down Expand Up @@ -183,11 +196,6 @@ def from_directory(cls, directory: Path) -> "RecCmpBuiltProject":

source_root = project_directory / project_target_data.source_root
filename = project_target_data.filename
if not filename:
raise InvalidRecCmpProjectException(
f"{project_config_path}: targets.{target_id}.filename is missing"
)

original_path = user_target_data.path

recompiled_path = build_directory.joinpath(build_target_data.path)
Expand Down Expand Up @@ -391,7 +399,9 @@ def detect_project(
logger.info("Found %s -> %s", target_id, p)
break
else:
logger.warning("Could not find %s under %s", filename, search_path_folder)
logger.warning(
"Could not find %s under %s", filename, search_path_folder
)

logger.info("Updating %s", user_config_path)
with user_config_path.open("w") as f:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import hashlib
import pytest

from reccmp.isledecomp.bin import (
Bin as IsleBin,
)
import pytest


def pytest_addoption(parser):
Expand Down
1 change: 0 additions & 1 deletion tests/test_islebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
2. Provides an interface to read from the DLL or EXE using a virtual address.
These are some basic smoke tests."""

import hashlib
from typing import Tuple
import pytest
from reccmp.isledecomp.bin import (
Expand Down
13 changes: 8 additions & 5 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pathlib import Path
import textwrap

from .conftest import LEGO1_SHA256
from reccmp.project.create import create_project, RecCmpProject
from reccmp.project.detect import detect_project, DetectWhat, RecCmpBuiltProject
from .conftest import LEGO1_SHA256


def test_project_loading(tmp_path_factory, binfile):
Expand Down Expand Up @@ -45,6 +45,7 @@ def test_project_loading(tmp_path_factory, binfile):
)
)
project = RecCmpProject.from_directory(project_root)
assert project is not None
assert len(project.targets) == 1
assert "LEGO1" in project.targets
assert project.targets["LEGO1"].target_id == "LEGO1"
Expand Down Expand Up @@ -75,20 +76,22 @@ def test_project_original_detection(tmp_path_factory, binfile):
)
)
bin_path = Path(binfile.filename)
project = detect_project(
detect_project(
project_directory=project_root,
search_path=[bin_path.parent],
detect_what=DetectWhat.ORIGINAL)
detect_what=DetectWhat.ORIGINAL,
)
assert (project_root / "reccmp-user.yml").is_file()



def test_project_creation(tmp_path_factory, binfile):
project_root = tmp_path_factory.mktemp("project")
bin_path = Path(binfile.filename)
project_config_path = project_root / "reccmp-project.yml"
user_config_path = project_root / "reccmp-user.yml"
project = create_project(project_directory=project_root, original_paths=[bin_path], scm=True, cmake=True)
project = create_project(
project_directory=project_root, original_paths=[bin_path], scm=True, cmake=True
)
assert project_config_path.is_file()
assert user_config_path.is_file()
target_name = bin_path.stem.upper()
Expand Down

0 comments on commit 60c8599

Please sign in to comment.