def test_check_file_output_exists_notty(self, mock_sys: Mock, mock_console: Mock): mock_sys.stdin.isatty.return_value = False mock_sys.exit.side_effect = SystemExit path = self.mock_path("foo", is_file=True) with self.assertRaises(SystemExit): check_file_output(path, False) self.assertEqual(mock_console.ask.call_args_list, [])
def test_check_file_output_exists_no(self, sys_exit): tmpfile = tempfile.NamedTemporaryFile() try: streamlink_cli.main.console = console = Mock() console.ask.return_value = "n" self.assertTrue(os.path.exists(tmpfile.name)) check_file_output(tmpfile.name, False) sys_exit.assert_called_with() finally: tmpfile.close()
def test_check_file_output_exists_ask_no(self, mock_sys: Mock, mock_console: Mock): mock_sys.stdin.isatty.return_value = True mock_sys.exit.side_effect = SystemExit mock_console.ask = Mock(return_value="N") path = self.mock_path("foo", is_file=True) with self.assertRaises(SystemExit): check_file_output(path, False) self.assertEqual( mock_console.ask.call_args_list, [call("File foo already exists! Overwrite it? [y/N] ")])
def test_check_file_output_exists_force(self): tmpfile = tempfile.NamedTemporaryFile() try: streamlink_cli.main.console = Mock() self.assertTrue(os.path.exists(tmpfile.name)) self.assertIsInstance(check_file_output(tmpfile.name, True), FileOutput) finally: tmpfile.close()
def test_check_file_output_exists_force(self): tmpfile = tempfile.NamedTemporaryFile() try: streamlink_cli.main.console = console = Mock() self.assertTrue(os.path.exists(tmpfile.name)) self.assertIsInstance(check_file_output(tmpfile.name, True), FileOutput) finally: tmpfile.close()
def test_check_file_output(self, mock_log: Mock): path = self.mock_path("foo", is_file=False, resolve="/path/to/foo") output = check_file_output(path, False) self.assertIsInstance(output, FileOutput) self.assertIs(output.filename, path) self.assertEqual(mock_log.info.call_args_list, [call("Writing output to\n/path/to/foo")]) self.assertEqual(mock_log.debug.call_args_list, [call("Checking file output")])
def test_check_file_output_exists(self): tmpfile = tempfile.NamedTemporaryFile() try: streamlink_cli.main.console = console = Mock() console.ask.return_value = "y" self.assertTrue(os.path.exists(tmpfile.name)) self.assertIsInstance(check_file_output(tmpfile.name, False), FileOutput) finally: tmpfile.close()
def test_check_file_output_exists_ask_yes(self, mock_sys: Mock, mock_console: Mock): mock_sys.stdin.isatty.return_value = True mock_console.ask = Mock(return_value="y") path = self.mock_path("foo", is_file=True) output = check_file_output(path, False) self.assertEqual( mock_console.ask.call_args_list, [call("File foo already exists! Overwrite it? [y/N] ")]) self.assertIsInstance(output, FileOutput) self.assertIs(output.filename, path)
def test_check_file_output(self, mock_log): streamlink_cli.main.console = Mock() self.assertIsInstance(check_file_output("foo", False), FileOutput) self.assertEqual(mock_log.debug.call_args_list, [call("Checking file output")])
def test_check_file_output(self): streamlink_cli.main.console = Mock() self.assertIsInstance(check_file_output("test", False), FileOutput)
def test_check_file_output_exists_force(self): output = check_file_output("foo", True) self.assertIsInstance(output, FileOutput) self.assertEqual(output.filename, "foo")
def test_check_file_output_exists_force(self): path = self.mock_path("foo", is_file=True) output = check_file_output(path, True) self.assertIsInstance(output, FileOutput) self.assertIs(output.filename, path)
def test_check_file_output(self): output = check_file_output("foo", False) self.assertIsInstance(output, FileOutput) self.assertEqual(output.filename, "foo")
def test_check_file_output(self): path = self.mock_path("foo", is_file=False) output = check_file_output(path, False) self.assertIsInstance(output, FileOutput) self.assertIs(output.filename, path)
def test_check_file_output_exists_notty(self, mock_sys: Mock): mock_sys.stdin.isatty.return_value = False mock_sys.exit.side_effect = SystemExit with self.assertRaises(SystemExit): check_file_output("foo", False)
def test_check_file_output_exists_ask_yes(self, mock_sys: Mock): mock_sys.stdin.isatty.return_value = True output = check_file_output("foo", False) self.assertIsInstance(output, FileOutput) self.assertEqual(output.filename, "foo")