Skip to content

Commit e931957

Browse files
thatchamyreese
authored andcommitted
Add test for --keep
1 parent a077414 commit e931957

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import tarfile
23
import unittest
34
from pathlib import Path
@@ -106,3 +107,13 @@ def patched_check_call(cmd: List[str], **kwargs: Any) -> Any:
106107
self.assertEqual("", result.output)
107108
self.assertFalse(result.exception)
108109
self.assertEqual(1, uploads)
110+
111+
@patch("squatter.templates.check_output")
112+
@patch("squatter.templates.check_call")
113+
def test_cli_keep_flag(self, check_call_mock: Any, check_output_mock: Any) -> None:
114+
runner = CliRunner()
115+
result = runner.invoke(generate, ["--keep", "foo"])
116+
m = re.match("Generating in (.+)", result.output)
117+
assert Path(m.group(1)).exists()
118+
assert Path(m.group(1), "pyproject.toml")
119+
self.assertFalse(result.exception)

0 commit comments

Comments
 (0)