Skip to content

Commit

Permalink
test the happy paths
Browse files Browse the repository at this point in the history
  • Loading branch information
muathendirangu committed Feb 5, 2024
1 parent 29c16ff commit 48600e9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ 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: |
# stop the build if there are Python syntax errors or undefined names
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
38 changes: 0 additions & 38 deletions reconciler_test.py

This file was deleted.

3 changes: 3 additions & 0 deletions test_output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Type,Record Identifier,Field,Source Value,Target Value
Missing in Target,1,,,
Missing in Source,3,,,
46 changes: 46 additions & 0 deletions test_reconciler.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 48600e9

Please sign in to comment.