fix(salary): handle missing/null city & resolve custom baseline percentage bug (#98)

* fix: handle None value for city key in salary lookup

* fix: calculate correct percentage difference for non-100 baselines in salary lookup
This commit is contained in:
student-mayank
2026-07-09 21:14:15 +02:00
committed by GitHub
parent 6a1240648f
commit 429e32f7c0
2 changed files with 52 additions and 5 deletions
+45 -1
View File
@@ -1,6 +1,6 @@
import unittest
from salary_lookup import format_entry
from salary_lookup import format_entry, search_company
class FormatEntryTests(unittest.TestCase):
@@ -36,6 +36,50 @@ class FormatEntryTests(unittest.TestCase):
self.assertIn("private", rendered)
def test_format_entry_with_zero_baseline(self):
entry = {
"company": "Example Corp",
"city": "",
"categories": {
"it": {
"count": None,
"index": 45000.0,
},
},
}
rendered = format_entry(entry, {"index_baseline": 0, "index_label": "Salary"})
self.assertIn("45000.0", rendered)
self.assertNotIn("%", rendered)
def test_format_entry_with_custom_baseline(self):
entry = {
"company": "Example Corp",
"city": "",
"categories": {
"it": {
"count": None,
"index": 45000.0,
},
},
}
rendered = format_entry(entry, {"index_baseline": 40000, "index_label": "Salary"})
self.assertIn("45000.0", rendered)
self.assertIn("+12.5%", rendered)
class SearchCompanyTests(unittest.TestCase):
def test_search_company_with_none_city(self):
data = {
"companies": [
{
"company": "Acme",
"city": None,
}
]
}
results = search_company(data, "Acme", city="Aarhus")
self.assertEqual(results, [])
if __name__ == "__main__":
unittest.main()