Skip to content

Commit e879798

Browse files
committed
Tests for Module feature
1 parent b19c150 commit e879798

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

qrcode.png

697 Bytes
Loading

qrcode/tests/test_module.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import subprocess
2+
import sys
3+
import tempfile
4+
from pathlib import Path
5+
6+
7+
def test_module_help():
8+
"""Test that the module can be executed with the help flag."""
9+
result = subprocess.run(
10+
[sys.executable, "-m", "qrcode", "-h"],
11+
capture_output=True,
12+
text=True,
13+
check=False,
14+
)
15+
16+
# Check that the command executed successfully
17+
assert result.returncode == 0
18+
19+
# Check that the help output contains expected information
20+
assert "qr - Convert stdin" in result.stdout
21+
assert "--output" in result.stdout
22+
assert "--factory" in result.stdout
23+
24+
25+
def test_module_generate_qrcode():
26+
"""Test that the module can generate a QR code image."""
27+
with tempfile.TemporaryDirectory() as temp_dir:
28+
output_path = Path(temp_dir) / "qrcode.png"
29+
30+
# Run the command to generate a QR code
31+
result = subprocess.run(
32+
[
33+
sys.executable,
34+
"-m",
35+
"qrcode",
36+
"--output",
37+
str(output_path),
38+
"https://github.com/lincolnloop/python-qrcode",
39+
],
40+
capture_output=True,
41+
text=True,
42+
check=False,
43+
)
44+
45+
# Check that the command executed successfully
46+
assert result.returncode == 0
47+
48+
# Check that the output file was created
49+
assert output_path.exists()
50+
51+
# Check that the file is not empty and is a valid image file
52+
assert output_path.stat().st_size > 0

0 commit comments

Comments
 (0)