Exemplo n.º 1
0
    def test_getting_defined_restricted_set(self):
        """ Make sure that properly formed commands are parsed into a list of
        command tuples. """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "has_section")
        self.mox.StubOutWithMock(SafeConfigParser, "items")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.has_section("commands").AndReturn(True)
        config.items("commands").AndReturn([
            ("foo", "ls::List files"),
            ("bar", "df:-h:Disk space usage (human readable)"),
            ("baz", "du:-sh .:"),
            ("foz", "pwd")
        ])

        self.mox.ReplayAll()

        self.assertEquals(restricted_set(), [
            ("ls", None, "List files"),
            ("df", ["-h"], "Disk space usage (human readable)"),
            ("du", ["-sh ."], ""),
            ("pwd", None, "")
        ])
Exemplo n.º 2
0
    def test_restricted_set_missing_section(self):
        """ If there is no commands section in the configuration file, an empty
        list should be returned. """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "has_section")
        self.mox.StubOutWithMock(SafeConfigParser, "items")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.has_section("commands").AndReturn(False)

        self.mox.ReplayAll()

        self.assertEquals(restricted_set(), [])