def test_m_empty_cli(self, mock_stderr): with self.assertRaises(SystemExit) as prog: main() self.assertIn( 'the following arguments are required: <command>', mock_stderr.getvalue(), ) self.assertEqual(prog.exception.code, 2)
def test_missing_error_message_cli(self, mock_stderr): with self.assertRaises(SystemExit) as prog: main() self.assertIn( 'the following arguments are required: message', mock_stderr.getvalue(), ) self.assertEqual(prog.exception.code, 2)
def test_sort(self, mock_exit, mock_stdout): expected = """ { "a": 1, "c": 3, "z": 99 } """ main() self.assertEqual(mock_stdout.getvalue(), f'{cdoc(expected)}\n') mock_exit.assert_called_with(0)
def test_error(self, mock_exit, mock_stderr): main() errors = mock_stderr.getvalue() self.assertIn('multi_get key retrieval failure', errors) self.assertIn('key lookup failure: `a.b.d.0`', errors) mock_exit.assert_called_with(1)
def test_access_nested(self, mock_exit, mock_stdout): main() self.assertEqual(mock_stdout.getvalue(), 'hello\n') mock_exit.assert_called_with(0)
def test_access_array(self, mock_exit, mock_stdout): main() self.assertEqual(mock_stdout.getvalue(), '1\n') mock_exit.assert_called_with(0)
def test_normal(self, mock_exit, mock_stdout): main() self.assertEqual(mock_stdout.getvalue(), '[]\n') mock_exit.assert_called_with(0)
def test_m_version(self, mock_stdout): with self.assertRaises(SystemExit) as prog: main() self.assertEqual(mock_stdout.getvalue(), '0.0.0-PLACEHOLDER\n') self.assertEqual(prog.exception.code, 0)
def test_error_message(self, mock_stderr): with self.assertRaises(SystemExit) as prog: main() self.assertIn('error message\n', mock_stderr.getvalue()) self.assertEqual(prog.exception.code, 1)