2026-08-16 18:35:42 +00:00
|
|
|
import subprocess
|
|
|
|
|
import unittest
|
2026-08-16 18:37:34 +00:00
|
|
|
from pathlib import Path
|
2026-08-16 18:35:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestHello(unittest.TestCase):
|
|
|
|
|
def test_hello_output(self):
|
|
|
|
|
"""Test that hello.py prints 'Hello, World!' to stdout."""
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["python3", "hello.py"],
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
2026-08-16 18:37:34 +00:00
|
|
|
cwd=Path(__file__).parent
|
2026-08-16 18:35:42 +00:00
|
|
|
)
|
|
|
|
|
self.assertEqual(result.returncode, 0)
|
|
|
|
|
self.assertIn("Hello, World!", result.stdout)
|
|
|
|
|
|
|
|
|
|
def test_hello_no_stderr(self):
|
|
|
|
|
"""Test that hello.py produces no stderr output."""
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["python3", "hello.py"],
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
2026-08-16 18:37:34 +00:00
|
|
|
cwd=Path(__file__).parent
|
2026-08-16 18:35:42 +00:00
|
|
|
)
|
|
|
|
|
self.assertEqual(result.stderr, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|