|
1 | | -import json |
2 | 1 | import os |
3 | 2 | import subprocess |
4 | | -import sys |
5 | 3 | from pathlib import Path |
6 | | -from unittest import mock |
7 | 4 |
|
8 | | -from cookie_python.new import main |
9 | 5 |
|
10 | | - |
11 | | -def test_new_cookie_create(temp_dir: Path) -> None: |
12 | | - testargs = [ |
13 | | - "new-cookie", |
14 | | - "--local", |
15 | | - str(temp_dir), |
16 | | - "--", |
17 | | - "-d", |
18 | | - "-y", |
19 | | - "--extra-context", |
20 | | - json.dumps( |
21 | | - { |
22 | | - "author_email": "ness@onett.example", |
23 | | - "author_name": "Ness", |
24 | | - "github_user": "ness.unittest.example", |
25 | | - "project_description": "Unit test project", |
26 | | - "project_name": "unit-test-1", |
27 | | - "enable_container_publish": "yes", |
28 | | - } |
29 | | - ), |
30 | | - ] |
31 | | - with mock.patch.object(sys, "argv", testargs): |
32 | | - main() |
33 | | - project_dir = temp_dir / "unit-test-1" |
34 | | - assert os.path.isdir(project_dir) |
| 6 | +def test_new_cookie_create(new_cookie: Path, temp_dir: Path) -> None: |
| 7 | + assert os.path.isdir(new_cookie) |
35 | 8 | assert not ( |
36 | 9 | subprocess.check_output( |
37 | | - ["git", "status", "--porcelain=v1"], cwd=project_dir |
| 10 | + ["git", "status", "--porcelain=v1"], cwd=new_cookie |
38 | 11 | ) |
39 | 12 | .decode("utf-8") |
40 | 13 | .strip() |
41 | 14 | ), "Untracked files present in template-rendered project" |
42 | 15 |
|
43 | 16 | # Verify cruft is up to date |
44 | 17 | subprocess.check_call( |
45 | | - ["poetry", "run", "pip", "install", "toml"], cwd=project_dir |
| 18 | + ["poetry", "run", "pip", "install", "toml"], cwd=new_cookie |
46 | 19 | ) |
47 | 20 | subprocess.check_call( |
48 | | - ["poetry", "run", "cruft", "diff", "--exit-code"], cwd=project_dir |
| 21 | + ["poetry", "run", "cruft", "diff", "--exit-code"], cwd=new_cookie |
49 | 22 | ) |
50 | 23 |
|
51 | 24 | # Install rendered project |
52 | | - subprocess.check_call(["poetry", "sync"], cwd=project_dir) |
| 25 | + subprocess.check_call(["poetry", "sync"], cwd=new_cookie) |
53 | 26 | # Run rendered project's tests |
54 | | - subprocess.check_call(["poetry", "run", "poe", "test"], cwd=project_dir) |
| 27 | + subprocess.check_call(["poetry", "run", "poe", "test"], cwd=new_cookie) |
55 | 28 | # Build container for rendered project |
56 | 29 | subprocess.check_call( |
57 | | - ["docker", "build", ".", "--no-cache"], cwd=project_dir |
| 30 | + ["docker", "build", ".", "--no-cache"], cwd=new_cookie |
58 | 31 | ) |
0 commit comments