本文整理汇总了Python中xmodule.modulestore.xml.XMLModuleStore.get_instance方法的典型用法代码示例。如果您正苦于以下问题:Python XMLModuleStore.get_instance方法的具体用法?Python XMLModuleStore.get_instance怎么用?Python XMLModuleStore.get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmodule.modulestore.xml.XMLModuleStore
的用法示例。
在下文中一共展示了XMLModuleStore.get_instance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_poll_and_conditional_import
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_poll_and_conditional_import(self):
modulestore = XMLModuleStore(DATA_DIR, course_dirs=["conditional_and_poll"])
course = modulestore.get_courses()[0]
chapters = course.get_children()
ch1 = chapters[0]
sections = ch1.get_children()
self.assertEqual(len(sections), 1)
location = course.location
conditional_location = Location(location.tag, location.org, location.course, "conditional", "condone")
module = modulestore.get_instance(course.id, conditional_location)
self.assertEqual(len(module.children), 1)
poll_location = Location(location.tag, location.org, location.course, "poll_question", "first_poll")
module = modulestore.get_instance(course.id, poll_location)
self.assertEqual(len(module.get_children()), 0)
self.assertEqual(module.voted, False)
self.assertEqual(module.poll_answer, "")
self.assertEqual(module.poll_answers, {})
self.assertEqual(
module.answers,
[{"text": u"Yes", "id": "Yes"}, {"text": u"No", "id": "No"}, {"text": u"Don't know", "id": "Dont_know"}],
)
示例2: test_colon_in_url_name
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_colon_in_url_name(self):
"""Ensure that colons in url_names convert to file paths properly"""
print("Starting import")
# Not using get_courses because we need the modulestore object too afterward
modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy'])
courses = modulestore.get_courses()
self.assertEquals(len(courses), 1)
course = courses[0]
course_id = course.id
print("course errors:")
for (msg, err) in modulestore.get_item_errors(course.location):
print(msg)
print(err)
chapters = course.get_children()
self.assertEquals(len(chapters), 2)
ch2 = chapters[1]
self.assertEquals(ch2.url_name, "secret:magic")
print("Ch2 location: ", ch2.location)
also_ch2 = modulestore.get_instance(course_id, ch2.location)
self.assertEquals(ch2, also_ch2)
print("making sure html loaded")
cloc = course.location
loc = Location(cloc.tag, cloc.org, cloc.course, 'html', 'secret:toylab')
html = modulestore.get_instance(course_id, loc)
self.assertEquals(html.display_name, "Toy lab")
示例3: test_definition_loading
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_definition_loading(self):
"""When two courses share the same org and course name and
both have a module with the same url_name, the definitions shouldn't clash.
TODO (vshnayder): once we have a CMS, this shouldn't
happen--locations should uniquely name definitions. But in
our imperfect XML world, it can (and likely will) happen."""
modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy', 'two_toys'])
toy_id = "edX/toy/2012_Fall"
two_toy_id = "edX/toy/TT_2012_Fall"
location = Location(["i4x", "edX", "toy", "video", "Welcome"])
toy_video = modulestore.get_instance(toy_id, location)
two_toy_video = modulestore.get_instance(two_toy_id, location)
self.assertEqual(etree.fromstring(toy_video.data).get('youtube'), "1.0:p2Q6BrNhdh8")
self.assertEqual(etree.fromstring(two_toy_video.data).get('youtube'), "1.0:p2Q6BrNhdh9")
示例4: test_poll_and_conditional_import
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_poll_and_conditional_import(self):
modulestore = XMLModuleStore(
DATA_DIR, course_dirs=['conditional_and_poll'])
course = modulestore.get_courses()[0]
chapters = course.get_children()
ch1 = chapters[0]
sections = ch1.get_children()
self.assertEqual(len(sections), 1)
location = course.location
conditional_location = Location(
location.tag, location.org, location.course,
'conditional', 'condone'
)
module = modulestore.get_instance(course.id, conditional_location)
self.assertEqual(len(module.children), 1)
poll_location = Location(
location.tag, location.org, location.course,
'poll_question', 'first_poll'
)
module = modulestore.get_instance(course.id, poll_location)
self.assertEqual(len(module.get_children()), 0)
self.assertEqual(module.voted, False)
self.assertEqual(module.poll_answer, '')
self.assertEqual(module.poll_answers, {})
self.assertEqual(
module.answers,
[
{'text': u'Yes', 'id': 'Yes'},
{'text': u'No', 'id': 'No'},
{'text': u"Don't know", 'id': 'Dont_know'}
]
)
示例5: test_graphicslidertool_import
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_graphicslidertool_import(self):
'''
Check to see if definition_from_xml in gst_module.py
works properly. Pulls data from the graphic_slider_tool directory
in the test data directory.
'''
modulestore = XMLModuleStore(DATA_DIR, course_dirs=['graphic_slider_tool'])
sa_id = "edX/gst_test/2012_Fall"
location = Location(["i4x", "edX", "gst_test", "graphical_slider_tool", "sample_gst"])
gst_sample = modulestore.get_instance(sa_id, location)
render_string_from_sample_gst_xml = """
<slider var="a" style="width:400px;float:left;"/>\
<plot style="margin-top:15px;margin-bottom:15px;"/>""".strip()
self.assertEqual(gst_sample.render, render_string_from_sample_gst_xml)
示例6: test_word_cloud_import
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
def test_word_cloud_import(self):
modulestore = XMLModuleStore(DATA_DIR, course_dirs=["word_cloud"])
course = modulestore.get_courses()[0]
chapters = course.get_children()
ch1 = chapters[0]
sections = ch1.get_children()
self.assertEqual(len(sections), 1)
location = course.location
location = Location(location.tag, location.org, location.course, "word_cloud", "cloud1")
module = modulestore.get_instance(course.id, location)
self.assertEqual(len(module.get_children()), 0)
self.assertEqual(module.num_inputs, 5)
self.assertEqual(module.num_top_words, 250)
示例7: DummyModulestore
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
class DummyModulestore(object):
"""
A mixin that allows test classes to have convenience functions to get a module given a location
"""
get_test_system = get_test_system()
def setup_modulestore(self, name):
self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
def get_course(self, name):
"""Get a test course by directory name. If there's more than one, error."""
courses = self.modulestore.get_courses()
return courses[0]
def get_module_from_location(self, location, course):
course = self.get_course(course)
if not isinstance(location, Location):
location = Location(location)
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
return descriptor.xmodule(self.test_system)
示例8: DummyModulestore
# 需要导入模块: from xmodule.modulestore.xml import XMLModuleStore [as 别名]
# 或者: from xmodule.modulestore.xml.XMLModuleStore import get_instance [as 别名]
class DummyModulestore(object):
"""
A mixin that allows test classes to have convenience functions to get a module given a location
"""
def get_module_system(self, descriptor):
raise NotImplementedError("Sub-tests must specify how to generate a module-system")
def setup_modulestore(self, name):
self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
def get_course(self, _):
"""Get a test course by directory name. If there's more than one, error."""
courses = self.modulestore.get_courses()
return courses[0]
def get_module_from_location(self, location, course):
course = self.get_course(course)
if not isinstance(location, Location):
location = Location(location)
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
descriptor.xmodule_runtime = self.get_module_system(descriptor)
return descriptor