From fac13116dd87e15c496d1ebc296358bd184d9e67 Mon Sep 17 00:00:00 2001 From: orchestrator-bot Date: Sun, 16 Aug 2026 18:38:57 +0000 Subject: [PATCH] tester: add unit tests iteration 2 --- tests/__init__.py | 1 + tests/test_hello.py | 94 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_hello.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..c342023 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Tests package for hello.py.""" diff --git a/tests/test_hello.py b/tests/test_hello.py new file mode 100644 index 0000000..3e33f0e --- /dev/null +++ b/tests/test_hello.py @@ -0,0 +1,94 @@ +"""Unit tests for hello.py module.""" + +import subprocess +import unittest +from pathlib import Path + + +class TestHelloOutput(unittest.TestCase): + """Tests for hello.py output behavior.""" + + def setUp(self): + """Set up test fixtures.""" + self.hello_script = Path(__file__).parent.parent / "hello.py" + self.working_dir = Path(__file__).parent.parent + + def test_hello_prints_expected_message(self): + """Test that hello.py prints 'Hello, World!' to stdout.""" + result = subprocess.run( + ["python3", str(self.hello_script)], + capture_output=True, + text=True, + cwd=self.working_dir + ) + self.assertIn("Hello, World!", result.stdout) + + def test_hello_exact_output(self): + """Test that hello.py output matches exactly (with newline).""" + result = subprocess.run( + ["python3", str(self.hello_script)], + capture_output=True, + text=True, + cwd=self.working_dir + ) + self.assertEqual(result.stdout.strip(), "Hello, World!") + + def test_hello_exit_code_zero(self): + """Test that hello.py exits with code 0.""" + result = subprocess.run( + ["python3", str(self.hello_script)], + capture_output=True, + text=True, + cwd=self.working_dir + ) + self.assertEqual(result.returncode, 0) + + def test_hello_no_stderr(self): + """Test that hello.py produces no stderr output.""" + result = subprocess.run( + ["python3", str(self.hello_script)], + capture_output=True, + text=True, + cwd=self.working_dir + ) + self.assertEqual(result.stderr, "") + + def test_hello_stdout_not_empty(self): + """Test that hello.py produces non-empty stdout.""" + result = subprocess.run( + ["python3", str(self.hello_script)], + capture_output=True, + text=True, + cwd=self.working_dir + ) + self.assertTrue(len(result.stdout) > 0) + + +class TestHelloFileExists(unittest.TestCase): + """Tests for hello.py file existence and content.""" + + def setUp(self): + """Set up test fixtures.""" + self.hello_script = Path(__file__).parent.parent / "hello.py" + + def test_hello_file_exists(self): + """Test that hello.py file exists.""" + self.assertTrue(self.hello_script.exists()) + + def test_hello_file_is_python(self): + """Test that hello.py has .py extension.""" + self.assertEqual(self.hello_script.suffix, ".py") + + def test_hello_file_contains_print(self): + """Test that hello.py contains a print statement.""" + content = self.hello_script.read_text() + self.assertIn("print", content) + + def test_hello_file_contains_hello_world(self): + """Test that hello.py contains 'Hello, World!' string.""" + content = self.hello_script.read_text() + self.assertIn("Hello, World!", content) + + +if __name__ == "__main__": + unittest.main()