From eccdc9cfdff458c4bfd9f571485fdbc474096ecc Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 04:07:02 +0000 Subject: [PATCH 1/2] Add unit testing setup with pytest configuration Initial test infrastructure setup including: - Basic unit test example - pytest configuration - Development dependencies - Test directory structure --- pytest.ini | 5 +++++ requirements-dev.txt | 2 ++ tests/__init__.py | 0 tests/test_sample.py | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 pytest.ini create mode 100644 requirements-dev.txt create mode 100644 tests/__init__.py create mode 100644 tests/test_sample.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..38be796 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +testpaths = tests +python_files = test_*.py +python_classes = Test* +python_functions = test_* \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..7571d09 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +pytest>=7.0.0 +pytest-cov>=4.0.0 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 0000000..058c458 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,17 @@ +import unittest + +class TestSample(unittest.TestCase): + def setUp(self): + """Set up test fixtures before each test method.""" + pass + + def tearDown(self): + """Clean up test fixtures after each test method.""" + pass + + def test_sample(self): + """Test case example.""" + self.assertEqual(1 + 1, 2) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 8a8798ffcb04fd5a0494cacd7626e5c542a01372 Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 04:10:14 +0000 Subject: [PATCH 2/2] test: add unit tests for basic operations Added test cases for arithmetic, strings, lists and setup functionality to improve test coverage. --- tests/test_sample.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/test_sample.py b/tests/test_sample.py index 058c458..7f995be 100644 --- a/tests/test_sample.py +++ b/tests/test_sample.py @@ -3,15 +3,35 @@ class TestSample(unittest.TestCase): def setUp(self): """Set up test fixtures before each test method.""" - pass - + self.test_value = 10 + def tearDown(self): """Clean up test fixtures after each test method.""" pass - def test_sample(self): - """Test case example.""" + def test_addition(self): + """Test basic addition.""" self.assertEqual(1 + 1, 2) + + def test_multiplication(self): + """Test basic multiplication.""" + self.assertEqual(2 * 3, 6) + + def test_string_concatenation(self): + """Test string concatenation.""" + self.assertEqual("Hello " + "World", "Hello World") + + def test_list_operations(self): + """Test list operations.""" + test_list = [1, 2, 3] + test_list.append(4) + self.assertEqual(len(test_list), 4) + self.assertIn(4, test_list) + + def test_value_from_setup(self): + """Test using value from setUp.""" + self.assertEqual(self.test_value, 10) + self.assertGreater(self.test_value, 5) if __name__ == '__main__': unittest.main() \ No newline at end of file