Skip to content

Commit 810d6fb

Browse files
authored
Merge pull request #16 from sandialabs/add-dry-run-test
Add dry run test
2 parents 14a8995 + c44d6ff commit 810d6fb

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

.coveragerc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[run]
2+
omit =
3+
test/*
4+
*/.vscode/*
5+
branch = True
6+
dynamic_context = test_function
7+
relative_files = True
8+
9+
[paths]
10+
source = staged_script
11+
12+
[report]
13+
skip_covered = False
14+
fail_under = 100
15+
show_missing = True
16+
exclude_lines =
17+
pragma: no cover
18+
if 0:
19+
if False:
20+
21+
[html]
22+
directory = test/htmlcov
23+
title = staged-script Coverage Report
24+
show_contexts = True
25+
26+
[xml]
27+
output = test/coverage.xml
28+
29+
[json]
30+
output = test/coverage.json
31+
pretty_print = True
32+
show_contexts = True
33+
34+
[lcov]
35+
output = test/coverage.lcov

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
20+
fail-fast: false
2021
steps:
2122

2223
- name: Check out the commit

staged_script/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
HelpFormatter,
1717
RetryStage,
1818
StageDuration,
19-
lazy_property,
2019
)
2120

2221
__all__ = [
2322
"StagedScript",
2423
"HelpFormatter",
2524
"RetryStage",
2625
"StageDuration",
27-
"lazy_property",
2826
]
2927
__version__ = "1.0.0"

staged_script/staged_script.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,6 @@
4141
rich.traceback.install()
4242

4343

44-
def lazy_property(func: Callable) -> property:
45-
"""
46-
A decorator to make it such that a property is lazily evaluated.
47-
48-
When the property is first accessed, the object will not yet have a
49-
corresponding attribute, so the value will be computed by executing
50-
:arg:`func`. Any time the property is accessed thereafter, the
51-
value will just be retrieved from the object's corresponding
52-
attribute.
53-
54-
Args:
55-
func: The function used to compute the value of the property.
56-
57-
Returns:
58-
The lazy property decorator.
59-
"""
60-
attr_name = f"_lazy_{func.__name__}"
61-
62-
@property # type: ignore[misc]
63-
def _lazy_property(self):
64-
if not hasattr(self, attr_name):
65-
setattr(self, attr_name, func(self))
66-
return getattr(self, attr_name)
67-
68-
return _lazy_property # type: ignore[return-value]
69-
70-
7144
class StageDuration(NamedTuple):
7245
"""
7346
The duration of a stage.
@@ -250,7 +223,7 @@ def _validate_stage_name(stage_name: str) -> None:
250223
# Parse the command line arguments.
251224
#
252225

253-
@lazy_property
226+
@functools.cached_property
254227
def parser(self) -> ArgumentParser:
255228
"""
256229
The base argument parser.
@@ -261,7 +234,7 @@ def parser(self) -> ArgumentParser:
261234
262235
.. code-block:: python
263236
264-
@lazy_property
237+
@functools.cached_property
265238
def parser(self) -> ArgumentParser:
266239
ap = super().parser
267240
ap.description = '''INSERT DESCRIPTION HERE'''

test/test_staged_script.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ def test_run_override_print_commands(
223223
assert f"Executing: {command}" in captured.out
224224

225225

226+
def test_run_dry_run(
227+
script: StagedScript, capsys: pytest.CaptureFixture
228+
) -> None:
229+
"""Test the :func:`run` method in dry-run mode."""
230+
command = "echo 'dry-run mode'"
231+
script.dry_run = True
232+
script.run(command)
233+
captured = capsys.readouterr()
234+
for _ in ["The command executed would be", command]:
235+
assert _ in captured.out
236+
237+
226238
@pytest.mark.parametrize("script_success", [True, False])
227239
@pytest.mark.parametrize(
228240
"extras",

0 commit comments

Comments
 (0)