Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Jan 30, 2025
1 parent f3758ee commit 55b153e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions ckanext/usmetadata/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def public_access_level_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(r'^(public)|(restricted public)|(non-public)$')
if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
return regex_candidate
Expand All @@ -25,7 +25,7 @@ def public_access_level_validator(regex_candidate):


def bureau_code_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(r'^\d{3}:\d{2}(\s*,\s*\d{3}:\d{2}\s*)*$')
if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
return regex_candidate
Expand All @@ -36,7 +36,7 @@ def bureau_code_validator(regex_candidate):


def program_code_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(r'^\d{3}:\d{3}(\s*,\s*\d{3}:\d{3}\s*)*$')
if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
return regex_candidate
Expand All @@ -47,7 +47,7 @@ def program_code_validator(regex_candidate):


def temporal_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(r'^([\-\dTWRZP/YMWDHMS:\+]{3,}/[\-\dTWRZP/YMWDHMS:\+]{3,})|(\[\[REDACTED).*?(\]\])$')
if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
return regex_candidate
Expand All @@ -58,7 +58,7 @@ def temporal_validator(regex_candidate):


def release_date_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(
r'^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?'
r'|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]'
Expand All @@ -73,7 +73,7 @@ def release_date_validator(regex_candidate):


def accrual_periodicity_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(
r'^([Dd]ecennial)|([Qq]uadrennial)|([Aa]nnual)|([Bb]imonthly)|([Ss]emiweekly)|([Dd]aily)|([Bb]iweekly)'
r'|([Ss]emiannual)|([Bb]iennial)|([Tt]riennial)|([Tt]hree times a week)|([Tt]hree times a month)'
Expand All @@ -91,7 +91,7 @@ def accrual_periodicity_validator(regex_candidate):


def language_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(
r'^(((([A-Za-z]{2,3}(-([A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-([A-Za-z]{4}))?'
r'(-([A-Za-z]{2}|[0-9]{3}))?(-([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-([0-9A-WY-Za-wy-z]'
Expand All @@ -109,7 +109,7 @@ def language_validator(regex_candidate):


def primary_it_investment_uii_validator(regex_candidate):
if type(regex_candidate) == str:
if isinstance(regex_candidate, str):
validator = re.compile(r'^([0-9]{3}-[0-9]{9})|(\[\[REDACTED).*?(\]\])$')
if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
return regex_candidate
Expand Down
2 changes: 1 addition & 1 deletion ckanext/usmetadata/tests/test_expanded_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def validate(sid, values):
try:
if validator in [release_date_validator, accrual_periodicity_validator, language_validator]:
valid = validator(test)
if type(valid) != Invalid:
if type(valid) is not Invalid:
print(" - OK {} for {} at {}".format(test, sid, validator))
ok.append(test)
else:
Expand Down
30 changes: 15 additions & 15 deletions ckanext/usmetadata/tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def testFieldValidationPublicAccessLevelBadValue(self):
schema = self.__getSchemaFromMetadataDict__('public_access_level')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['public_access_level']) == Invalid
assert type(converted_data['public_access_level']) is Invalid

def testFieldValidationPublicAccessLevelRejectsEmpty(self):

Expand All @@ -148,7 +148,7 @@ def testFieldValidationPublicAccessLevelRejectsEmpty(self):
# We want to update the schema to have this test reject empty parameters again
# When updated, the assertion should be similar to the below comment
# self.assertEqual(errors, {'public_access_level':[u'Missing value']})
assert type(converted_data['public_access_level']) == Invalid
assert type(converted_data['public_access_level']) is Invalid

def testFieldValidationPublicAccessLevelRejectsMissing(self):

Expand Down Expand Up @@ -178,7 +178,7 @@ def testFieldValidationPublisherNameTooLong(self):
schema = self.__getSchemaFromMetadataDict__('publisher')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['publisher']) == Invalid
assert type(converted_data['publisher']) is Invalid
assert converted_data['publisher'].error == 'Attribute is too long. (character limit = 300)'

def testFieldValidationPublisherRejectsMissing(self):
Expand Down Expand Up @@ -219,7 +219,7 @@ def testFieldValidationContactNameTooLong(self):
schema = self.__getSchemaFromMetadataDict__('contact_name')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['contact_name']) == Invalid
assert type(converted_data['contact_name']) is Invalid
assert converted_data['contact_name'].error == 'Attribute is too long. (character limit = 300)'

def testFieldValidationContactRejectsMissing(self):
Expand Down Expand Up @@ -258,7 +258,7 @@ def testFieldValidationContactEmailTooLong(self):
schema = self.__getSchemaFromMetadataDict__('contact_email')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['contact_email']) == Invalid
assert type(converted_data['contact_email']) is Invalid
assert converted_data['contact_email'].error == 'Attribute is too long. (character limit = 200)'

def testFieldValidationContactEmailRejectsMissing(self):
Expand Down Expand Up @@ -298,7 +298,7 @@ def testFieldValidationUIDTooLong(self):
schema = self.__getSchemaFromMetadataDict__('unique_id')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['unique_id']) == Invalid
assert type(converted_data['unique_id']) is Invalid
assert converted_data['unique_id'].error == 'Attribute is too long. (character limit = 100)'

def testFieldValidationUIDRejectsMissing(self):
Expand Down Expand Up @@ -349,7 +349,7 @@ def testFieldValidationDataDictionaryTooLong(self):
schema = self.__getSchemaFromMetadataDict__('data_dictionary')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['data_dictionary']) == Invalid
assert type(converted_data['data_dictionary']) is Invalid
assert converted_data['data_dictionary'].error == 'Attribute is too long. (character limit = 2048)'

def testFieldValidationDataDictionaryIgnoresMissing(self):
Expand Down Expand Up @@ -422,7 +422,7 @@ def testFieldValidationSpatialTooLong(self):
schema = self.__getSchemaFromMetadataDict__('spatial')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['spatial']) == Invalid
assert type(converted_data['spatial']) is Invalid
assert converted_data['spatial'].error == 'Attribute is too long. (character limit = 500)'

def testFieldValidationSpatialIgnoresMissing(self):
Expand Down Expand Up @@ -499,7 +499,7 @@ def testFieldValidationAccrualPeriodicityInvalidValue(self):
schema = self.__getSchemaFromMetadataDict__('accrual_periodicity')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['accrual_periodicity']) == Invalid
assert type(converted_data['accrual_periodicity']) is Invalid

def testFieldValidationAccrualPeriodicityIgnoresMissing(self):

Expand Down Expand Up @@ -550,15 +550,15 @@ def testFieldValidationBureauCodeInvalid1(self):
schema = self.__getSchemaFromMetadataDict__('bureau_code')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['bureau_code']) == Invalid
assert type(converted_data['bureau_code']) is Invalid

def testFieldValidationBureauCodeInvalid2(self):

data = {'bureau_code': '000:1'}
schema = self.__getSchemaFromMetadataDict__('bureau_code')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['bureau_code']) == Invalid
assert type(converted_data['bureau_code']) is Invalid

def testFieldValidationBureauCodeValid(self):

Expand Down Expand Up @@ -611,15 +611,15 @@ def testFieldValidationProgramCodeInvalid1(self):
schema = self.__getSchemaFromMetadataDict__('program_code')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['program_code']) == Invalid
assert type(converted_data['program_code']) is Invalid

def testFieldValidationProgramCodeInvalid2(self):

data = {'program_code': '000:11'}
schema = self.__getSchemaFromMetadataDict__('program_code')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['program_code']) == Invalid
assert type(converted_data['program_code']) is Invalid

def testFieldValidationProgramCodeValid(self):

Expand Down Expand Up @@ -672,7 +672,7 @@ def testFieldValidationAccessLevelCommentTooLong(self):
schema = self.__getSchemaFromMetadataDict__('access_level_comment')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['access_level_comment']) == Invalid
assert type(converted_data['access_level_comment']) is Invalid
assert converted_data['access_level_comment'].error == 'Attribute is too long. (character limit = 255)'

def testFieldValidationAccessLevelCommentIgnoresMissing(self):
Expand All @@ -699,7 +699,7 @@ def testFieldValidationInvestmentUIITooLong(self):
schema = self.__getSchemaFromMetadataDict__('primary_it_investment_uii')

converted_data, errors = df.validate(data, schema)
assert type(converted_data['primary_it_investment_uii']) == Invalid
assert type(converted_data['primary_it_investment_uii']) is Invalid
assert converted_data['primary_it_investment_uii'].error == 'Attribute is too long. (character limit = 2100)'

def testFieldValidationInvestmentUIIIgnoresMissing(self):
Expand Down

0 comments on commit 55b153e

Please sign in to comment.