当前位置: 首页>>代码示例>>Python>>正文


Python Interpreter._detect_event_class_and_id方法代码示例

本文整理汇总了Python中interpreter.Interpreter._detect_event_class_and_id方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter._detect_event_class_and_id方法的具体用法?Python Interpreter._detect_event_class_and_id怎么用?Python Interpreter._detect_event_class_and_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter._detect_event_class_and_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InterpreterTest

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import _detect_event_class_and_id [as 别名]
class InterpreterTest(unittest.TestCase):

    calendar_path = '../data/multi-fr.ics'
    moodle_archive_path = '\
../data/backup-moodle2-course-1677-s20143-log792-09-20151102-1202-nu.mbz'

    def setUp(self):
        # Setup calendar
        calendar = CalendarReader(self.calendar_path)

        self.calendar_meetings = calendar.get_all_meetings()

        # Setup Moodle course
        self.tmp_path = tempfile.mkdtemp()
        with tarfile.open(self.moodle_archive_path) as tar_file:
            tar_file.extractall(self.tmp_path)

        self.course = MoodleCourse(self.tmp_path)
        self.interpreter = Interpreter(self.calendar_meetings, self.course)

    def tearDown(self):
        # TODO test on windows
        shutil.rmtree(self.tmp_path)

    def test_split_events_line(self):
        self.assertEqual(['Q1', 'S1F', 'S2S'],
                         self.interpreter._split_line('Q1 S1F S2S'))

    def test_detection_of_event(self):
        event = self.interpreter._detect_event_class_and_id('MQ1')
        self.assertEqual((MoodleQuiz, 1), event)

        event = self.interpreter._detect_event_class_and_id('Mq13')
        self.assertEqual((MoodleQuiz, 13), event)

        event = self.interpreter._detect_event_class_and_id('p2')
        self.assertEqual((Practicum, 2), event)

        event = self.interpreter._detect_event_class_and_id('P12')
        self.assertEqual((Practicum, 12), event)

        event = self.interpreter._detect_event_class_and_id('s4')
        self.assertEqual((Seminar, 4), event)

        event = self.interpreter._detect_event_class_and_id('S4')
        self.assertEqual((Seminar, 4), event)

        event = self.interpreter._detect_event_class_and_id('E1')
        self.assertEqual('Exam', event[0].name)

        event = self.interpreter._detect_event_class_and_id('Q1')
        self.assertEqual('Quiz', event[0].name)

    def test_get_at_end_modifier(self):
        # Implicit start
        mods = self.interpreter._get_modifiers_as_string('S1')
        relative_modifier = mods[0]
        self.assertEqual(False, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string('S1F')
        relative_modifier = mods[0]
        self.assertEqual(True, relative_modifier)

        # Explicit finish lowercase
        mods = self.interpreter._get_modifiers_as_string('S1f')
        relative_modifier = mods[0]
        self.assertEqual(True, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string('[email protected]:59')
        relative_modifier = mods[0]
        self.assertEqual(True, relative_modifier)

        # Implicit start
        mods = self.interpreter._get_modifiers_as_string('S1-1d')
        relative_modifier = mods[0]
        self.assertEqual(False, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string('[email protected]:59')
        at_end = mods[0]
        self.assertEqual(True, at_end)

        # Explicit start
        mods = self.interpreter._get_modifiers_as_string('[email protected]:59')
        at_end = mods[0]
        self.assertEqual(False, at_end)

        # Implicit start
        mods = self.interpreter._get_modifiers_as_string('[email protected]:59')
        at_end = mods[0]
        self.assertEqual(False, at_end)

    def test_parse_invalid_modifiers(self):
        self.assertRaises(InvalidModifiersException,
                          self.interpreter._get_modifiers_as_string,
                          '[email protected]:59')
        self.assertRaises(InvalidModifiersException,
                          self.interpreter._get_modifiers_as_string,
#.........这里部分代码省略.........
开发者ID:jdupl,项目名称:course-activity-planner,代码行数:103,代码来源:interpreter_test.py

示例2: InterpreterTest

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import _detect_event_class_and_id [as 别名]
class InterpreterTest(unittest.TestCase):

    calendar_path = "../data/multi-fr.ics"
    moodle_archive_path = "\
../data/backup-moodle2-course-1677-s20143-log792-09-20151102-1202-nu.mbz"

    def setUp(self):
        # Setup calendar
        calendar = CalendarReader(self.calendar_path)

        self.calendar_meetings = calendar.get_all_meetings()

        # Setup Moodle course
        self.tmp_path = tempfile.mkdtemp()
        with tarfile.open(self.moodle_archive_path) as tar_file:
            tar_file.extractall(self.tmp_path)

        self.course = MoodleCourse(self.tmp_path)
        self.interpreter = Interpreter(self.calendar_meetings, self.course)

    def tearDown(self):
        # TODO test on windows
        shutil.rmtree(self.tmp_path)

    def test_invalid_syntax(self):
        self.assertRaises(InvalidSyntaxException, self.interpreter._split_line, "Q1S1FS2S")

    def test_split_events_line(self):
        self.assertEqual(["Q1", "S1F", "S2S"], self.interpreter._split_line("Q1 S1F S2S"))

    def test_detection_of_event(self):
        event = self.interpreter._detect_event_class_and_id("Q1")
        self.assertEqual((MoodleQuiz, 1), event)

        event = self.interpreter._detect_event_class_and_id("q13")
        self.assertEqual((MoodleQuiz, 13), event)

        event = self.interpreter._detect_event_class_and_id("p2")
        self.assertEqual((Practica, 2), event)

        event = self.interpreter._detect_event_class_and_id("P12")
        self.assertEqual((Practica, 12), event)

        event = self.interpreter._detect_event_class_and_id("s4")
        self.assertEqual((Seminar, 4), event)

        event = self.interpreter._detect_event_class_and_id("S4")
        self.assertEqual((Seminar, 4), event)

    def test_get_at_end_modifier(self):
        # Implicit start
        mods = self.interpreter._get_modifiers_as_string("S1")
        relative_modifier = mods[0]
        self.assertEqual(False, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string("S1F")
        relative_modifier = mods[0]
        self.assertEqual(True, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
        relative_modifier = mods[0]
        self.assertEqual(True, relative_modifier)

        # Implicit start
        mods = self.interpreter._get_modifiers_as_string("S1-1d")
        relative_modifier = mods[0]
        self.assertEqual(False, relative_modifier)

        # Explicit finish
        mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
        at_end = mods[0]
        self.assertEqual(True, at_end)

        # Explicit start
        mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
        at_end = mods[0]
        self.assertEqual(False, at_end)

        # Implicit start
        mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
        at_end = mods[0]
        self.assertEqual(False, at_end)

    def test_parse_invalid_modifiers(self):
        self.assertRaises(InvalidModifiersException, self.interpreter._get_modifiers_as_string, "[email protected]:59")
        self.assertRaises(InvalidModifiersException, self.interpreter._get_modifiers_as_string, "[email protected]:59+1m")
        self.assertRaises(InvalidModifiersException, self.interpreter._get_modifiers_as_string, "S1-23:[email protected]")

    def test_get_relative_modifier_as_string(self):
        mods = self.interpreter._get_modifiers_as_string("S1")
        relative_modifier = mods[1]
        self.assertEqual(None, relative_modifier)

        mods = self.interpreter._get_modifiers_as_string("S1F")
        relative_modifier = mods[1]
        self.assertEqual(None, relative_modifier)

        mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
#.........这里部分代码省略.........
开发者ID:hubuhuan,项目名称:course-activity-planner,代码行数:103,代码来源:interpreter_test.py


注:本文中的interpreter.Interpreter._detect_event_class_and_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。