def test_stdin_py3_unicodedecodeerror(self, mock_print_ascii): mock_stdin = mock.Mock(sys.stdin) mock_stdin.buffer.read.return_value = 'testtext' mock_stdin.read.side_effect = bad_read with mock.patch('sys.stdin', mock_stdin): main([]) mock_print_ascii.assert_called_with(tty=True)
def test_stdin_py3_unicodedecodeerror(self, mock_print_ascii): mock_stdin = mock.Mock(sys.stdin) mock_stdin.buffer.read.return_value = "testtext" mock_stdin.read.side_effect = bad_read with mock.patch("sys.stdin", mock_stdin): main([]) mock_print_ascii.assert_called_with(tty=True)
def test_stdin(self, mock_print_ascii): mock_stdin = mock.Mock() mock_stdin.configure_mock(**{'read.return_value': 'testtext'}) with mock.patch('sys.stdin', mock_stdin) as stdin: main([]) self.assertTrue(stdin.read.called) mock_print_ascii.assert_called_with(tty=True)
def test_stdin(self, mock_print_ascii): mock_stdin = mock.Mock(sys.stdin) stdin_buffer = getattr(mock_stdin, 'buffer', mock_stdin) stdin_buffer.read.return_value = 'testtext' with mock.patch('sys.stdin', mock_stdin): main([]) self.assertTrue(stdin_buffer.read.called) mock_print_ascii.assert_called_with(tty=True)
def test_stdin_py3_unicodedecodeerror(self, mock_print_ascii): mock_stdin = mock.Mock(sys.stdin) mock_stdin.buffer.read.return_value = 'testtext' mock_stdin.read.side_effect = bad_read with mock.patch('sys.stdin', mock_stdin): # sys.stdin.read() will raise an error... self.assertRaises(UnicodeDecodeError, sys.stdin.read) # ... but it won't be used now. main([]) mock_print_ascii.assert_called_with(tty=True)
def test_piped(self, mock_stdout): main(['testtext'])
def test_isatty(self, mock_print_ascii): main(['testtext']) mock_print_ascii.assert_called_with(tty=True)
def test_factory(self, mock_stdout): main('testtext --factory svg'.split())
def show_qrcode(self, user: str, issuer: str): from qrcode import console_scripts console_scripts.main([self.generate_uri(user, issuer)])
def test_optimize(self, mock_print_ascii): main('testtext --optimize 0'.split())
def test_output(self): tmpfile = os.path.join(self.tmpdir, "test.png") main(['testtext', '--output', tmpfile]) os.remove(tmpfile)
def test_piped(self, mock_stdout): main(["testtext"])