Ejemplo n.º 1
0
    def test_return(self):
        if platform.system().lower() == "windows":
            return_command_item = CommandItem("return_command_item", "exit 1")
        else:
            return_command_item = CommandItem("return_command_item", "return 1")

        return_command_item.action()

        self.assertEqual(return_command_item.get_return(), 1)
Ejemplo n.º 2
0
    def test_run(self):
        create_item = CommandItem("create_item", 'echo hello>test.txt')
        if platform.system().lower() == "windows":
            delete_item = CommandItem("delete_item", "del test.txt")
            expected_contents = "hello \n"
        else:
            delete_item = CommandItem("delete_item", "rm test.txt")
            expected_contents = "hello\n"
        create_item.action()
        self.assertEqual(create_item.get_return(), 0)
        self.assertTrue(os.path.isfile("test.txt"))

        with open("test.txt", 'r') as text:
            self.assertEqual(text.read(), expected_contents)

        delete_item.action()
        self.assertEqual(delete_item.get_return(), 0)
        self.assertFalse(os.path.isfile("test.txt"))
Ejemplo n.º 3
0
 def test_call(self, mock_class):
     command_item = CommandItem("command_item", "ls", ["-l", "-a", "~"])
     command_item.action()
     mock_class.run.assert_called_with("ls -l -a ~", shell=True)