Skip to content

Commit

Permalink
Little fix to handle relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-haffi committed Nov 7, 2023
1 parent 5b9820a commit 7bf1789
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/bo4e_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@
from bo4e_generator.schema import get_namespace


def resolve_paths(input_directory: Path, output_directory: Path) -> tuple[Path, Path]:
"""
Resolve the input and output paths. The data-model-parser have problems with handling relative paths.
"""
if not input_directory.is_absolute():
input_directory = input_directory.resolve()
if not output_directory.is_absolute():
output_directory = output_directory.resolve()
return input_directory, output_directory


def generate_bo4e_schemas(input_directory: Path, output_directory: Path):
"""
Generate all BO4E schemas from the given input directory and save them in the given output directory.
"""
input_directory, output_directory = resolve_paths(input_directory, output_directory)
namespace = get_namespace(input_directory, output_directory)
for schema_metadata in namespace.values():
result = generate_bo4e_schema(schema_metadata, namespace)
Expand Down
14 changes: 10 additions & 4 deletions unittests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from pathlib import Path
from traceback import format_tb

from click.testing import CliRunner
from pydantic import BaseModel
Expand All @@ -7,16 +9,20 @@
from bo4e_generator.parser import generate_bo4e_schema
from bo4e_generator.schema import get_namespace

OUTPUT_DIR = Path(__file__).parent / "output/bo4e"
INPUT_DIR = Path(__file__).parent / "test_data/bo4e_schemas"
BASE_DIR = Path(__file__).parents[1]
OUTPUT_DIR = Path("unittests/output/bo4e")
INPUT_DIR = Path("unittests/test_data/bo4e_schemas")


class TestMain:
def test_main(self):
os.chdir(BASE_DIR)
runner = CliRunner()
result = runner.invoke(main, ["--input-dir", str(INPUT_DIR), "--output-dir", str(OUTPUT_DIR)])
# generate_bo4e_schemas(input_directory=INPUT_DIR, output_directory=OUTPUT_DIR)
assert result.exit_code == 0, f"Error: {result.output}"

assert (
result.exit_code == 0
), f"{result.exc_info[0].__name__}: {result.exc_info[1]}\n{''.join(format_tb(result.exc_info[2]))}"
assert (OUTPUT_DIR / "bo" / "angebot.py").exists()
assert (OUTPUT_DIR / "bo" / "preisblatt_netznutzung.py").exists()
assert (OUTPUT_DIR / "com" / "com.py").exists()
Expand Down

0 comments on commit 7bf1789

Please sign in to comment.