Esempio n. 1
0
    def test_creation(self):
        name = "test"
        shell_collection = ShellCollection(name)

        parent = MockParent()
        shell_collection.setParent(parent)

        self.assertEqual(shell_collection.name, name)

        self.assertTrue(hasattr(parent, "do_%s" % name))
        self.assertTrue(hasattr(parent, "complete_%s" % name))
        self.assertTrue(hasattr(parent, "help_%s" % name))
Esempio n. 2
0
    def test_creation(self):
        name = "test"
        shell_collection = ShellCollection(name)

        parent = MockParent()
        shell_collection.setParent(parent)

        self.assertEqual(shell_collection.name, name)

        self.assertTrue(hasattr(parent, "do_%s" % name))
        self.assertTrue(hasattr(parent, "complete_%s" % name))
        self.assertTrue(hasattr(parent, "help_%s" % name))
Esempio n. 3
0
    def test_sub_collection(self):
        l1 = "level_1"
        l2 = "level_2"
        l3 = "level_3"

        root = MockParent()
        level_1 = ShellCollection(l1)
        level_1.setParent(root)
        level_2 = ShellCollection(l2)
        level_1.addCollection(level_2)
        level_3 = ShellCollection(l3)
        level_2.addCollection(level_3)

        tests = [(root, l1), (level_1, l2), (level_2, l3)]

        for parent, name in tests:
            self.assertTrue(hasattr(parent, "do_%s" % name))
            self.assertTrue(hasattr(parent, "complete_%s" % name))
            self.assertTrue(hasattr(parent, "help_%s" % name))

        root.do_level_1("level_2 ")
        self.assertFalse(root.didLastCommandFail())

        root.do_level_1("r ")
        self.assertTrue(root.didLastCommandFail())

        root.do_level_1(" level_2 level_3")
        self.assertFalse(root.didLastCommandFail())

        root.do_level_1("level_2 level_3 p")
        self.assertTrue(root.didLastCommandFail())

        result = root.complete_level_1(*completeMock("level_1 "))
        self.assertListEqual(result, [l2])

        result = root.complete_level_1(*completeMock("level_1 lev"))
        self.assertListEqual(result, [l2])

        result = root.complete_level_1(*completeMock("level_1 level_2 "))
        self.assertListEqual(result, [l3])

        root.help_level_1()
        level_1.help_level_2()
        level_2.help_level_3()
Esempio n. 4
0
    def test_sub_collection(self):
        l1 = "level_1"
        l2 = "level_2"
        l3 = "level_3"

        root = MockParent()
        level_1 = ShellCollection(l1)
        level_1.setParent(root)
        level_2 = ShellCollection(l2)
        level_1.addCollection(level_2)
        level_3 = ShellCollection(l3)
        level_2.addCollection(level_3)

        tests = [(root, l1), (level_1, l2), (level_2, l3)]

        for parent, name in tests:
            self.assertTrue(hasattr(parent, "do_%s" % name))
            self.assertTrue(hasattr(parent, "complete_%s" % name))
            self.assertTrue(hasattr(parent, "help_%s" % name))

        root.do_level_1("level_2 ")
        self.assertFalse(root.didLastCommandFail())

        root.do_level_1("r ")
        self.assertTrue(root.didLastCommandFail())

        root.do_level_1(" level_2 level_3")
        self.assertFalse(root.didLastCommandFail())

        root.do_level_1("level_2 level_3 p")
        self.assertTrue(root.didLastCommandFail())

        result = root.complete_level_1(*completeMock("level_1 "))
        self.assertListEqual(list(result), [l2])

        result = root.complete_level_1(*completeMock("level_1 lev"))
        self.assertListEqual(result, [l2])

        result = root.complete_level_1(*completeMock("level_1 level_2 "))
        self.assertListEqual(list(result), [l3])

        root.help_level_1()
        level_1.help_level_2()
        level_2.help_level_3()