Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update schema to detect duplicates #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions source/langtags_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"tags": {
"type": "array",
"items": { "$ref": "#/definitions/bcp47" },
"additionalItems": false
"additionalItems": false,
"uniqueItems": true
},
"variants": {
"type": "array",
"items": { "$ref": "#/definitions/bcp47_variant" },
"additionalItems": false
"additionalItems": false,
"uniqueItems": true
},
"iso639_3": {
"$ref": "#/definitions/iso639_3"
Expand All @@ -43,21 +45,24 @@
"regions": {
"type": "array",
"items": { "$ref": "#/definitions/iso3166_1" },
"additionalItems": false
"additionalItems": false,
"uniqueItems": true
},
"regionname": {
"type": "string"
},
"iana": {
"type": "array",
"items": { "type": "string" }
"items": { "type": "string" },
"uniqueItems": true
},
"name": {
"type": "string"
},
"names": {
"type": "array",
"items": { "type": "string" }
"items": { "type": "string" },
"uniqueItems": true
},
"localname": {
"type": "string"
Expand All @@ -76,11 +81,13 @@
},
"localnames": {
"type": "array",
"items": { "type": "string" }
"items": { "type": "string" },
"uniqueItems": true
},
"latnnames": {
"type": "array",
"items": { "type": "string" }
"items": { "type": "string" },
"uniqueItems": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need not be unique. The key is that each entry aligns with a corresponding entry in the localnames array.

},
"suppress": {
"type": "boolean"
Expand Down
21 changes: 20 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
schemapath = os.path.join(os.path.dirname(__file__), '..', 'source', 'langtags_schema.json')
testfile = os.path.join(os.path.dirname(__file__), '..', 'pub', 'langtags.json')


class JsonSchemaTest(unittest.TestCase):
''' Tests that generated JSON conforms to the schema '''
def test_jsonschema(self):
Expand All @@ -25,7 +26,25 @@ def test_jsonschema(self):
testdata = json.load(inf)
for error in validator.iter_errors(testdata):
errors.append(error.message)
if len(errors):
if len(errors) > 0:
self.fail("\n".join(errors))

def test_duplicate_tags(self):
'test for duplicate tags not found by schema'
unique_values = set()
locations = {}
errors = []
with open(testfile) as data:
testdata = json.load(data)
for item in testdata:
if 'tags' in item:
for value in item['tags']:
if value in unique_values:
errors.append(f'tag {value} is repeated at {item["full"]} and {locations[value]}')
else:
unique_values.add(value)
locations[value] = item['full']
if len(errors) > 0:
self.fail("\n".join(errors))


Expand Down