本文整理汇总了Python中mnemosyne.libmnemosyne.Mnemosyne.initialise方法的典型用法代码示例。如果您正苦于以下问题:Python Mnemosyne.initialise方法的具体用法?Python Mnemosyne.initialise怎么用?Python Mnemosyne.initialise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnemosyne.libmnemosyne.Mnemosyne
的用法示例。
在下文中一共展示了Mnemosyne.initialise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyClient
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例2: TestSmconvImport
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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)
示例3: MnemosyneTest
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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]
示例4: startup
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例5: TestMainController
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例6: TestDBImport
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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
示例7: test_setup
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例8: MyServer
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
class MyServer(Server):
program_name = "Mnemosyne"
program_version = "test"
capabilities = "TODO"
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 authorise(self, login, password):
return login == "user" and password == "pass"
def load_database(self, database_name):
self.mnemosyne.database().load(database_name)
return self.mnemosyne.database()
def unload_database(self, database):
self.mnemosyne.database().release_connection()
# Dirty way to make sure we restart the server and create a new database
# (as opposed to keep sending old history back and forth)'
self.wsgi_server.stop()
def run(self):
Server.__init__(self, "client_machine_id", 8186,
self.mnemosyne.main_widget())
self.serve_until_stopped()
示例9: MyServer
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
class MyServer(Server):
program_name = "Mnemosyne"
program_version = "test"
capabilities = "TODO"
stop_after_sync = True
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()
def authorise(self, login, password):
return login == "user" and password == "pass"
def open_database(self, database_name):
return self.mnemosyne.database()
def run(self):
Server.__init__(self, "client_machine_id", "192.168.2.54", 8186,
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()
示例10: MyServer
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例11: startup
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
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()
示例12:
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
"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.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") ]
# Run Mnemosyne.
mnemosyne.initialise(data_dir=data_dir)
mnemosyne.start_review()
app.mainframe = mnemosyne.main_widget()
app.run()
mnemosyne.finalise()
示例13: TestMedia
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
class TestMedia(MnemosyneTest):
def restart(self):
self.mnemosyne = Mnemosyne()
self.mnemosyne.components.insert(0, ("mnemosyne.libmnemosyne.translator",
"GetTextTranslator"))
self.mnemosyne.components.append(\
("test_media", "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 test_sound_1(self):
global filename
filename = ""
self.controller().insert_sound("")
def test_sound_2(self):
global filename
file("a.ogg", "w")
filename = os.path.abspath("a.ogg")
self.controller().insert_sound("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a.ogg"))
filename = os.path.join(self.config().mediadir(), "a.ogg")
self.controller().insert_sound("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a.ogg"))
def test_sound_3(self):
global filename
file("a.ogg", "w")
filename = os.path.abspath("a.ogg")
self.controller().insert_sound("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a.ogg"))
self.controller().insert_sound("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a_1_.ogg"))
self.controller().insert_sound("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a_2_.ogg"))
def test_img_1(self):
global filename
filename = ""
self.controller().insert_img("")
def test_img_2(self):
global filename
file("a.ogg", "w")
filename = os.path.abspath("a.ogg")
self.controller().insert_img("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a.ogg"))
filename = os.path.join(self.config().mediadir(), "a.ogg")
self.controller().insert_img("")
assert os.path.exists(os.path.join(self.config().mediadir(), "a.ogg"))
def test_media_subdir(self):
global filename
subdir = os.path.join(self.config().mediadir(), "subdir")
os.mkdir(subdir)
filename = os.path.join(subdir, "b.ogg")
os.system("touch %s" % filename)
self.controller().insert_img("")
assert os.path.exists(os.path.join(self.config().mediadir(),
"subdir", "b.ogg"))
def test_card(self):
file("a.ogg", "w")
full_path = os.path.abspath("a.ogg")
fact_data = {"q": "<img src=\"%s\">" % full_path,
"a": "answer"}
card_type = self.card_type_by_id("1")
card = self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])[0]
full_path_in_media_dir = os.path.join(self.config().mediadir(), "a.ogg")
assert os.path.exists(full_path_in_media_dir)
assert full_path not in card.fact.data["q"]
assert full_path_in_media_dir not in card.fact.data["q"]
assert full_path not in card.question()
assert full_path_in_media_dir in card.question()
assert self.database().con.execute(\
"select count() from log where event=?",
(self.database().ADDED_MEDIA, )).fetchone()[0] == 1
def test_card_2(self):
fact_data = {"q": "<img src=\"a.ogg>", # Missing closing "
"a": "answer"}
card_type = self.card_type_by_id("1")
card = self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])[0]
#.........这里部分代码省略.........
示例14: TestPlugin
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
class TestPlugin(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_plugin", "Widget"))
self.mnemosyne.components.append(\
("mnemosyne.libmnemosyne.ui_components.review_widget", "ReviewWidget"))
self.mnemosyne.initialise(os.path.abspath("dot_test"))
self.review_controller().reset()
@raises(AssertionError)
def test_1(self):
from mnemosyne.libmnemosyne.plugin import Plugin
p = Plugin(self.mnemosyne.component_manager)
@raises(NotImplementedError)
def test_2(self):
from mnemosyne.libmnemosyne.card_types.front_to_back import FrontToBack
from mnemosyne.libmnemosyne.plugin import Plugin
class MyCardType(FrontToBack):
id = "666"
class MyPlugin(Plugin):
name = "myplugin"
description = "MyPlugin"
components = [MyCardType]
p = MyPlugin(self.mnemosyne.component_manager)
old_length = len(self.card_types())
p.activate()
assert len(self.card_types()) == old_length + 1
p.deactivate()
assert len(self.card_types()) == old_length
p.activate()
fact_data = {"q": "question",
"a": "answer"}
card_type = self.card_type_by_id("666")
self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])
p.deactivate() # Pops up an information box that this is not possible.
def test_3(self):
from mnemosyne.libmnemosyne.card_types.front_to_back import FrontToBack
from mnemosyne.libmnemosyne.plugin import Plugin
class MyCardType(FrontToBack):
id = "666"
class MyPlugin(Plugin):
name = "myplugin"
description = "MyPlugin"
components = [MyCardType]
p = MyPlugin(self.mnemosyne.component_manager)
old_length = len(self.card_types())
p.activate()
assert len(self.card_types()) == old_length + 1
p.deactivate()
assert len(self.card_types()) == old_length
p.activate()
fact_data = {"q": "question",
"a": "answer"}
card_type = self.card_type_by_id("666")
card = self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])[0]
fact = card.fact
self.database().delete_fact_and_related_data(fact)
p.deactivate() # Should work without problems.
def test_4(self):
from mnemosyne.libmnemosyne.plugin import Plugin
from mnemosyne.libmnemosyne.card_types.front_to_back import FrontToBack
from mnemosyne.pyqt_ui.generic_card_type_widget import GenericCardTypeWdgt
class RedGenericCardTypeWdgt(GenericCardTypeWdgt):
used_for = FrontToBack
def __init__(self, parent, component_manager):
GenericCardTypeWdgt.__init__(self, FrontToBack,
parent, component_manager)
class RedPlugin(Plugin):
name = "Red"
#.........这里部分代码省略.........
示例15: TestLogging
# 需要导入模块: from mnemosyne.libmnemosyne import Mnemosyne [as 别名]
# 或者: from mnemosyne.libmnemosyne.Mnemosyne import initialise [as 别名]
class TestLogging(MnemosyneTest):
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 test_logging(self):
card_type = self.card_type_by_id("1")
fact_data = {"q": "1", "a": "a"}
card = self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])[0]
self.review_controller().new_question()
self.review_controller().grade_answer(0)
self.review_controller().new_question()
self.review_controller().grade_answer(1)
self.review_controller().grade_answer(4)
self.mnemosyne.finalise()
self.restart()
fact_data = {"q": "2", "a": "a"}
card = self.controller().create_new_cards(fact_data, card_type,
grade=-1, tag_names=["default"])[0]
self.review_controller().new_question()
self.controller().delete_current_fact()
self.log().dump_to_science_log()
sql_res = self.database().con.execute(\
"select * from log where _id=1").fetchone()
assert sql_res["event_type"] == EventTypes.STARTED_PROGRAM
sql_res = self.database().con.execute(\
"select * from log where _id=2").fetchone()
assert sql_res["event_type"] == EventTypes.STARTED_SCHEDULER
sql_res = self.database().con.execute(\
"select * from log where _id=3").fetchone()
assert sql_res["event_type"] == EventTypes.LOADED_DATABASE
assert sql_res["acq_reps"] == 0
assert sql_res["ret_reps"] == 0
assert sql_res["lapses"] == 0
sql_res = self.database().con.execute(\
"select * from log where _id=4").fetchone()
assert sql_res["event_type"] == EventTypes.ADDED_FACT
assert sql_res["object_id"] is not None
sql_res = self.database().con.execute(\
"select * from log where _id=5").fetchone()
assert sql_res["event_type"] == EventTypes.ADDED_TAG
assert sql_res["object_id"] is not None
sql_res = self.database().con.execute(\
"select * from log where _id=6").fetchone()
assert sql_res["event_type"] == EventTypes.ADDED_CARD
assert sql_res["object_id"] is not None
sql_res = self.database().con.execute(\
"select * from log where _id=7").fetchone()
assert sql_res["event_type"] == EventTypes.REPETITION
assert sql_res["acq_reps"] == 1
assert sql_res["ret_reps"] == 0
assert sql_res["scheduled_interval"] == 0
assert sql_res["actual_interval"] == 0
assert sql_res["new_interval"] == 0
assert sql_res["thinking_time"] == 0
assert sql_res["object_id"] is not None
sql_res = self.database().con.execute(\
"select * from log where _id=8").fetchone()
assert sql_res["event_type"] == EventTypes.REPETITION
assert sql_res["acq_reps"] == 2
assert sql_res["ret_reps"] == 0
assert sql_res["scheduled_interval"] == 0
assert sql_res["actual_interval"] == 0
assert sql_res["new_interval"] == 0
assert sql_res["thinking_time"] == 0
sql_res = self.database().con.execute(\
"select * from log where _id=9").fetchone()
assert sql_res["event_type"] == EventTypes.REPETITION
assert sql_res["acq_reps"] == 3
assert sql_res["ret_reps"] == 0
assert sql_res["scheduled_interval"] == 0
assert sql_res["actual_interval"] <= 10 # Depends on CPU load.
assert sql_res["new_interval"] > 0
assert sql_res["thinking_time"] == 0
sql_res = self.database().con.execute(\
"select * from log where _id=10").fetchone()
assert sql_res["event_type"] == EventTypes.SAVED_DATABASE
assert sql_res["acq_reps"] == 0
assert sql_res["ret_reps"] == 0
#.........这里部分代码省略.........