示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
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)
示例#5
0
 def test_access_nested(self, mock_exit, mock_stdout):
     main()
     self.assertEqual(mock_stdout.getvalue(), 'hello\n')
     mock_exit.assert_called_with(0)
示例#6
0
 def test_access_array(self, mock_exit, mock_stdout):
     main()
     self.assertEqual(mock_stdout.getvalue(), '1\n')
     mock_exit.assert_called_with(0)
示例#7
0
 def test_normal(self, mock_exit, mock_stdout):
     main()
     self.assertEqual(mock_stdout.getvalue(), '[]\n')
     mock_exit.assert_called_with(0)
示例#8
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)
示例#9
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)