Skip to content

Commit a474a1b

Browse files
committed
Add test for --keep
1 parent b9721c2 commit a474a1b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

squatter/__main__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ def cli() -> None: # pragma: no cover
1212

1313

1414
@cli.command(help="Generate a package")
15-
@click.option(
16-
"--keep", is_flag=True, default=False, help="Do not delete temp dir"
17-
)
15+
@click.option("--keep", is_flag=True, default=False, help="Do not delete temp dir")
1816
@click.option(
1917
"--upload", is_flag=True, default=False, help="Whether to invoke twine upload"
2018
)
@@ -24,7 +22,11 @@ def cli() -> None: # pragma: no cover
2422
)
2523
@click.argument("package_name")
2624
def generate(
27-
package_name: str, upload: bool, keep: bool, author: Optional[str], author_email: Optional[str]
25+
package_name: str,
26+
upload: bool,
27+
keep: bool,
28+
author: Optional[str],
29+
author_email: Optional[str],
2830
) -> None:
2931
# TODO flag for delete
3032
with tempfile.TemporaryDirectory(prefix=package_name, delete=not keep) as d:

squatter/tests/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os.path
2+
import re
13
import unittest
24
from pathlib import Path
35
from subprocess import check_call
@@ -87,3 +89,13 @@ def patched_check_call(cmd: List[str], **kwargs: Any) -> Any:
8789
self.assertEqual("", result.output)
8890
self.assertFalse(result.exception)
8991
self.assertEqual(1, uploads)
92+
93+
@patch("squatter.templates.check_output")
94+
@patch("squatter.templates.check_call")
95+
def test_cli_keep_flag(self, check_call_mock: Any, check_output_mock: Any) -> None:
96+
runner = CliRunner()
97+
result = runner.invoke(generate, ["--keep", "foo"])
98+
m = re.match("Generating in (.+)", result.output)
99+
assert os.path.exists(m.group(1))
100+
assert os.path.exists(os.path.join(m.group(1), "setup.py"))
101+
self.assertFalse(result.exception)

0 commit comments

Comments
 (0)