diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f3d4fca..e7419f3 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install flake8 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | @@ -34,6 +34,6 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest + - name: Test with unittests run: | - pytest + python -m unittest test_reconciler.py diff --git a/reconciler_test.py b/reconciler_test.py deleted file mode 100644 index 8a2b5aa..0000000 --- a/reconciler_test.py +++ /dev/null @@ -1,38 +0,0 @@ -import unittest -from unittest.mock import patch -import csv -from reconciler import Reconciler - -class TestReconciler(unittest.TestCase): - def setUp(self): - self.source_data = [ - {'ID': '1', 'Name': 'John', 'Age': '20'}, - {'ID': '2', 'Name': 'Jane', 'Age': '21'}, - {'ID': '3', 'Name': 'Jill', 'Age': '22'}, - {'ID': '4', 'Name': 'Jack', 'Age': '23'}, - ] - self.target_data = [ - {'ID': '1', 'Name': 'John', 'Age': '20'}, - {'ID': '2', 'Name': 'Jane', 'Age': '21'}, - {'ID': '3', 'Name': 'Jill', 'Age': '22'}, - {'ID': '4', 'Name': 'Jack', 'Age': '23'}, - {'ID': '5', 'Name': 'Jake', 'Age': '24'}, - ] - - @patch('reconcile.Reconcile._read_csv') - def test_check_missing_records(self, mock_read_csv): - mock_read_csv.side_effect = [self.source_data, self.target_data] - reconcile = Reconciler('source.csv', 'target.csv') - missing_in_target, missing_in_source = reconcile.reconcile_data() - self.assertEqual(missing_in_target, {'5'}) - self.assertEqual(missing_in_source, {'5'}) - - @patch('reconciler.Reconciler._read_csv') - def test_report_generation(self, mock_read_csv): - mock_read_csv.return_value = [] - reconciler = Reconciler('source.csv', 'target.csv') - report = reconciler.reconcile_data() - - with patch('reconciler.ReconciliationReport.generate_report') as mock_generate_report: - reconciler.reconcile_data().generate_report('output.csv') - mock_generate_report.assert_called_once_with('output.csv') diff --git a/test_output.csv b/test_output.csv new file mode 100644 index 0000000..a915fc9 --- /dev/null +++ b/test_output.csv @@ -0,0 +1,3 @@ +Type,Record Identifier,Field,Source Value,Target Value +Missing in Target,1,,, +Missing in Source,3,,, diff --git a/test_reconciler.py b/test_reconciler.py new file mode 100644 index 0000000..503ff1a --- /dev/null +++ b/test_reconciler.py @@ -0,0 +1,46 @@ +import unittest +import csv +import os +from reconciler import Reconciler, ReconciliationReport + +class TestReconciler(unittest.TestCase): + def setUp(self): + # Create sample CSV files for testing + self.source_csv_path = 'test_source.csv' + self.target_csv_path = 'test_target.csv' + self.output_csv_path = 'test_output.csv' + + self.create_sample_csv(self.source_csv_path, [{'ID': '1', 'Name': 'John'}, {'ID': '2', 'Name': 'Alice'}]) + self.create_sample_csv(self.target_csv_path, [{'ID': '2', 'Name': 'Alice'}, {'ID': '3', 'Name': 'Bob'}]) + + def tearDown(self): + # Remove sample CSV files after testing + os.remove(self.source_csv_path) + os.remove(self.target_csv_path) + + + def create_sample_csv(self, file_path, data): + with open(file_path, 'w', newline='') as file: + writer = csv.DictWriter(file, fieldnames=['ID', 'Name']) + writer.writeheader() + writer.writerows(data) + + def test_reconciliation_with_discrepancies(self): + rc = Reconciler(self.source_csv_path, self.target_csv_path) + report = rc.reconcile_data() + + self.assertIsInstance(report, ReconciliationReport) + self.assertTrue(report.missing_in_target) + self.assertTrue(report.missing_in_source) + self.assertTrue(report.discrepancies) + + + def test_report_generation(self): + rc = Reconciler(self.source_csv_path, self.target_csv_path) + report = rc.reconcile_data() + report.generate_report(self.output_csv_path) + + self.assertTrue(os.path.exists(self.output_csv_path)) + +if __name__ == '__main__': + unittest.main()