Skip to content

The job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.

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

student-mayank429e32f7c0aa
diff --git a/salary_lookup.py b/salary_lookup.py
index d0cb379b..35022160 100644
--- a/salary_lookup.py
+++ b/salary_lookup.py
@@ -160,7 +160,7 @@ def search_company(data, query, city=None):
for entry in companies:
if city:
city_lower = city.lower()
- entry_city = entry.get("city", "").lower()
+ entry_city = (entry.get("city") or "").lower()
if city_lower not in entry_city and anglicize(city_lower) not in anglicize(entry_city):
continue
@@ -206,10 +206,13 @@ def format_entry(entry, metadata):
if count is not None or index is not None:
count_str = str(count) if count is not None else "-"
if isinstance(index, (int, float)):
- diff = index - baseline
- sign = "+" if diff >= 0 else ""
index_str = f"{index:.1f}"
- diff_str = f"{sign}{diff:.1f}%"
+ if baseline == 0:
+ diff_str = ""
+ else:
+ diff_pct = ((index - baseline) / baseline) * 100
+ sign = "+" if diff_pct >= 0 else ""
+ diff_str = f"{sign}{diff_pct:.1f}%"
elif index is not None:
index_str = str(index)
diff_str = ""
diff --git a/tests/test_salary_lookup.py b/tests/test_salary_lookup.py
index 361771c7..bf647b0e 100644
--- a/tests/test_salary_lookup.py
+++ b/tests/test_salary_lookup.py
@@ -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()