mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-02 13:12:50 +00:00
fix(salary): accept BOM-prefixed UTF-8 data files (#602)
* fix(salary): accept BOM-prefixed UTF-8 data files Fixes #594. Thanks to @rahul05ranjan for reporting the failure and identifying the decoder change. * docs(changelog): entry for #602 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Mads Lorentzen <madslorentzen_17@hotmail.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+57
-1
No files matched your search
@@ -1,6 +1,10 @@
|
||||
"""Tests for salary_lookup.py — format_entry, match_score, and search_company."""
|
||||
|
||||
import io
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
@@ -600,5 +604,50 @@ class TestSearchCompanyScoreThreshold(unittest.TestCase):
|
||||
self.assertEqual(results[0]["company"], "Novo Nordisk")
|
||||
|
||||
|
||||
class TestSalaryFileEncoding(unittest.TestCase):
|
||||
"""Exercise user-created UTF-8 files through the documented CLI."""
|
||||
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.root = Path(directory.name)
|
||||
self.script = self.root / "salary_lookup.py"
|
||||
shutil.copyfile(salary_lookup.__file__, self.script)
|
||||
self.data_file = self.root / "salary_data.json"
|
||||
self.entry = {
|
||||
"company": "Novo Nordisk A/S",
|
||||
"city": "Bagsværd",
|
||||
"categories": {"engineering": {"count": 120, "index": 112.3}},
|
||||
}
|
||||
|
||||
def run_cli(self, *args):
|
||||
return subprocess.run(
|
||||
[sys.executable, str(self.script), *args],
|
||||
cwd=self.root, capture_output=True, text=True, encoding="utf-8",
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
def test_utf8_with_and_without_bom(self):
|
||||
payload = {"metadata": {"index_baseline": 100}, "companies": [self.entry]}
|
||||
for encoding in ("utf-8", "utf-8-sig"):
|
||||
with self.subTest(encoding=encoding):
|
||||
self.data_file.write_text(
|
||||
json.dumps(payload, ensure_ascii=False), encoding=encoding,
|
||||
)
|
||||
validated = self.run_cli("--validate")
|
||||
self.assertEqual(validated.returncode, 0, validated.stderr)
|
||||
self.assertIn("OK - no issues found.", validated.stdout)
|
||||
lookup = self.run_cli("Novo Nordisk", "--json")
|
||||
self.assertEqual(lookup.returncode, 0, lookup.stderr)
|
||||
self.assertEqual(json.loads(lookup.stdout), [self.entry])
|
||||
|
||||
def test_bom_does_not_hide_invalid_json(self):
|
||||
self.data_file.write_text('{"companies": [}', encoding="utf-8-sig")
|
||||
result = self.run_cli("--validate")
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("invalid JSON at line 1, column 16", result.stderr)
|
||||
self.assertNotIn("Unexpected UTF-8 BOM", result.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user