From ed30b995ef4c905b08b082826aa67f226b31ce50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Wed, 25 Nov 2020 16:38:48 +0300 Subject: [PATCH] Json format encoding bug is fixed #46 --- calculate/templates/format/json_format.py | 9 ++++++--- tests/templates/format/test_json.py | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/calculate/templates/format/json_format.py b/calculate/templates/format/json_format.py index 6a2e010..5724c7c 100644 --- a/calculate/templates/format/json_format.py +++ b/calculate/templates/format/json_format.py @@ -37,11 +37,14 @@ class JSONFormat(Format): '''Метод для получения словаря документа, переопределяющий метод базового класса.''' self._document_dictionary = json.loads(json_file_text, - object_pairs_hook=OrderedDict) + object_pairs_hook=OrderedDict, + encoding="utf8") @property def document_text(self): '''Метод для получения текста документа, переопределяющий метод базового класса.''' - json_file_text = json.dumps(self._document_dictionary, indent=4) - return json_file_text + json_file_text = json.dumps(self._document_dictionary, + ensure_ascii=False, + indent=4).encode('utf8') + return json_file_text.decode() diff --git a/tests/templates/format/test_json.py b/tests/templates/format/test_json.py index d127d76..801b092 100644 --- a/tests/templates/format/test_json.py +++ b/tests/templates/format/test_json.py @@ -106,8 +106,7 @@ class TestParsingMethods: "Description[de]": "Anpassung der Lautstärke von Geräten und Anwendungen", "Description[el]": "Προσαρμογή της έντασης των συσκευών και εφαρμογών", "test": "false" -} -''' +}''' original_object = JSONFormat(original_text, '/path/to/template') template_object = JSONFormat(template_text, '/path/to/template')