def __init__(self, datadir=None, category=None): Mnemosyne.__init__(self) self.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.components.append(("mnemosyne.maemo_ui.factory", "ConfigHook")) if datadir: datadir = os.path.abspath(datadir) elif os.path.exists(os.path.join(os.getcwdu(), ".mnemosyne")): datadir = os.path.abspath(os.path.join(os.getcwdu(), ".mnemosyne")) else: datadir = os.path.abspath(os.path.join(os.path.expanduser("~"), ".mnemosyne")) self.initialise(datadir) self.review_controller().reset() self.card_type = [ct for ct in self.card_types() \ if ct.name == "Front-to-back only"][0] self.saved = False self.category = category #Category(category)
def setup(self): self.initialise_data_dir() path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_cloze", "Widget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() from mnemosyne.libmnemosyne.card_types.cloze import ClozePlugin for plugin in self.plugins(): if isinstance(plugin, ClozePlugin): plugin.activate() break
def load_mnemosyne(self): self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True) self.mnemosyne.components.insert( 0, (("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator"))) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.web_server.web_server_render_chain", "WebServerRenderChain")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = [\ ("mnemosyne.web_server.review_wdgt", "ReviewWdgt")] self.mnemosyne.initialise(self.data_dir, config_dir=self.config_dir, filename=self.filename, automatic_upgrades=False) self.save_after_n_reps = self.mnemosyne.config()["save_after_n_reps"] self.mnemosyne.config()["save_after_n_reps"] = 1 self.mnemosyne.config()["study_mode"] = "ScheduledForgottenNew" self.mnemosyne.config()["QA_split"] = "fixed" self.mnemosyne.start_review() self.mnemosyne.review_widget().set_client_on_same_machine_as_server(\ self.client_on_same_machine_as_server) self.is_mnemosyne_loaded = True self.release_database_after_timeout = \ ReleaseDatabaseAfterTimeout(self.port) self.release_database_after_timeout.start()
def test_recover_user_id_2(self): assert self.config()["user_id"] is not None MnemosyneTest.teardown(self) open( os.path.join(os.getcwd(), "dot_test", "history", "userid_machine_001.bz2"), "w") os.remove(os.path.join(os.getcwd(), "dot_test", "config.db")) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() assert self.config()["user_id"] == "userid"
class TestSmconvImport(MnemosyneTest): def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator") ) self.mnemosyne.components.append(("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.components.append(("test_smconv_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def sm7_importer(self): for format in self.mnemosyne.component_manager.all("file_format"): if format.__class__.__name__ == "Smconv_XML": return format def test_1(self): global last_error filename = os.path.join(os.getcwd(), "tests", "files", "smconv.xml") self.sm7_importer().do_import(filename) assert last_error is "" assert len([c for c in self.database().cards()]) == 3 def teardown(self): filename = os.path.join(os.getcwd(), "dot_test", "default.db_media", "a.png") if os.path.exists(filename): os.remove(filename) filename = os.path.join(os.getcwd(), "dot_test", "test.txt") if os.path.exists(filename): os.remove(filename) MnemosyneTest.teardown(self)
def restart(self): # If there is another Mnemosyne still running, finalise it so as to # avoid having multiple component_managers active. if hasattr(self, "mnemosyne"): try: self.mnemosyne.finalise() except: pass path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.gui_for_component["CramAll"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def __init__(self): shutil.rmtree(os.path.abspath("dot_sync_server"), ignore_errors=True) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_sync_server"), automatic_upgrades=False) self.mnemosyne.config().change_user_id("user_id") self.mnemosyne.review_controller().reset() self.supports_binary_transfer = lambda x: False # Add 20 cards to database. card_type = self.mnemosyne.card_type_with_id("1") for i in range(20): fact_data = {"f": "question %d" % (i, ), "b": "answer"} self.mnemosyne.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default" ])[0] self.mnemosyne.database().save() self.mnemosyne.database().release_connection()
def load_mnemosyne(self): self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True) self.mnemosyne.components.insert( 0, (("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator"))) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.web_server.review_wdgt", "ReviewWdgt")) self.mnemosyne.components.append(\ ("mnemosyne.web_server.web_server_render_chain", "WebServerRenderChain")) self.mnemosyne.initialise(self.data_dir, config_dir=self.config_dir, filename=self.filename, automatic_upgrades=False) self.mnemosyne.review_controller().set_render_chain("web_server") self.save_after_n_reps = self.mnemosyne.config()["save_after_n_reps"] self.mnemosyne.config()["save_after_n_reps"] = 1 self.mnemosyne.start_review() self.mnemosyne.review_widget().set_is_server_local(\ self.is_server_local) self.is_mnemosyne_loaded = True self.release_database_after_timeout = \ ReleaseDatabaseAfterTimeout(self.port) self.release_database_after_timeout.start()
def __init__(self): shutil.rmtree(os.path.abspath("dot_sync_client"), ignore_errors=True) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) self.mnemosyne.components = [ ("mnemosyne.libmnemosyne.gui_translator", "NoGuiTranslation"), ("mnemosyne.libmnemosyne.databases.SQLite", "SQLite"), ("mnemosyne.libmnemosyne.configuration", "Configuration"), ("mnemosyne.libmnemosyne.loggers.database_logger", "DatabaseLogger"), ("mnemosyne.libmnemosyne.schedulers.SM2_mnemosyne", "SM2Mnemosyne"), ("mnemosyne.libmnemosyne.stopwatch", "Stopwatch"), ("mnemosyne.libmnemosyne.card_types.front_to_back", "FrontToBack"), ("mnemosyne.libmnemosyne.card_types.both_ways", "BothWays"), ("mnemosyne.libmnemosyne.card_types.vocabulary", "Vocabulary"), ("mnemosyne.libmnemosyne.renderers.html_css", "HtmlCss"), ("mnemosyne.libmnemosyne.filters.escape_to_html", "EscapeToHtml"), ("mnemosyne.libmnemosyne.filters.expand_paths", "ExpandPaths"), ("mnemosyne.libmnemosyne.filters.latex", "Latex"), ("mnemosyne.libmnemosyne.render_chains.default_render_chain", "DefaultRenderChain"), ("mnemosyne.libmnemosyne.render_chains.plain_text_chain", "PlainTextChain"), ("mnemosyne.libmnemosyne.controllers.default_controller", "DefaultController"), ("mnemosyne.libmnemosyne.review_controllers.SM2_controller", "SM2Controller"), ("mnemosyne.libmnemosyne.card_types.map", "MapPlugin"), ("mnemosyne.libmnemosyne.card_types.cloze", "ClozePlugin"), ("mnemosyne.libmnemosyne.criteria.default_criterion", "DefaultCriterion"), ("mnemosyne.libmnemosyne.databases.SQLite_criterion_applier", "DefaultCriterionApplier"), ("mnemosyne.libmnemosyne.plugins.cramming_plugin", "CrammingPlugin") ] self.mnemosyne.components.append(("benchmark_sync_client", "Widget")) self.mnemosyne.components.append( ("benchmark_sync_client", "MyReviewWidget")) self.mnemosyne.initialise(os.path.abspath( os.path.join(os.getcwd(), "dot_sync_client")), automatic_upgrades=False) self.mnemosyne.config().change_user_id("user_id") self.check_for_edited_local_media_files = False self.do_backup = False self.mnemosyne.review_controller().reset() # Do 200 reviews. card_type = self.mnemosyne.card_type_with_id("1") fact_data = {"f": "question", "b": "answer"} card = self.mnemosyne.controller().create_new_cards( fact_data, card_type, grade=-1, tag_names=["default"])[0] self.mnemosyne.database().save() self.mnemosyne.review_controller().show_new_question() for i in range(200): self.mnemosyne.review_controller().show_answer() self.mnemosyne.review_controller().grade_answer(0) Client.__init__(self, "client_machine_id", self.mnemosyne.database(), self.mnemosyne.main_widget())
class TestDBImport(MnemosyneTest): def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.components.append(\ ("test_db_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def db_importer(self): for format in self.mnemosyne.component_manager.all("file_format"): if format.__class__.__name__ == "Mnemosyne2Db": return format def test_1(self): print(os.getcwd()) filename = os.path.join(os.getcwd(), "tests", "files", "basedir_to_merge", "config.db") self.db_importer().do_import(filename) assert "configuration database" in last_error def test_2(self): fact_data = {"f": "question", "b": "answer"} card_type = self.card_type_with_id("1") old_card = self.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default"])[0] assert len([self.database().cards()]) == 1 filename = os.path.join(os.getcwd(), "tests", "files", "basedir_to_merge", "to_merge.db") global last_error last_error = "" self.db_importer().do_import(filename) assert last_error == "" db = self.database() assert db.con.execute("select count() from log where event_type != 26" ).fetchone()[0] == 258 self.review_controller().reset() assert self.database().card_count() == 7 assert self.database().active_count() == 6 assert self.database().fact_count() == 5 card_type = self.database().card_type("2::new clone", is_id_internal=False) assert self.config().card_type_property("background_colour", card_type) == 4278233600
class MnemosyneTest(): def setup(self): os.system("rm -fr dot_test") self.restart() def restart(self): self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test")) self.review_controller().reset() def teardown(self): self.mnemosyne.finalise() def config(self): return self.mnemosyne.component_manager.get_current("config") def log(self): return self.mnemosyne.component_manager.get_current("log") def database(self): return self.mnemosyne.component_manager.get_current("database") def scheduler(self): return self.mnemosyne.component_manager.get_current("scheduler") def main_widget(self): return self.mnemosyne.component_manager.get_current("main_widget") def review_widget(self): return self.mnemosyne.component_manager.get_current("review_widget") def controller(self): return self.mnemosyne.component_manager.get_current("controller") def review_controller(self): return self.mnemosyne.component_manager.get_current("review_controller") def card_types(self): return self.mnemosyne.component_manager.get_all("card_type") def filters(self): return self.mnemosyne.component_manager.get_all("filter") def plugins(self): return self.mnemosyne.component_manager.get_all("plugin") def card_type_by_id(self, id): return self.mnemosyne.component_manager.card_type_by_id[id]
class TestMainController(MnemosyneTest): def setup(self): os.system("rm -fr dot_test") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_main_controller", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "AddCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditFactDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "BrowseCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "CardAppearanceDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ActivatePluginsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ManageCardTypesDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "StatisticsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ConfigurationDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ActivateCardsDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test")) self.review_controller().reset() def test_coverage(self): self.controller().heartbeat() self.controller().add_cards() card_type = self.card_type_by_id("2") fact_data = {"q": "q", "a": "a"} card_1, card_2 = self.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default"]) self.review_controller().new_question() self.controller().edit_current_card() self.controller().file_new() self.controller().file_open() self.controller().file_save_as() self.controller().card_appearance() self.controller().activate_plugins() self.controller().manage_card_types() self.controller().browse_cards() self.controller().configure() self.controller().show_statistics() self.controller().activate_cards() def test_2(self): self.controller().file_save_as() self.controller().file_open()
def restart(self): self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False)
def __init__(self, data_dir=None): MnemosyneParent.__init__(self, upload_science_logs=False, interested_in_old_reps=True) self.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.components.append(\ ("mnemosyne.script", "ScriptMainWidget")) self.components.append(\ ("mnemosyne.script", "ScriptReviewWidget")) self.initialise(data_dir)
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.components.append(\ ("test_smconv_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def __init__(self, data_dir=None): MnemosyneParent.__init__(self, upload_science_logs=False, interested_in_old_reps=True) self.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.components.append(\ ("mnemosyne.script", "ScriptMainWidget")) self.components.append(\ ("mnemosyne.script", "ScriptReviewWidget")) self.initialise(data_dir)
def setup(self): self.initialise_data_dir() path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_controller", "Widget")) self.mnemosyne.components.append(\ ("test_controller", "ExportWidget")) self.mnemosyne.components.append(\ ("test_controller", "DataWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "AddCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "BrowseCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "SyncDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ManagePluginsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ManageCardTypesDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "StatisticsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ConfigurationDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ActivateCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ImportDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "TipDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "GettingStartedDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "AboutDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "CompactDatabaseDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def test_setup(): shutil.rmtree("dot_test", ignore_errors=True) global mnemosyne mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) mnemosyne.components.append(\ ("test_add_cards", "Widget")) mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) mnemosyne.review_controller().reset()
class MyClient(Client): program_name = "Mnemosyne" program_version = "test" capabilities = "TODO" def __init__(self): os.system("rm -fr dot_benchmark") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.initialise(os.path.abspath(os.path.join(os.getcwdu(), "dot_benchmark"))) self.mnemosyne.review_controller().reset() Client.__init__(self, "client_machine_id", self.mnemosyne.database(), self.mnemosyne.main_widget()) def do_sync(self): self.sync("127.0.0.1", 8190, "user", "pass") self.mnemosyne.database().save()
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.components.append(\ ("test_mem_import", "Widget")) self.mnemosyne.components.append(\ ("test_mem_import", "MyImportDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
class TestDBImport(MnemosyneTest): def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.components.append(\ ("test_db_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def db_importer(self): for format in self.mnemosyne.component_manager.all("file_format"): if format.__class__.__name__ == "Mnemosyne2Db": return format def test_1(self): filename = os.path.join(os.getcwd(), "tests", "files", "basedir_to_merge", "config.db") self.db_importer().do_import(filename) assert "configuration database" in last_error def test_2(self): fact_data = {"f": "question", "b": "answer"} card_type = self.card_type_with_id("1") old_card = self.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default"])[0] assert len([self.database().cards()]) == 1 filename = os.path.join(os.getcwd(), "tests", "files", "basedir_to_merge", "to_merge.db") global last_error last_error = "" self.db_importer().do_import(filename) assert last_error == "" db = self.database() assert db.con.execute("select count() from log where event_type != 26").fetchone()[0] == 258 self.review_controller().reset() assert self.database().card_count() == 7 assert self.database().active_count() == 6 assert self.database().fact_count() == 5 card_type = self.database().card_type("2::new clone", is_id_internal=False) assert self.config().card_type_property("background_colour", card_type) == 4278233600
def restart(self): path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_media", "Widget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def __init__(self, data_dir=None, filename=None): MnemosyneParent.__init__(self, upload_science_logs=False, interested_in_old_reps=True) self.components.insert(0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.components.append(\ ("mnemosyne.script", "ScriptMainWidget")) self.components.append(\ ("mnemosyne.script", "ScriptReviewWidget")) self.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne.script", "ScriptReviewWidget")] if data_dir is not None: data_dir = os.path.abspath(data_dir) self.initialise(data_dir, filename=filename)
def test_log_upload_bad_server(self): # Most reliable way of setting this variable is throug config.py, otherwise # it will stay alive in a dangling imported userconfig. config_py_file = os.path.join(self.mnemosyne.config().config_dir, "config.py") f = open(config_py_file, "w") print("science_server = \"noserver:80\"", file=f) f.close() machine_id_file = os.path.join(self.mnemosyne.config().config_dir, "machine.id") f = open(machine_id_file, "w") print("TESTMACHINE", file=f) f.close() self.config().change_user_id("UPLOADTEST") self.config()["max_log_size_before_upload"] = 1 MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def test_upgrade(self): os.system("rm -fr dot_test") basedir = os.path.join(os.getcwd(), "tests", "files", "basedir_bz2") shutil.copytree(basedir, "dot_test") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_mem_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test")) assert self.config()["grade_0_cards_in_hand"] == 7 assert "grade_0_items_at_once" not in self.config() assert self.config()["dvipng"].rstrip() == \ "dvipng -D 300 -T tight tmp.dvi\necho" assert "14pt" in self.config()["latex_preamble"] assert os.path.exists(os.path.join("dot_test", "latex", "dvipng.NO_LONGER_USED")) assert not os.path.exists(os.path.join("dot_test", "latex", "dvipng")) self.review_controller().reset()
def setup(self): os.system("rm -fr dot_test") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_main_controller", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "AddCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditFactDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "BrowseCardsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "CardAppearanceDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ActivatePluginsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ManageCardTypesDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "StatisticsDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ConfigurationDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ActivateCardsDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test")) self.review_controller().reset()
def load_mnemosyne(self): self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True) self.mnemosyne.components.insert(0, ( ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator"))) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.web_server.review_wdgt", "ReviewWdgt")) self.mnemosyne.components.append(\ ("mnemosyne.web_server.web_server_render_chain", "WebServerRenderChain")) self.mnemosyne.initialise(self.data_dir, config_dir=self.config_dir, filename=self.filename, automatic_upgrades=False) self.mnemosyne.review_controller().set_render_chain("web_server") self.save_after_n_reps = self.mnemosyne.config()["save_after_n_reps"] self.mnemosyne.config()["save_after_n_reps"] = 1 self.mnemosyne.start_review() self.mnemosyne.review_widget().set_is_server_local(\ self.is_server_local) self.is_mnemosyne_loaded = True self.release_database_after_timeout = \ ReleaseDatabaseAfterTimeout(self.port) self.release_database_after_timeout.start()
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator") ) self.mnemosyne.components.append(("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.components.append(("test_smconv_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def test_log_upload(self): machine_id_file = os.path.join(self.mnemosyne.config().config_dir, "machine.id") f = file(machine_id_file, "w") print >> f, "TESTMACHINE" f.close() self.config().change_user_id("UPLOADTEST") self.config()["max_log_size_before_upload"] = 1 MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def restart(self): self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test")) self.review_controller().reset()
def __init__(self): Thread.__init__(self) self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget"))
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_cramming", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) from mnemosyne.libmnemosyne.plugins.cramming_plugin import CrammingPlugin for plugin in self.plugins(): if isinstance(plugin, CrammingPlugin): plugin.activate() break self.mnemosyne.start_review()
def setup(self): self.initialise_data_dir() path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_cramming", "Widget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.gui_for_component["CramAll"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.config()["study_mode"] = "CramAll" self.mnemosyne.start_review()
def restart(self): self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def setup(self): global expected_scheduled_count expected_scheduled_count = None self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("test_review_controller", "MyReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_mnemosyne2cards", "Widget")) self.mnemosyne.components.append(\ ("test_mnemosyne2cards", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() from mnemosyne.libmnemosyne.card_types.cloze import ClozePlugin for plugin in self.plugins(): if isinstance(plugin, ClozePlugin): plugin.activate() break
def restart(self): # If there is another Mnemosyne still running, finalise it so as to # avoid having multiple component_managers active. if hasattr(self, "mnemosyne"): try: self.mnemosyne.finalise() except: pass self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def setup(self): os.system("rm -fr dot_test") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_add_cards", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test")) self.review_controller().reset()
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.components.append(\ ("test_db_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() self.merge_db_path = os.path.join(os.getcwd(), "tests", "files", "basedir_to_merge", "to_merge.db") self.merge_db_tmppath = os.path.join( os.path.dirname(self.merge_db_path), "to_merge_tmp.db") shutil.copy2(self.merge_db_path, self.merge_db_tmppath)
class TestSM7Import(MnemosyneTest): def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.components.append(\ ("test_supermemo_7_text_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def sm7_importer(self): for format in self.mnemosyne.component_manager.all("file_format"): if format.__class__.__name__ == "SuperMemo7Txt": return format def test_1(self): global last_error filename = os.path.join(os.getcwd(), "tests", "files", "sm7.txt") self.sm7_importer().do_import(filename) assert last_error is "" assert len([c for c in self.database().cards()]) == 4 def teardown(self): filename = \ os.path.join(os.getcwd(), "dot_test", "default.db_media", "a.png") if os.path.exists(filename): os.remove(filename) filename = \ os.path.join(os.getcwd(), "dot_test", "test.txt") if os.path.exists(filename): os.remove(filename) MnemosyneTest.teardown(self)
def test_log_upload_bad_server(self): # Most reliable way of setting this variable is throug config.py, otherwise # it will stay alive in a dangling imported userconfig. config_py_file = os.path.join(self.mnemosyne.config().config_dir, "config.py") f = file(config_py_file, "w") print >> f, "science_server = \"noserver:80\"" f.close() machine_id_file = os.path.join(self.mnemosyne.config().config_dir, "machine.id") f = file(machine_id_file, "w") print >> f, "TESTMACHINE" f.close() self.config().change_user_id("UPLOADTEST") self.config()["max_log_size_before_upload"] = 1 MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def setup(self): global expected_scheduled_count expected_scheduled_count = None self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator") ) self.mnemosyne.components.append(("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(("test_review_controller", "MyReviewWidget")) self.mnemosyne.components.append(("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def setup(self): global expected_scheduled_count expected_scheduled_count = None self.initialise_data_dir() path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("test_review_controller", "MyReviewWidget")] self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset()
def startup(): global mnemosyne # Note that this also includes building the queue and getting the first card. mnemosyne = Mnemosyne(resource_limited=True) mnemosyne.components = [ ("mnemosyne.libmnemosyne.translator", "NoTranslation"), ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget"), ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget"), ("mnemosyne.libmnemosyne.databases.SQLite", "SQLite"), ("mnemosyne.libmnemosyne.configuration", "Configuration"), ("mnemosyne.libmnemosyne.loggers.sql_logger", "SqlLogger"), ("mnemosyne.libmnemosyne.schedulers.SM2_mnemosyne", "SM2Mnemosyne"), ("mnemosyne.libmnemosyne.stopwatch", "Stopwatch"), ("mnemosyne.libmnemosyne.card_types.front_to_back", "FrontToBack"), ("mnemosyne.libmnemosyne.card_types.both_ways", "BothWays"), ("mnemosyne.libmnemosyne.card_types.three_sided", "ThreeSided"), ("mnemosyne.libmnemosyne.renderers.html_css_old", "HtmlCssOld"), ("mnemosyne.libmnemosyne.filters.escape_to_html", "EscapeToHtml"), ("mnemosyne.libmnemosyne.filters.expand_paths", "ExpandPaths"), ("mnemosyne.libmnemosyne.filters.latex", "Latex"), ("mnemosyne.libmnemosyne.controllers.default_controller", "DefaultController"), ("mnemosyne.libmnemosyne.review_controllers.SM2_controller", "SM2Controller"), ("mnemosyne.libmnemosyne.card_types.map", "MapPlugin"), ("mnemosyne.libmnemosyne.card_types.cloze", "ClozePlugin"), ("mnemosyne.libmnemosyne.plugins.cramming_plugin", "CrammingPlugin"), ("mnemosyne.libmnemosyne.file_formats.mnemosyne1_mem", "Mnemosyne1Mem"), ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog") ] mnemosyne.initialise(basedir=os.path.abspath("dot_benchmark")) #mnemosyne.initialise(basedir="\SDMMC\.mnemosyne") mnemosyne.review_controller().reset()
def startup(): global mnemosyne # Note that this also includes building the queue and getting the first card. mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.no_translator", "NoTranslator")) mnemosyne.components.append( ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) mnemosyne.components.append( ("mnemosyne_test", "TestReviewWidget")) mnemosyne.initialise(data_dir=os.path.abspath("dot_benchmark"), automatic_upgrades=False) #mnemosyne.initialise(data_dir="\SDMMC\.mnemosyne", #automatic_upgrades=False) mnemosyne.start_review()
def __init__(self): os.system("rm -fr dot_benchmark") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.initialise(os.path.abspath(os.path.join(os.getcwdu(), "dot_benchmark"))) self.mnemosyne.review_controller().reset() Client.__init__(self, "client_machine_id", self.mnemosyne.database(), self.mnemosyne.main_widget())
def test_log_upload(self): machine_id_file = os.path.join(self.mnemosyne.config().config_dir, "machine.id") f = open(machine_id_file, "w") print("TESTMACHINE", file=f) f.close() self.config().change_user_id("UPLOADTEST") self.config()["max_log_size_before_upload"] = 1 MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review() MnemosyneTest.teardown(self) self.mnemosyne = Mnemosyne(upload_science_logs=True, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def test_setup(): shutil.rmtree("dot_test", ignore_errors=True) global mnemosyne mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) mnemosyne.components.append(\ ("test_add_cards", "Widget")) mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) mnemosyne.review_controller().reset()
def test_recover_user_id_2(self): assert self.config()["user_id"] is not None MnemosyneTest.teardown(self) file(os.path.join(os.getcwd(), "dot_test", "history", "userid_machine_001.bz2"), "w") os.remove(os.path.join(os.getcwd(), "dot_test", "config.db")) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_logging", "MyMainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) assert self.config()["user_id"] == "userid"
def setup(self): os.system("rm -fr dot_test") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_cramming", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test")) from mnemosyne.libmnemosyne.plugins.cramming_plugin import CrammingPlugin for plugin in self.plugins(): if isinstance(plugin, CrammingPlugin): plugin.activate() break self.review_controller().reset()
def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("test_convert_cards", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() from mnemosyne.libmnemosyne.card_types.map import MapPlugin for plugin in self.plugins(): if isinstance(plugin, MapPlugin): plugin.activate() break
def restart(self): # If there is another Mnemosyne still running, finalise it so as to # avoid having multiple component_managers active. if hasattr(self, "mnemosyne"): try: self.mnemosyne.finalise() except: pass self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.mnemosyne.start_review()
def __init__(self): shutil.rmtree(os.path.abspath("dot_sync_server"), ignore_errors=True) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.initialise(os.path.abspath("dot_sync_server"), automatic_upgrades=False) self.mnemosyne.config().change_user_id("user_id") self.mnemosyne.review_controller().reset() self.supports_binary_transfer = lambda x : False # Add 20 cards to database. card_type = self.mnemosyne.card_type_with_id("1") for i in range (20): fact_data = {"f": "question %d" % (i,), "b": "answer"} self.mnemosyne.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default"])[0] self.mnemosyne.database().save() self.mnemosyne.database().release_connection()
def __init__(self): os.system("rm -rf sync_from_here") self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) self.mnemosyne.initialise(os.path.abspath("sync_from_here")) self.mnemosyne.config().change_user_id("user_id") self.mnemosyne.review_controller().reset() # Add 20 cards to database. card_type = self.mnemosyne.card_type_by_id("1") for i in range (20): fact_data = {"q": "question %d" % (i,), "a": "answer"} self.mnemosyne.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["default"])[0] self.mnemosyne.database().save()
class MyServer(Server, Thread): program_name = "Mnemosyne" program_version = "test" capabilities = "TODO" stop_after_sync = True def __init__(self): Thread.__init__(self) self.mnemosyne = Mnemosyne() self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(("test_sync", "Widget")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "ProgressDialog")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget")) def authorise(self, login, password): return login == "user" and password == "pass" def open_database(self, database_name): return self.mnemosyne.database() def run(self): # We only open the database connection inside the thread to prevent # access problems, as a single connection can only be used inside a # single thread. self.mnemosyne.initialise(os.path.abspath("sync_from_here")) self.mnemosyne.review_controller().reset() Server.__init__(self, "server_machine_id", "127.0.0.1", 8190, self.mnemosyne.main_widget()) # Because we stop_after_sync is True, serve_forever will actually stop # after one sync. self.serve_forever() self.mnemosyne.finalise()
def __init__(self, port, upload_science_logs=False, interested_in_old_reps=False): self.mnemosyne = Mnemosyne(upload_science_logs, interested_in_old_reps) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.UDP_server.main_wdgt", "MainWidget")) self.mnemosyne.components.append(\ ("mnemosyne.UDP_server.review_wdgt", "ReviewWdgt")) socketserver.UDPServer.__init__(self, ("localhost", port), MyHandler) print(("Server listening on port", port)) self.stopped = False while not self.stopped: # We time out every 0.25 seconds, so that changing # self.stopped can have an effect. if select.select([self.socket], [], [], 0.25)[0]: self.handle_request() self.socket.close()
def startup(): global mnemosyne # Note that this also includes building the queue and getting the first card. mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.no_gui_translator", "NoGuiTranslator")) mnemosyne.components.append( ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("mnemosyne_test", "TestReviewWidget")] mnemosyne.initialise(data_dir=os.path.abspath("dot_benchmark"), automatic_upgrades=False) #mnemosyne.initialise(data_dir="\SDMMC\.mnemosyne", #automatic_upgrades=False) mnemosyne.start_review()
class TestMnemosyne1XMLImport(MnemosyneTest): def setup(self): self.initialise_data_dir() self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translators.gettext_translator", "GetTextTranslator")) self.mnemosyne.components.append(\ ("mnemosyne_test", "TestReviewWidget")) self.mnemosyne.components.append(\ ("test_mnemosyne1xml_import", "Widget")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def xml_importer(self): for format in self.mnemosyne.component_manager.all("file_format"): if format.__class__.__name__ == "Mnemosyne1XML": return format def test_file_not_found(self): filename = os.path.join(os.getcwd(), "tests", "files", "nothere.xml") self.xml_importer().do_import(filename) assert last_error.startswith("Unable to open") def test_wrong_format(self): filename = os.path.join(os.getcwd(), "tests", "files", "wrong_format.xml") self.xml_importer().do_import(filename) assert last_error.startswith("Unable to parse") def test_bad_version(self): filename = os.path.join(os.getcwd(), "tests", "files", "bad_version.xml") self.xml_importer().do_import(filename) assert last_error.startswith("XML file does not seem") def test_card_type_1(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "1sided.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 4 card = self.review_controller().card assert card.grade == 2 assert card.easiness == 2.5 assert card.acq_reps == 1 assert card.ret_reps == 0 assert card.lapses == 0 assert card.acq_reps_since_lapse == 1 assert card.ret_reps_since_lapse == 0 assert [tag.name for tag in card.tags] == ["__UNTAGGED__"] assert card.last_rep == 1247529600 assert card.next_rep == 1247616000 assert card.id == "9cff728f" def test_card_type_1_abort(self): global answer answer = 1 filename = os.path.join(os.getcwd(), "tests", "files", "1sided.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 0 def test_card_type_1_unseen(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "1sided_unseen.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 1 card = self.review_controller().card assert card.grade == -1 assert card.easiness == 2.5 assert card.acq_reps == 0 assert card.ret_reps == 0 assert card.lapses == 0 assert card.acq_reps_since_lapse == 0 assert card.ret_reps_since_lapse == 0 assert card.last_rep == -1 assert card.next_rep == -1 assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_CARD, )).fetchone()[0] == 1 def test_card_type_1_edited(self): filename = os.path.join(os.getcwd(), "tests", "files", "1sided.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 4 card = self.review_controller().card assert card.id == "9cff728f" assert "question" in card.question() filename = os.path.join(os.getcwd(), "tests", "files", "1sided.xml") self.xml_importer().do_import(filename) assert last_error.startswith("These cards seem to have been imported before") def test_card_type_2(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "2sided.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 2 card_1 = self.review_controller().card assert "question" in card_1.question() assert "answer" in card_1.answer() cards = self.database().cards_from_fact(card_1.fact) if cards[0] == card_1: card_2 = cards[1] else: card_2 = cards[0] assert "question" in card_2.answer() assert "answer" in card_2.question() assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_CARD, )).fetchone()[0] == 2 def test_card_type_3(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "3sided.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 2 card_1 = self.review_controller().card assert card_1.fact.data == {"f": "f", "p_1": "p", "m_1": "t"} assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_CARD, )).fetchone()[0] == 2 def test_card_type_3_corrupt(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "3sided_corrupt.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 2 card_1 = self.review_controller().card assert card_1.fact.data == {"f": "f", "m_1": "t"} assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_CARD, )).fetchone()[0] == 2 def test_card_type_3_missing(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "3sided_missing.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 1 card_1 = self.review_controller().card assert card_1.fact.data == {"f": "t", "b": "f\np"} assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_CARD, )).fetchone()[0] == 1 def test_media(self): global answer answer = 0 os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs")) os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs", "figs")) figures = [\ os.path.join(os.getcwd(), "tests", "files", "a.png"), os.path.join(os.getcwd(), "tests", "files", "figs", "a.png"), os.path.join(os.getcwd(), "tests", "files", "figs", "figs", "a.png")] for filename in figures: file(filename, "w") filename = os.path.join(os.getcwd(), "tests", "files", "media.xml") self.xml_importer().do_import(filename) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "a.png")) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_MEDIA_FILE, )).fetchone()[0] == 3 def test_media_missing(self): global answer answer = 0 os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs")) os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs", "figs")) figures = [\ os.path.join(os.getcwd(), "tests", "files", "a.png"), os.path.join(os.getcwd(), "tests", "files", "figs", "a.png")] for filename in figures: file(filename, "w") filename = os.path.join(os.getcwd(), "tests", "files", "media.xml") self.xml_importer().do_import(filename) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "a.png")) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_MEDIA_FILE, )).fetchone()[0] == 2 def test_media_missing_2(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "media.xml") self.xml_importer().do_import(filename) assert not os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "a.png")) assert not os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_MEDIA_FILE, )).fetchone()[0] == 0 def test_media_slashes(self): global answer answer = 0 os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs")) os.mkdir(os.path.join(os.getcwd(), "tests", "files", "figs", "figs")) figures = [\ os.path.join(os.getcwd(), "tests", "files", "a.png"), os.path.join(os.getcwd(), "tests", "files", "figs", "a.png"), os.path.join(os.getcwd(), "tests", "files", "figs", "figs", "a.png")] for filename in figures: file(filename, "w") filename = os.path.join(os.getcwd(), "tests", "files", "media_slashes.xml") self.xml_importer().do_import(filename) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "a.png")) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "figs", "a.png")) assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_MEDIA_FILE, )).fetchone()[0] == 3 def test_sound(self): global answer answer = 0 os.mkdir(os.path.join(\ os.getcwd(), "tests", "files", "soundfiles")) soundname = os.path.join(os.path.join(\ os.getcwd(), "tests", "files", "soundfiles", "a.ogg")) file(soundname, "w") filename = os.path.join(os.getcwd(), "tests", "files", "sound.xml") self.xml_importer().do_import(filename) assert os.path.exists(os.path.join(\ os.path.abspath("dot_test"), "default.db_media", "soundfiles", "a.ogg")) assert self.database().con.execute(\ "select count() from log where event_type=?", (EventTypes.ADDED_MEDIA_FILE, )).fetchone()[0] == 1 self.review_controller().reset() card = self.review_controller().card assert card.fact["f"] == """<audio src="soundfiles/a.ogg">""" def test_map(self): filename = os.path.join(os.getcwd(), "tests", "files", "map.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.database().card_count() == 2 card = self.review_controller().card assert card.fact["loc"] == "<b>Drenthe</b>" assert card.fact["marked"] == \ """<img src_missing="maps/Netherlands-Provinces/Drenthe.png">""" assert card.fact["blank"] == \ """<img src_missing="maps/Netherlands-Provinces/Netherlands-Provinces.png">""" def test_dups(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "dups.xml") self.xml_importer().do_import(filename) self.review_controller().reset() assert self.review_controller().card.fact["loc"] == \ u"""<b>Freistaat Th\xfcringen (Free State of Thuringia)</b>""" assert self.review_controller().card.tag_string() == "Germany: States, MISSING_MEDIA" def test_anon_id(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "anon_id.xml") self.xml_importer().do_import(filename) self.review_controller().reset() fact = self.review_controller().card.fact for card in self.database().cards_from_fact(fact): assert not card.id.startswith("_") assert self.database().card_count() == 2 def test_anon_id_2(self): global answer, last_error answer = 0 last_error = None filename = os.path.join(os.getcwd(), "tests", "files", "anon_id.xml") self.xml_importer().do_import(filename) assert last_error == None self.xml_importer().do_import(filename) assert last_error == None self.review_controller().reset() fact = self.review_controller().card.fact for card in self.database().cards_from_fact(fact): assert not card.id.startswith("_") assert self.database().card_count() == 4 def test_no_id(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "no_id.xml") self.xml_importer().do_import(filename) self.review_controller().reset() fact = self.review_controller().card.fact for card in self.database().cards_from_fact(fact): assert card.id def test_bad_xml(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "bad_xml.xml") self.xml_importer().do_import(filename) assert last_error.startswith("Unable to parse") def test_tags(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "tag.xml") self.xml_importer().do_import(filename, extra_tag_names="extra") self.review_controller().reset() assert len(self.review_controller().card.tags) == 2 def test_log(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "sound.xml") self.xml_importer().do_import(filename) ids = [cursor[0] for cursor in self.database().con.execute(\ "select distinct object_id from log where event_type='6' or event_type='7'")] assert ids == ['ef2e21e1'] def teardown(self): global answer answer = 0 filename = os.path.join(os.getcwd(), "tests", "files", "basedir_bz2", "DIRECTORY_NO_LONGER_USED_BY_MNEMOSYNE2") if os.path.exists(filename): os.remove(filename) filename = os.path.join(os.getcwd(), "tests", "files", "a.png") if os.path.exists(filename): os.remove(filename) filename = os.path.join(os.getcwd(), "tests", "files", "a.ogg") if os.path.exists(filename): os.remove(filename) dirname = os.path.join(os.getcwd(), "tests", "files", "figs") if os.path.exists(dirname): shutil.rmtree(dirname) dirname = os.path.join(os.getcwd(), "tests", "files", "soundfiles") if os.path.exists(dirname): shutil.rmtree(dirname) MnemosyneTest.teardown(self)
# # mnemosyne_android.py <*****@*****.**> # import os # Workaround for this bug: # https://github.com/pyinstaller/pyinstaller/issues/1113 import encodings.idna # Initialise Mnemosyne. from mnemosyne.libmnemosyne import Mnemosyne mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True) mnemosyne.components = [\ ("mnemosyne.libmnemosyne.translators.no_translator", "NoTranslator"), ("mnemosyne.libmnemosyne.databases.SQLite", "SQLite"), ("mnemosyne.cle.database_maintenance", "AndroidDatabaseMaintenance"), ("mnemosyne.libmnemosyne.configuration", "Configuration"), ("mnemosyne.libmnemosyne.loggers.database_logger", "DatabaseLogger"), ("mnemosyne.libmnemosyne.schedulers.SM2_mnemosyne", "SM2Mnemosyne"), ("mnemosyne.libmnemosyne.stopwatch", "Stopwatch"), ("mnemosyne.libmnemosyne.card_types.front_to_back", "FrontToBack"),
class TestReviewController(MnemosyneTest): def setup(self): global expected_scheduled_count expected_scheduled_count = None self.initialise_data_dir() path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne", "renderers") if path not in sys.path: sys.path.append(path) self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True, asynchronous_database=True) self.mnemosyne.components.insert( 0, ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator")) self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.main_widget", "MainWidget")) self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \ [("test_review_controller", "MyReviewWidget")] self.mnemosyne.components.append(\ ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog")) self.mnemosyne.initialise(os.path.abspath("dot_test"), automatic_upgrades=False) self.review_controller().reset() def test_1(self): card_1 = None self.review_controller().reset() for i in range(10): fact_data = {"f": "question" + str(i), "b": "answer" + str(i)} if i % 2: card_type = self.card_type_with_id("1") else: card_type = self.card_type_with_id("2") card = self.controller().create_new_cards(fact_data, card_type, grade=4, tag_names=[ "default" + str(i) ])[0] if i == 0: card_1 = card card.next_rep -= 1000 * 24 * 60 * 60 self.database().update_card(card) self.review_controller().set_render_chain("default") self.review_controller().show_new_question() self.review_controller().reset_but_try_to_keep_current_card() self.review_controller().show_answer() assert self.review_controller().card == card_1 assert self.review_controller().counters() == (1, 0, 15) self.review_controller().grade_answer(0) assert self.review_controller().counters() == (0, 1, 15) self.review_controller().grade_answer(2) assert self.review_controller().counters() == (0, 0, 15) self.review_controller().next_rep_string(0) self.review_controller().next_rep_string(1) self.review_controller().next_rep_string(2) def test_2(self): card_1 = None self.review_controller().reset() for i in range(10): fact_data = {"f": "question" + str(i), "b": "answer" + str(i)} if i % 2: card_type = self.card_type_with_id("1") else: card_type = self.card_type_with_id("2") card = self.controller().create_new_cards(fact_data, card_type, grade=4, tag_names=[ "default" + str(i) ])[0] if i == 0: card_1 = card card.next_rep -= 1000 * 24 * 60 * 60 self.database().update_card(card) self.review_controller().show_new_question() assert self.review_controller().card == card_1 self.review_controller().reload_counters() assert self.review_controller().counters() == (1, 0, 15) self.review_controller().grade_answer(0) self.review_controller().reload_counters() assert self.review_controller().counters() == (0, 1, 15) self.review_controller().grade_answer(2) self.review_controller().reload_counters() assert self.review_controller().counters() == (0, 0, 15) self.mnemosyne.review_widget().set_grade_enabled(1, True) def test_reset_but_try_to_keep_current_card_turned_inactive(self): card_type = self.card_type_with_id("1") fact_data = {"f": "1", "b": "b"} card = self.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=["forbidden"])[0] self.review_controller().show_new_question() assert self.review_controller().card == card c = DefaultCriterion(self.mnemosyne.component_manager) c.deactivated_card_type_fact_view_ids = set() c._tag_ids_active = set( [self.database().get_or_create_tag_with_name("active")._id]) c._tag_ids_forbidden = set( [self.database().get_or_create_tag_with_name("forbidden")._id]) self.database().set_current_criterion(c) assert self.database().active_count() == 0 assert self.review_controller().card == card self.review_controller().reset_but_try_to_keep_current_card() assert self.review_controller().card is None def test_last_card(self): card_type = self.card_type_with_id("1") for data in ["1", "2", "3"]: fact_data = {"f": data, "b": data} self.controller().create_new_cards(fact_data, card_type, grade=-1, tag_names=[]) self.review_controller().show_new_question() self.review_controller().show_answer() for i in range(5): self.review_controller().grade_answer(0) self.review_controller().show_answer() for i in range(2): self.review_controller().grade_answer(2) self.review_controller().show_answer() for i in range(6): self.review_controller().grade_answer(0) self.review_controller().show_answer() def test_counters(self): global expected_scheduled_count card_type = self.card_type_with_id("1") fact_data = {"f": '1', "b": '1'} card = self.controller().create_new_cards(fact_data, card_type, grade=5, tag_names=[])[0] card.next_rep = 0 self.database().update_card(card) expected_scheduled_count = 1 self.review_controller().show_new_question() assert self.review_controller().scheduled_count == 1 assert self.review_controller().counters()[0] == 1 self.review_controller().show_answer() expected_scheduled_count = 0 self.review_controller().grade_answer(0) assert self.review_controller().scheduled_count == 0 assert self.review_controller().counters()[0] == 0 def test_counters_prefetch(self): global expected_scheduled_count card_type = self.card_type_with_id("1") for data in ['1', '2', '3', '4']: fact_data = {"f": data, "b": data} card = self.controller().create_new_cards(fact_data, card_type, grade=5, tag_names=[])[0] card.next_rep = 0 self.database().update_card(card) expected_scheduled_count = 4 self.review_controller().show_new_question() assert self.review_controller().scheduled_count == 4 assert self.review_controller().counters()[0] == 4 self.review_controller().show_answer() expected_scheduled_count = 3 self.review_controller().grade_answer(3) assert self.review_controller().scheduled_count == 3 assert self.review_controller().counters()[0] == 3