def test_constructor(): file_location = TestFiles.CrowdAnkiExport.TEST1_JSON file = JsonFile(file_location) assert isinstance(file, JsonFile) assert file.file_location == file_location assert len(file.get_data().keys()) == 13
def test_to_filename_json(): expected = "read-this-file.json" assert expected == JsonFile.to_filename_json("read this file") assert expected == JsonFile.to_filename_json("read-this-file") assert expected == JsonFile.to_filename_json("read-this-file.json") assert expected == JsonFile.to_filename_json( "read this file")
def test_configure_file_location(): expected = "folder/read-this-file.json" assert expected == JsonFile.get_json_file_location("folder/", "read this file") assert expected == JsonFile.get_json_file_location("folder/", "read-this-file.json") assert expected == JsonFile.get_json_file_location( "", "folder/read this file") assert expected == JsonFile.get_json_file_location( "", "folder/read-this-file.json")
def _read_json_file(self): if SourceFile.is_file(self.json_file_location): self.json_data = CrowdAnkiJsonWrapper( JsonFile.read_file(self.json_file_location)) self.note_models = list( map(NoteModel.from_crowdanki, self.json_data.note_models)) else: self.write_to_files({}) self.json_data = CrowdAnkiJsonWrapper({})
def temp_json_file(tmpdir) -> JsonFile: file = tmpdir.mkdir("json").join("file.json") file.write("{}") return JsonFile(file.strpath)
def ca_nm_data_word_no_defaults(): return JsonFile.read_file( TestFiles.CrowdAnkiNoteModels.LL_WORD_NO_DEFAULTS)
def ca_nm_data_word_required_only(): return JsonFile.read_file( TestFiles.CrowdAnkiNoteModels.LL_WORD_ONLY_REQUIRED)
def ca_nm_data_word(): return JsonFile.read_file(TestFiles.CrowdAnkiNoteModels.LL_WORD)
def write_to_files(self, json_data): # import_config_data JsonFile.write_file(self.json_file_location, json_data)
def debug_write_to_target_json(data, json: JsonFile): json.set_data(data) json.write_file()