Skip to content

Commit

Permalink
Fix for invalid name column throwing error (#44)
Browse files Browse the repository at this point in the history
* Updated validator to catch invalid names
* Updated pyinstaller so builds work again
  • Loading branch information
n2qzshce authored Jul 23, 2022
1 parent ffe95a4 commit 8e547a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pyinstaller-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: Build executeable

env:
semver: 1.10.0.${{ github.run_number }}
semver: 1.10.1.${{ github.run_number }}
python-version: 3.8
KIVY_GL_BACKEND: 'angle_sdl2'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ gpxpy == 1.4.2 #gpx output
Kivy == 2.0.0 #gui
kivy-garden.contextmenu == 0.1.0.dev1 #app context menu
openpyxl == 3.0.7 #xlsx support
pyinstaller == 4.3 #compilation
requests == 2.25.1
pyinstaller == 4.10 #compilation
requests == 2.25.1 #version checking
semantic-version == 2.8.5 #semantic version comparing
32 changes: 28 additions & 4 deletions src/ham/util/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@


class Validator:
MAX_MEDIUM_NAME_LENGTH = 8
MAX_SHORT_NAME_LENGTH = 7

def __init__(self):
self._radio_channel_template = RadioChannelDefault.create_empty()
self._digital_contact_template = DmrContactDefault.create_empty()
Expand Down Expand Up @@ -75,7 +78,21 @@ def validate_radio_channel(self, cols, line_num, file_name, digital_contacts, zo
return errors

channel = RadioChannel(cols, None, None)
if channel.short_name.fmt_val().lower() in self._short_names.keys():

if len(channel.medium_name.fmt_val()) > self.MAX_MEDIUM_NAME_LENGTH:
err = ValidationError(f"Line {line_num} '{channel.medium_name.get_alias(radio_types.DEFAULT)}' greater than {self.MAX_MEDIUM_NAME_LENGTH} characters in length", line_num, file_name)
logging.debug(err.message)
errors.append(err)
if len(channel.short_name.fmt_val()) > self.MAX_SHORT_NAME_LENGTH:
err = ValidationError(f"Line {line_num} '{channel.short_name.get_alias(radio_types.DEFAULT)}' greater than {self.MAX_MEDIUM_NAME_LENGTH} characters in length", line_num, file_name)
logging.debug(err.message)
errors.append(err)

if channel.short_name.fmt_val() is None:
err = ValidationError(f"'medium_name' column cannot be empty", line_num, file_name)
logging.debug(err.message)
errors.append(err)
elif channel.short_name.fmt_val().lower() in self._short_names.keys():
err = ValidationError(
f"Collision in {channel.short_name.get_alias(radio_types.DEFAULT)} "
f"(value: `{channel.short_name.fmt_val()}`) found with line"
Expand All @@ -86,7 +103,11 @@ def validate_radio_channel(self, cols, line_num, file_name, digital_contacts, zo
else:
self._short_names[channel.short_name.fmt_val().lower()] = line_num

if channel.medium_name.fmt_val().lower() in self._medium_names.keys():
if channel.medium_name.fmt_val() is None:
err = ValidationError(f"'medium_name' column cannot be empty", line_num, file_name)
logging.debug(err.message)
errors.append(err)
elif channel.medium_name.fmt_val().lower() in self._medium_names.keys():
err = ValidationError(
f"Collision in {channel.medium_name.get_alias(radio_types.DEFAULT)} "
f"(value: `{channel.medium_name.fmt_val()}`) found with line"
Expand All @@ -97,7 +118,11 @@ def validate_radio_channel(self, cols, line_num, file_name, digital_contacts, zo
else:
self._medium_names[channel.medium_name.fmt_val().lower()] = line_num

if channel.name.fmt_val().lower() in self._long_names.keys():
if channel.name.fmt_val() is None:
err = ValidationError(f"'name' column cannot be empty", line_num, file_name)
logging.debug(err.message)
errors.append(err)
elif channel.name.fmt_val().lower() in self._long_names.keys():
err = ValidationError(
f"Collision in {channel.name.get_alias(radio_types.DEFAULT)} "
f"(value: `{channel.name.fmt_val()}`) found with line"
Expand Down Expand Up @@ -172,7 +197,6 @@ def _validate_generic(self, cols, line_num, file_name, needed_cols_dict_gen):

for val in needed_cols_dict_gen.values():
if not isinstance(val, DataColumn):
logging.debug(f"Skipping adding `{val}` to needed cols")
continue
needed_cols[val.get_alias(radio_types.DEFAULT)] = val

Expand Down
6 changes: 6 additions & 0 deletions test/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@ def test_validate_bad_long(self):
self.assertEqual(len(errors), 1)
found = errors[0].args[0].find('Longitude must be between')
self.assertEqual(found, 0)

def test_name_missing(self):
self.radio_cols['name'] = ''
errors = self.validator.validate_radio_channel(self.radio_cols, 1, 'LAT_LONG_UNITTEST', {}, {})
self.assertEqual(len(errors), 1)

0 comments on commit 8e547a8

Please sign in to comment.