Beispiel #1
0
    def test_run_interactive_shell_command_kwargs_delegation(self):
        with self.assertRaises(TypeError):
            with run_interactive_shell_command("some_command",
                                               weird_parameter=30):
                pass

        # Test one of the forbidden parameters.
        with self.assertRaises(TypeError):
            with run_interactive_shell_command("some_command", shell=False):
                pass
Beispiel #2
0
    def test_run_interactive_shell_command_kwargs_delegation(self):
        with self.assertRaises(TypeError):
            with run_interactive_shell_command("some_command",
                                               weird_parameter=30):
                pass

        # Test one of the forbidden parameters.
        with self.assertRaises(TypeError):
            with run_interactive_shell_command("some_command", shell=False):
                pass
Beispiel #3
0
    def test_run_interactive_shell_command_custom_streams(self):
        command = RunShellCommandTest.construct_testscript_command(
            'test_interactive_program.py')

        with ExitStack() as stack:
            streams = {
                s: stack.enter_context(NamedTemporaryFile(mode='w+'))
                for s in ['stdout', 'stderr', 'stdin']
            }

            with run_interactive_shell_command(command, **streams) as p:
                streams['stdin'].write('712\n')
                streams['stdin'].flush()
                streams['stdin'].seek(0)

            self.assertFalse(streams['stdout'].closed)
            self.assertFalse(streams['stderr'].closed)
            self.assertFalse(streams['stdin'].closed)

            streams['stdout'].seek(0)
            self.assertEqual(
                streams['stdout'].read(),
                'test_program X\nType in a number:\n712\n'
                'Exiting program.\n')

            streams['stderr'].seek(0)
            self.assertEqual(streams['stderr'].read(), '')
Beispiel #4
0
    def test_run_interactive_shell_command_custom_streams(self):
        command = RunShellCommandTest.construct_testscript_command(
            "test_interactive_program.py")

        with ExitStack() as stack:
            streams = {
                s: stack.enter_context(NamedTemporaryFile(mode="w+"))
                for s in ["stdout", "stderr", "stdin"]
            }

            with run_interactive_shell_command(command, **streams) as p:
                streams["stdin"].write("712\n")
                streams["stdin"].flush()
                streams["stdin"].seek(0)

            self.assertFalse(streams["stdout"].closed)
            self.assertFalse(streams["stderr"].closed)
            self.assertFalse(streams["stdin"].closed)

            streams["stdout"].seek(0)
            self.assertEqual(
                streams["stdout"].read(),
                "test_program X\nType in a number:\n712\n"
                "Exiting program.\n")

            streams["stderr"].seek(0)
            self.assertEqual(streams["stderr"].read(), "")
Beispiel #5
0
    def test_run_interactive_shell_command(self):
        command = RunShellCommandTest.construct_testscript_command(
            "test_interactive_program.py")

        with run_interactive_shell_command(command) as p:
            self.assertEqual(p.stdout.readline(), "test_program X\n")
            self.assertEqual(p.stdout.readline(), "Type in a number:\n")
            p.stdin.write("33\n")
            p.stdin.flush()
            self.assertEqual(p.stdout.readline(), "33\n")
            self.assertEqual(p.stdout.readline(), "Exiting program.\n")
Beispiel #6
0
    def test_run_interactive_shell_command(self):
        command = RunShellCommandTest.construct_testscript_command(
            "test_interactive_program.py")

        with run_interactive_shell_command(command) as p:
            self.assertEqual(p.stdout.readline(), "test_program X\n")
            self.assertEqual(p.stdout.readline(), "Type in a number:\n")
            p.stdin.write("33\n")
            p.stdin.flush()
            self.assertEqual(p.stdout.readline(), "33\n")
            self.assertEqual(p.stdout.readline(), "Exiting program.\n")
Beispiel #7
0
    def test_run_interactive_shell_command(self):
        command = RunShellCommandTest.construct_testscript_command(
            'test_interactive_program.py')

        with run_interactive_shell_command(command) as p:
            self.assertEqual(p.stdout.readline(), 'test_program X\n')
            self.assertEqual(p.stdout.readline(), 'Type in a number:\n')
            p.stdin.write('33\n')
            p.stdin.flush()
            self.assertEqual(p.stdout.readline(), '33\n')
            self.assertEqual(p.stdout.readline(), 'Exiting program.\n')

            self.assertEqual(p.stdout.read(), '')
            self.assertEqual(p.stderr.read(), '')
Beispiel #8
0
    def test_run_interactive_shell_command(self):
        command = RunShellCommandTest.construct_testscript_command(
            'test_interactive_program.py')

        with run_interactive_shell_command(command) as p:
            self.assertEqual(p.stdout.readline(), 'test_program X\n')
            self.assertEqual(p.stdout.readline(), 'Type in a number:\n')
            p.stdin.write('33\n')
            p.stdin.flush()
            self.assertEqual(p.stdout.readline(), '33\n')
            self.assertEqual(p.stdout.readline(), 'Exiting program.\n')

            self.assertEqual(p.stdout.read(), '')
            self.assertEqual(p.stderr.read(), '')
Beispiel #9
0
    def test_run_interactive_shell_command_custom_streams(self):
        command = RunShellCommandTest.construct_testscript_command(
            "test_interactive_program.py")

        with ExitStack() as stack:
            streams = {s: stack.enter_context(NamedTemporaryFile(mode="w+"))
                       for s in ["stdout", "stderr", "stdin"]}

            with run_interactive_shell_command(command, **streams) as p:
                streams["stdin"].write("712\n")
                streams["stdin"].flush()
                streams["stdin"].seek(0)

            self.assertFalse(streams["stdout"].closed)
            self.assertFalse(streams["stderr"].closed)
            self.assertFalse(streams["stdin"].closed)

            streams["stdout"].seek(0)
            self.assertEqual(streams["stdout"].read(),
                             "test_program X\nType in a number:\n712\n"
                             "Exiting program.\n")

            streams["stderr"].seek(0)
            self.assertEqual(streams["stderr"].read(), "")
Beispiel #10
0
    def test_run_interactive_shell_command_custom_streams(self):
        command = RunShellCommandTest.construct_testscript_command(
            'test_interactive_program.py')

        with ExitStack() as stack:
            streams = {s: stack.enter_context(NamedTemporaryFile(mode='w+'))
                       for s in ['stdout', 'stderr', 'stdin']}

            with run_interactive_shell_command(command, **streams) as p:
                streams['stdin'].write('712\n')
                streams['stdin'].flush()
                streams['stdin'].seek(0)

            self.assertFalse(streams['stdout'].closed)
            self.assertFalse(streams['stderr'].closed)
            self.assertFalse(streams['stdin'].closed)

            streams['stdout'].seek(0)
            self.assertEqual(streams['stdout'].read(),
                             'test_program X\nType in a number:\n712\n'
                             'Exiting program.\n')

            streams['stderr'].seek(0)
            self.assertEqual(streams['stderr'].read(), '')
Beispiel #11
0
 def test_run_interactive_shell_command_kwargs_delegation(self):
     with self.assertRaises(TypeError):
         with run_interactive_shell_command("some_command",
                                            weird_parameter=30):
             pass
Beispiel #12
0
 def test_run_interactive_shell_command_kwargs_delegation(self):
     with self.assertRaises(TypeError):
         with run_interactive_shell_command('some_command',
                                            weird_parameter=30):
             pass