Skip to content

Commit 11af94d

Browse files
authored
Refactor: time convert uses env vars for IO targets (#32)
2 parents ff043ee + 9fce004 commit 11af94d

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

bin/hours-convert.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

compiler_admin/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ def setup_time_command(cmd_parsers: _SubParsersAction):
6969

7070
time_convert = add_sub_cmd(time_subcmds, "convert", help="Convert a time report from one format into another.")
7171
time_convert.add_argument(
72-
"--input", default=sys.stdin, help="The path to the source data for conversion. Defaults to stdin."
72+
"--input",
73+
default=os.environ.get("TOGGL_DATA", sys.stdin),
74+
help="The path to the source data for conversion. Defaults to $TOGGL_DATA or stdin.",
7375
)
7476
time_convert.add_argument(
75-
"--output", default=sys.stdout, help="The path to the file where converted data should be written. Defaults to stdout."
77+
"--output",
78+
default=os.environ.get("HARVEST_DATA", sys.stdout),
79+
help="The path to the file where converted data should be written. Defaults to $HARVEST_DATA or stdout.",
7680
)
7781
time_convert.add_argument("--client", default=None, help="The name of the client to use in converted data.")
7882

@@ -92,7 +96,9 @@ def setup_time_command(cmd_parsers: _SubParsersAction):
9296
help="The end date of the reporting period. Defaults to the end of the prior month.",
9397
)
9498
time_download.add_argument(
95-
"--output", default=sys.stdout, help="The path to the file where converted data should be written. Defaults to stdout."
99+
"--output",
100+
default=os.environ.get("TOGGL_DATA", sys.stdout),
101+
help="The path to the file where downloaded data should be written. Defaults to $TOGGL_DATA or stdout.",
96102
)
97103
time_download.add_argument(
98104
"--client",

tests/test_main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from compiler_admin.services.google import DOMAIN
1111

1212

13+
@pytest.fixture(autouse=True)
14+
def reset_env(monkeypatch):
15+
monkeypatch.delenv("HARVEST_DATA", raising=False)
16+
monkeypatch.delenv("TOGGL_DATA", raising=False)
17+
18+
1319
@pytest.fixture
1420
def mock_local_now(mocker):
1521
dt = datetime(2024, 9, 25, tzinfo=TZINFO)
@@ -114,6 +120,20 @@ def test_main_time_convert_default(mock_commands_time):
114120
)
115121

116122

123+
def test_main_time_convert_env(monkeypatch, mock_commands_time):
124+
monkeypatch.setenv("HARVEST_DATA", "harvest")
125+
monkeypatch.setenv("TOGGL_DATA", "toggl")
126+
127+
main(argv=["time", "convert"])
128+
129+
mock_commands_time.assert_called_once()
130+
call_args = mock_commands_time.call_args.args
131+
assert (
132+
Namespace(func=mock_commands_time, command="time", subcommand="convert", client=None, input="toggl", output="harvest")
133+
in call_args
134+
)
135+
136+
117137
@pytest.mark.usefixtures("mock_local_now")
118138
def test_main_time_download_default(mock_commands_time, mock_start, mock_end):
119139
main(argv=["time", "download"])

0 commit comments

Comments
 (0)