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

FIX: CSIPSTR3 false positive #66

Draft
wants to merge 2 commits into
base: integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions eark_validator/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, package_path: Path, version: SpecificationVersion = Specifica
self._report = _report_from_bad_path(package_path)
return

self._report = self.validate(self._version, self._to_proc)
self._report = self.validate(self._version, self._to_proc, PackageHandler.is_archive(package_path))

@property
def original_path(self) -> Path:
Expand All @@ -86,10 +86,10 @@ def version(self) -> SpecificationVersion:
return self._version

@classmethod
def validate(cls, version: SpecificationVersion, to_validate: Path) -> ValidationReport:
def validate(cls, version: SpecificationVersion, to_validate: Path, is_archive: bool=False) -> ValidationReport:
"""Returns the validation report that results from validating the path
to_validate as a folder. The method does not validate archive files."""
is_struct_valid, struct_results = structure.validate(to_validate)
is_struct_valid, struct_results = structure.validate(to_validate, is_archive)
if not is_struct_valid:
return ValidationReport.model_validate({'structure': struct_results})
validator = MetsValidator(str(to_validate))
Expand Down
12 changes: 6 additions & 6 deletions eark_validator/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
class StructureParser():
_package_handler = PackageHandler()
"""Encapsulates the set of tests carried out on folder structure."""
def __init__(self, package_path: Path):
self._is_archive = PackageHandler.is_archive(package_path)
def __init__(self, package_path: Path, is_archive: bool = False):
self._is_archive = is_archive
self.md_folders: set[str]= set()
self.folders: set[str] = set()
self.files : set[str] = set()
Expand Down Expand Up @@ -117,9 +117,9 @@ def is_archive(self) -> bool:
return self._is_archive

class StructureChecker():
def __init__(self, dir_to_scan: Path):
def __init__(self, dir_to_scan: Path, is_archive: bool=False):
self.name: str = os.path.basename(dir_to_scan)
self.parser: StructureParser = StructureParser(dir_to_scan)
self.parser: StructureParser = StructureParser(dir_to_scan, is_archive)
self.representations: Dict[Representation, StructureParser] = {}
if self.parser.is_parsable:
_reps = os.path.join(self.parser.resolved_path, DIR_NAMES['REPS'])
Expand Down Expand Up @@ -245,9 +245,9 @@ def _get_str1_result_list(name: str) -> List[Result]:
def _root_loc(name: str) -> str:
return f'{ROOT} {name}'

def validate(to_validate) -> Tuple[bool, StructResults]:
def validate(to_validate, is_archive: bool=False) -> Tuple[bool, StructResults]:
try:
struct_tests = StructureChecker(to_validate).get_test_results()
struct_tests = StructureChecker(to_validate, is_archive).get_test_results()
return struct_tests.status == StructureStatus.WELLFORMED, struct_tests
except PackageError:
return False, get_bad_path_results(to_validate)
Loading