Commit f8888f3d217233a954ea2c9874615ecd5f6af4a7

Authored by selurvedu
1 parent c26fae0d

Add basic unit tests for set_to_object()

  1 +from unittest import TestCase, main
  2 +
  3 +from op_robot_tests.tests_files.service_keywords import set_to_object
  4 +
  5 +
  6 +class TestSetToObject(TestCase):
  7 + def test_raises_1(self):
  8 + given = None
  9 + with self.assertRaises(TypeError):
  10 + given = set_to_object(given, 'foo[0]', 1)
  11 +
  12 + def test_raises_2(self):
  13 + given = {'foo': None}
  14 + with self.assertRaises(TypeError):
  15 + given = set_to_object(given, 'foo[0]', 1)
  16 +
  17 + def test_1(self):
  18 + given = {}
  19 + expected = {'foo': 1}
  20 + given = set_to_object(given, 'foo', 1)
  21 + self.assertEqual(given, expected)
  22 +
  23 + def test_2(self):
  24 + given = {'foo': []}
  25 + expected = {'foo': [1]}
  26 + given = set_to_object(given, 'foo[0]', 1)
  27 + self.assertEqual(given, expected)
  28 +
  29 + def test_3(self):
  30 + given = {}
  31 + expected = {'foo': [1]}
  32 + given = set_to_object(given, 'foo[0]', 1)
  33 + self.assertEqual(given, expected)
  34 +
  35 + def test_4(self):
  36 + given = {}
  37 + expected = {'foo': {'bar': 1}}
  38 + given = set_to_object(given, 'foo.bar', 1)
  39 + self.assertEqual(given, expected)
  40 +
  41 + def test_5(self):
  42 + given = {}
  43 + expected = {'foo': [None, {'bar': 1}]}
  44 + given = set_to_object(given, 'foo[1].bar', 1)
  45 + self.assertEqual(given, expected)
  46 +
  47 + def test_6(self):
  48 + given = {}
  49 + expected = {'foo': [{'bar': [1]}]}
  50 + given = set_to_object(given, 'foo[0].bar[0]', 1)
  51 + self.assertEqual(given, expected)
  52 +
  53 + def test_7(self):
  54 + given = {}
  55 + expected = {'foo': [{'bar': [1]}, None, None]}
  56 + given = set_to_object(given, 'foo[-3].bar[-1]', 1)
  57 + self.assertEqual(given, expected)
  58 +
  59 + def test_8(self):
  60 + given = {'foo': [{'bar': [1]}]}
  61 + expected = {'foo': [{'bar': [1]}, None, {'baz': [2]}]}
  62 + given = set_to_object(given, 'foo[2].baz[0]', 2)
  63 + self.assertEqual(given, expected)
  64 +
  65 + def test_9(self):
  66 + given = {'foo': [{'bar': [1]}]}
  67 + expected = {'foo': [{'baz': [2, None]}, None, {'bar': [1]}]}
  68 + given = set_to_object(given, 'foo[-3].baz[-2]', 2)
  69 + self.assertEqual(given, expected)
  70 +
  71 +
  72 +if __name__ == '__main__':
  73 + main()
... ...
Please register or login to post a comment