Skip to content

Commit ac7f6f2

Browse files
committed
address PR feedback
1 parent 7dfd7bf commit ac7f6f2

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

.generator/cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@
2020

2121
logger = logging.getLogger()
2222

23-
LIBRARIAN = "/librarian"
23+
LIBRARIAN_DIR = "/librarian"
24+
GENERATOR_DIR = "/.generator"
25+
GENERATE_REQUEST_FILE = "generate-request.json"
26+
27+
28+
def _get_base_dir():
29+
"""Returns the correct base directory based on the environment."""
30+
environment = os.getenv("PY_GENERATOR_ENV", "production").lower()
31+
if environment == "test":
32+
return GENERATOR_DIR
33+
return LIBRARIAN_DIR
2434

2535

2636
# Helper function that reads a json file path and returns the loaded json content.
@@ -38,9 +48,8 @@ def handle_generate(dry_run=False):
3848

3949
# Read a generate-request.json file
4050
if not dry_run:
41-
request_path = f"{LIBRARIAN}/generate-request.json"
4251
try:
43-
request_data = _read_json_file(request_path)
52+
request_data = _read_json_file(f"{_get_base_dir()}/{GENERATE_REQUEST_FILE}")
4453
except Exception as e:
4554
logger.error(e)
4655
sys.exit(1)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
}
88
]
99
}
10-

.generator/test_cli.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,25 @@
1515
import pytest
1616
import json
1717

18-
from cli import _read_json_file, handle_generate, handle_build, handle_configure
18+
from unittest.mock import mock_open
19+
20+
from cli import (
21+
_read_json_file,
22+
handle_generate,
23+
handle_build,
24+
handle_configure,
25+
GENERATOR_DIR,
26+
GENERATE_REQUEST_FILE,
27+
)
28+
29+
30+
# # The fixture is defined directly in the test file
31+
@pytest.fixture(autouse=True)
32+
def set_test_environment(monkeypatch):
33+
"""
34+
Sets the environment variable only for tests in this file.
35+
"""
36+
monkeypatch.setenv("PY_GENERATOR_ENV", "test")
1937

2038

2139
def test_handle_configure_dry_run():

0 commit comments

Comments
 (0)