-
Notifications
You must be signed in to change notification settings - Fork 726
Expand file tree
/
Copy pathtest_module.py
More file actions
62 lines (49 loc) · 1.68 KB
/
test_module.py
File metadata and controls
62 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import subprocess
import sys
import tempfile
from pathlib import Path
import pytest
try:
from PIL import Image, ImageDraw # noqa: F401
PIL_NOT_INSTALLED = False
except ImportError:
PIL_NOT_INSTALLED = True
def test_module_help():
"""Test that the module can be executed with the help flag."""
result = subprocess.run(
[sys.executable, "-m", "qrcode", "-h"],
capture_output=True,
text=True,
check=False,
)
# Check that the command executed successfully
assert result.returncode == 0
# Check that the help output contains expected information
assert "qr - Convert stdin" in result.stdout
assert "--output" in result.stdout
assert "--factory" in result.stdout
@pytest.mark.skipif(PIL_NOT_INSTALLED, reason="PIL is not installed")
def test_module_generate_qrcode():
"""Test that the module can generate a QR code image."""
with tempfile.TemporaryDirectory() as temp_dir:
output_path = Path(temp_dir) / "qrcode.png"
# Run the command to generate a QR code
result = subprocess.run(
[
sys.executable,
"-m",
"qrcode",
"--output",
str(output_path),
"https://github.com/lincolnloop/python-qrcode",
],
capture_output=True,
text=True,
check=False,
)
# Check that the command executed successfully
assert result.returncode == 0
# Check that the output file was created
assert output_path.exists()
# Check that the file is not empty and is a valid image file
assert output_path.stat().st_size > 0