def test_runs(self, export_name):
        file = CrowdAnkiExport(export_name)

        assert isinstance(file, CrowdAnkiExport)
        assert file.folder_location == TestFiles.CrowdAnkiExport.TEST1_FOLDER
        assert file.file_location == TestFiles.CrowdAnkiExport.TEST1_JSON
        assert len(file.get_data().keys()) == 13
Пример #2
0
 def from_repr(cls, data: Union[Representation, dict]):
     rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data)
     return cls(
         rep=rep,
         ca_export=CrowdAnkiExport.create_or_get(rep.source),
         part_id=rep.part_id,
         save_to_file=rep.save_to_file
     )
    def test_too_many_json_files(self, tmpdir):
        directory = tmpdir.mkdir("test")
        file1, file2 = directory.join("file1.json"), directory.join(
            "file2.json")
        file1.write("{}")
        file2.write("{}")

        with pytest.raises(FileExistsError):
            file = CrowdAnkiExport(directory.strpath)
Пример #4
0
 def from_repr(cls, data: Union[Representation, dict]):
     rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data)
     return cls(
         rep=rep,
         ca_export=CrowdAnkiExport.create_or_get(rep.source),
         part_id=rep.part_id,
         sort_order=SharedBaseNotes._get_sort_order(rep.sort_order),
         reverse_sort=SharedBaseNotes._get_reverse_sort(rep.reverse_sort),
         save_to_file=rep.save_to_file
     )
Пример #5
0
 def from_repr(cls, data: Union[Representation, dict]):
     rep: cls.Representation = data if isinstance(
         data, cls.Representation) else cls.Representation.from_dict(data)
     return cls(rep=rep,
                crowd_anki_export=CrowdAnkiExport.create_or_get(rep.folder),
                notes_transform=NotesToCrowdAnki.from_repr(rep.notes),
                note_model_transform=NoteModelsToCrowdAnki.from_repr(
                    rep.note_models),
                headers_transform=HeadersToCrowdAnki.from_repr(rep.headers),
                media_transform=MediaGroupToCrowdAnki.from_repr(rep.media)
                if rep.media else None)
Пример #6
0
    def __init__(self, config_data: dict, read_now=True):
        self.setup_config_with_subconfig_replacement(config_data)
        self.verify_config_entry()

        self.file_manager = FileManager.get_instance()

        self.headers = DeckPartHeader.create(self.config_entry[BuildConfigKeys.HEADERS.value], read_now=read_now)
        self.notes = DeckPartNotes.create(self.config_entry[BuildConfigKeys.NOTES.value], read_now=read_now)
        self.crowd_anki_export = CrowdAnkiExport.create(self.config_entry[CrowdAnkiKeys.FILE.value], read_now=read_now)

        self.should_handle_media = self.config_entry[CrowdAnkiKeys.MEDIA.value]
        self.useless_note_keys = self.config_entry[CrowdAnkiKeys.USELESS_NOTE_KEYS.value]
    def from_repr(cls, data: Union[MediaGroupFromFolder.Representation, dict]):
        rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data)

        cae: CrowdAnkiExport = CrowdAnkiExport.create_or_get(rep.source)
        return cls(
            rep=rep,
            part=create_media_group_from_location(
                part_id=rep.part_id,
                save_to_file=rep.save_to_file,
                media_group=MediaGroup.from_directory(cae.media_loc, rep.recursive),
                groups_to_blacklist=list(holder.part for holder in
                                         map(PartHolder.from_file_manager, rep.filter_blacklist_from_parts)),
                groups_to_whitelist=list(holder.part for holder in
                                         map(PartHolder.from_file_manager, rep.filter_whitelist_from_parts))
            )
        )
def temp_ca_export_file(tmpdir) -> CrowdAnkiExport:
    folder = tmpdir.mkdir("ca_export")
    file = folder.join("file.json")
    file.write("{}")

    return CrowdAnkiExport(folder.strpath, read_now=False)
def ca_export_test1() -> CrowdAnkiExport:
    return CrowdAnkiExport.create(TestFiles.CrowdAnkiExport.TEST1_FOLDER)
Пример #10
0
    def test_no_json_file(self, tmpdir):
        directory = tmpdir.mkdir("test")

        with pytest.raises(FileNotFoundError):
            file = CrowdAnkiExport(directory.strpath)