Ejemplo n.º 1
0
 def test_update_conflicting_nested_fields(self) -> None:
     n = Nested1(a=Nested2(b=Nested3(c=easy(val=42, name="foo"))))
     with self.assertRaises(ValueError):
         n = update_nested_field(
             n,
             {
                 "a.b.c": easy(val=128),
                 "a.b.c.val": 256,
             },
         )
Ejemplo n.º 2
0
 def test_call_replace(self) -> None:
     x = easy(val=1, an_int=Integers(small=300), name="foo")
     y = x(name="bar")
     self.assertNotEqual(x.name, y.name)
     z = y(an_int=None, val=4)
     self.assertNotEqual(x.an_int, z.an_int)
     self.assertNotEqual(x.val, z.val)
     self.assertIsNone(z.an_int.value)
     self.assertEqual(y.val, x.val)
     self.assertEqual(y.an_int, x.an_int)
     x = easy()
     self.assertIsNotNone(x.val)
     self.assertIsNotNone(x.val_list)
     self.assertIsNone(x.name)
     self.assertIsNotNone(x.an_int)
Ejemplo n.º 3
0
 def test_optional_struct_creation(self) -> None:
     with self.assertRaises(TypeError):
         # pyre-ignore[19]: for test
         easy(1, [1, 1], "test", Integers(tiny=1))
     easy(val=1, an_int=Integers(small=500))
     with self.assertRaises(TypeError):
         # pyre-ignore[6]: for test
         easy(name=b"binary")
     # Only Required Fields don't accept None
     easy(val=5, an_int=None)
Ejemplo n.º 4
0
 def test_update_invalid_nested_fields(self) -> None:
     n = Nested1(a=Nested2(b=Nested3(c=easy(val=42, name="foo"))))
     with self.assertRaises(ValueError):
         update_nested_field(n, {"": 0})
     with self.assertRaises(ValueError):
         update_nested_field(n, {"e": 0})
     with self.assertRaises(ValueError):
         update_nested_field(n, {"a.b.e": 0})
     with self.assertRaises(ValueError):
         update_nested_field(n, {"a.e.f": 0})
Ejemplo n.º 5
0
 def test_update_multiple_nested_fields(self) -> None:
     n = Nested1(a=Nested2(b=Nested3(c=easy(val=42, name="foo"))))
     n = update_nested_field(
         n,
         {
             "a.b.c.name": "bar",
             "a.b.c.val": 256,
         },
     )
     self.assertEqual(n.a.b.c.name, "bar")
     self.assertEqual(n.a.b.c.val, 256)
Ejemplo n.º 6
0
 def test_hashability(self) -> None:
     hash(easy())
Ejemplo n.º 7
0
 def test_copy(self) -> None:
     x = easy(val=1, an_int=Integers(small=300), name="foo", val_list=[1, 2, 3, 4])
     dif_list = copy.copy(x.val_list)
     self.assertEqual(x.val_list, dif_list)
     dif_int = copy.copy(x.an_int)
     self.assertEqual(x.an_int, dif_int)
Ejemplo n.º 8
0
 def test_update_nested_fields(self) -> None:
     n = Nested1(a=Nested2(b=Nested3(c=easy(val=42, name="foo"))))
     n = update_nested_field(n, {"a.b.c": easy(val=128)})
     self.assertEqual(n.a.b.c.val, 128)
Ejemplo n.º 9
0
 def test_init_with_invalid_field(self) -> None:
     with self.assertRaises(TypeError):
         # pyre-ignore[28]: for test
         easy(val=1, an_int=Integers(small=300), name="foo", val_lists=[1, 2, 3, 4])