Exemplo n.º 1
0
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
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
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")
Exemplo n.º 4
0
 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({})
Exemplo n.º 5
0
def temp_json_file(tmpdir) -> JsonFile:
    file = tmpdir.mkdir("json").join("file.json")
    file.write("{}")

    return JsonFile(file.strpath)
Exemplo n.º 6
0
def ca_nm_data_word_no_defaults():
    return JsonFile.read_file(
        TestFiles.CrowdAnkiNoteModels.LL_WORD_NO_DEFAULTS)
Exemplo n.º 7
0
def ca_nm_data_word_required_only():
    return JsonFile.read_file(
        TestFiles.CrowdAnkiNoteModels.LL_WORD_ONLY_REQUIRED)
Exemplo n.º 8
0
def ca_nm_data_word():
    return JsonFile.read_file(TestFiles.CrowdAnkiNoteModels.LL_WORD)
Exemplo n.º 9
0
 def write_to_files(self, json_data):  # import_config_data
     JsonFile.write_file(self.json_file_location, json_data)
Exemplo n.º 10
0
def debug_write_to_target_json(data, json: JsonFile):
    json.set_data(data)
    json.write_file()