Skip to content

Commit

Permalink
Merge pull request #226 from hickeyma/tests/add-gen-data-ut
Browse files Browse the repository at this point in the history
tests: Add test to validate that generate_data() is generating the files expected
  • Loading branch information
markmc authored Aug 21, 2024
2 parents 889c9da + 55247c7 commit eb22d4a
Show file tree
Hide file tree
Showing 5 changed files with 671 additions and 35 deletions.
16 changes: 9 additions & 7 deletions tests/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

# Standard
from pathlib import Path
from typing import List
from typing import Any, Dict, List
import shutil

# Third Party
import git
import yaml


class MockTaxonomy:
Expand All @@ -25,28 +26,29 @@ def untracked_files(self) -> List[str]:
"""List untracked files in the repository"""
return self._repo.untracked_files

def create_untracked(self, rel_path: str, contents: str) -> Path:
def create_untracked(self, rel_path: str, contents: Dict[str, Any]) -> Path:
"""Create a new untracked file in the repository.
Args:
rel_path (str): Relative path (from repository root) to the file.
contents (str): String to be written to the file.
contents (Dict[str, Any]): Object to be written to the file.
Returns:
file_path: The path to the created file.
"""
taxonomy_path = Path(rel_path)
assert not taxonomy_path.is_absolute()
file_path = self.root.joinpath(taxonomy_path)
file_path.parent.mkdir(exist_ok=True, parents=True)
file_path.write_text(contents, encoding="utf-8")
with file_path.open(mode="w", encoding="utf-8") as fp:
yaml.dump(contents, fp)
return file_path

def add_tracked(self, rel_path, contents: str) -> Path:
"""Add a new tracked file to the repository (and commits it).
def add_tracked(self, rel_path, contents: Dict[str, Any]) -> Path:
"""Add a new tracked file to the repository (and commit it).
Args:
rel_path (str): Relative path (from repository root) to the file.
contents (str): String to be written to the file.
contents (Dict[str, Any]): Object to be written to the file.
Returns:
file_path: The path to the added file.
"""
Expand Down
Loading

0 comments on commit eb22d4a

Please sign in to comment.