From ba0ca3e4fb8bb18b17b52a99f09e9c78b926289d Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Sun, 13 Dec 2015 15:03:20 +0100 Subject: [PATCH] =?UTF-8?q?V=C3=A9rifie=20le=20sch=C3=A9ma=20de=20traducti?= =?UTF-8?q?ons.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cela ajoute deux vérifications: - que les données ont le bon format (anglais, français, classe - genre est optionnel) - que les données sont triées par "anglais" --- besoins.txt | 1 + schema.json | 37 +++++++++++++++++++++++++++++++++++++ verifie.py | 24 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 besoins.txt create mode 100644 schema.json create mode 100644 verifie.py diff --git a/besoins.txt b/besoins.txt new file mode 100644 index 0000000..88a2bfd --- /dev/null +++ b/besoins.txt @@ -0,0 +1 @@ +jsonschema==2.5.1 diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..2f3f9cd --- /dev/null +++ b/schema.json @@ -0,0 +1,37 @@ +{ "type": "object", + "properties": { + "faux mots": { + "type": "array", + "items": {"$ref": "#/definitions/mot"} + }, + "vrais mots": { + "type": "array", + "items": {"$ref": "#/definitions/mot"} + } + }, + "definitions": { + "mot": { + "type": "object", + "properties": + { + "anglais": {"type": "string"}, + "francais": {"type": "string"}, + "classe": { + "type": "string", + "enum": [ + "groupe nominal", + "groupe verbal", + "proposition", + "verbe" + ] + }, + "genre": { + "type": "string", + "enum": ["f", "m"] + }, + "pluriel": {"type": "boolean"} + }, + "required": ["anglais", "francais", "classe"] + } + } +} diff --git a/verifie.py b/verifie.py new file mode 100644 index 0000000..e8f7621 --- /dev/null +++ b/verifie.py @@ -0,0 +1,24 @@ +import json +from jsonschema import validate as valide + + +def verifie_ordre(mots): + for (a, b) in zip(mots, mots[1:]): + mot_a = a['anglais'].lower() + mot_b = b['anglais'].lower() + msg = "%s et %s ne sont pas dans le bon ordre" % (mot_a, mot_b) + assert mot_a < mot_b, msg + + +def principal(): + with open('traductions.json') as f: + d = json.load(f) + with open('schema.json') as f: + schema = json.load(f) + valide(d, schema) + verifie_ordre(d['faux mots']) + verifie_ordre(d['vrais mots']) + + +if __name__ == '__main__': + principal()