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


Python Course.take方法代码示例

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


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

示例1: TestCourseTake

# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import take [as 别名]
class TestCourseTake(unittest.TestCase):

    def setUp(self):
        self.c1 = Course('CSC108')
        self.c2 = Course('CSC148', [self.c1])
        self.c3 = Course('CSC207', [self.c2])

    def test_take_prereq_satisfied(self):
        self.c1.taken = True
        self.assertFalse(self.c2.taken)
        self.c2.take()
        self.assertTrue(self.c2.taken)

    def test_take_taken(self):
        self.c1.taken = True
        self.c1.take()
        self.assertTrue(self.c1.taken)

    def test_take_many_in_a_row(self):
        self.c1.take()
        self.c2.take()
        self.c3.take()
        self.assertTrue(self.c3.taken)

    def test_take_error(self):
        self.c1.taken = False
        self.assertRaises(UntakeableError, self.c2.take)
开发者ID:sinoforever,项目名称:Assignment-2,代码行数:29,代码来源:course_test.py

示例2: TestCourseTake

# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import take [as 别名]
class TestCourseTake(unittest.TestCase):

    def setUp(self):
        self.c1 = Course('CSC108')
        self.c2 = Course('CSC148', [self.c1])

    def test_take_prereq_satisfied(self):
        self.c1.taken = True
        self.assertFalse(self.c2.taken)
        self.c2.take()
        self.assertTrue(self.c2.taken)
开发者ID:ooo125258,项目名称:Assignment-2,代码行数:13,代码来源:course_test.py

示例3: TestCourse

# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import take [as 别名]
class TestCourse(unittest.TestCase):

    def setUp(self):
        self.a = Course('A')
        self.b = Course('B')
        self.c = Course('C', [self.a])
        self.d = Course('D', [self.b, self.c])

    def test_initializes_with_values(self):
        self.assertEqual([self.b, self.c], self.d.prereqs)
        self.assertEqual([], self.a.prereqs)
        self.assertEqual('A', self.a.name)
        self.assertEqual(False, self.a.taken)

    def test_is_not_takeable_without_prereqs(self):
        self.assertEqual(False, self.d.is_takeable())
        self.assertEqual(False, self.c.is_takeable())

    def test_is_takeable_with_prereqs(self):
        self.a.take()
        self.assertEqual(True, self.c.is_takeable())
        self.assertEqual(False, self.d.is_takeable())
        self.b.take()
        self.assertEqual(False, self.d.is_takeable())
        self.c.take()
        self.assertEqual(True, self.d.is_takeable())

    def test_take_works(self):
        self.assertEqual(False, self.a.taken)
        self.a.take()
        self.assertEqual(True, self.a.taken)
        self.a.take()
        self.assertEqual(True, self.a.taken)

    def test_raises_error_if_cant_take(self):
        self.assertEqual(False, self.d.is_takeable())
        with self.assertRaises(UntakeableError):
            self.d.take()

    def test_add_prereq_works(self):
        self.a.add_prereq(self.b)
        self.assertEqual([self.b], self.a.prereqs)

    def test_add_prereq_fails_if_already_there(self):
        with self.assertRaises(PrerequisiteError):
            self.c.add_prereq(self.a)

    def test_add_prereq_fails_if_circular(self):
        with self.assertRaises(PrerequisiteError):
            self.a.add_prereq(self.c)

    def test_find(self):
        self.assertEqual(self.a, self.d.find('A'))
        self.assertEqual(None, self.d.find('G'))

    def test_missing_prereqs_works(self):
        self.assertEqual([], self.a.missing_prereqs())
        self.assertEqual(['A'], self.c.missing_prereqs())
        self.assertEqual(['A', 'B', 'C'], self.d.missing_prereqs())

    def test_adds_self_as_prereq(self):
        with self.assertRaises(PrerequisiteError):
            self.a.add_prereq(self.a)
开发者ID:connor4312,项目名称:CSC148-assignment-2,代码行数:65,代码来源:course_test.py


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