Closed masenf closed 3 years ago
Add new test case to reproduce the issue
================================== test session starts ===================================
platform darwin -- Python 3.8.6, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
cachedir: .tox/py38/.pytest_cache
rootdir: /Users/masen/code/dzcb, configfile: tox.ini, testpaths: tests
collected 1 item
tests/test_k7abd.py F [100%]
======================================== FAILURES ========================================
_________________________ test_multiple_repeaters_one_talkgroups _________________________
def test_multiple_repeaters_one_talkgroups():
"""
a Digital-Repeaters__ZoneName.csv files does NOT require a Talkgroups__ZoneName.csv
file, as long as all of the talkgroups are defined in at least one
existing Talkgroups.csv
"""
input_dir = Path(os.path.dirname(__file__)) / "multiple-repeaters-one-talkgroups"
> cp = k7abd.Codeplug_from_k7abd(input_dir)
tests/test_k7abd.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
input_dir = PosixPath('/Users/masen/code/dzcb/tests/multiple-repeaters-one-talkgroups')
def Codeplug_from_k7abd(input_dir):
"""
:param input_dir: directory on the filesystem containing K7ABD ACB files
:return: Codeplug
"""
d = Path(input_dir)
zones = {}
talkgroups = {}
all_talkgroups_by_name = {}
total_files = 0
for p in d.glob("Analog__*.csv"):
update_zones_channels(zones, Analog_from_csv(p.read_text().splitlines()), log_filename=p)
total_files += 1
for p in d.glob("Talkgroups__*.csv"):
name = p.name.replace("Talkgroups__", "").replace(".csv", "")
talkgroups[name] = Talkgroups_map_from_csv(p.read_text().splitlines())
logger.debug("Load %s talkgroups from %s", len(talkgroups[name]), p)
# XXX: potential bug here if talkgroup definitions differ between files
all_talkgroups_by_name.update(talkgroups[name])
for p in d.glob("Digital-Others__*.csv"):
update_zones_channels(zones, DigitalChannels_from_k7abd_csv(p.read_text().splitlines(), all_talkgroups_by_name), log_filename=p)
total_files += 1
for p in d.glob("Digital-Repeaters__*.csv"):
zname = p.name.replace("Digital-Repeaters__", "").replace(".csv", "")
# merge Talkgroup files, but prefer talkgroup names from this zone
tg_csv = all_talkgroups_by_name.copy()
> tg_csv.update(talkgroups[zname])
E KeyError: 'Additional'
.tox/py38/lib/python3.8/site-packages/dzcb/k7abd.py:270: KeyError
Cool, github actions is able to find the regression in CI: https://github.com/masenf/dzcb/runs/1856059300?check_suite_focus=true#step:5:68
Dodge this build error: https://github.com/hillsboro/k7vkt-codeplug/actions/runs/546636848
If the talkgroup mapping exists in one of the files, ignore the key error when reading Digital-Repeaters__ZoneName.csv