Exemple #1
0
 def test_adapted_type_in_containers(self) -> None:
     int_list = [1, 2, 3]
     int_set = {4, 5, 6}
     int_to_datetime_map = {42: datetime.fromtimestamp(int(time.time()))}
     foo = Foo(
         int_list=int_list, int_set=int_set, int_to_datetime_map=int_to_datetime_map
     )
     self.assertEqual(foo.int_list, int_list)
     self.assertEqual(foo.int_set, int_set)
     self.assertEqual(foo.int_to_datetime_map, int_to_datetime_map)
Exemple #2
0
    def test_adapter_called_with_field_id(self) -> None:
        mock_from_thrift_field = MagicMock(wraps=DatetimeAdapter.from_thrift_field)
        DatetimeAdapter.from_thrift_field = mock_from_thrift_field
        mock_to_thrift_field = MagicMock(wraps=DatetimeAdapter.to_thrift_field)
        DatetimeAdapter.to_thrift_field = mock_to_thrift_field

        now_ts = int(time.time())
        now = datetime.fromtimestamp(now_ts)
        foo = Foo(created_at=now)
        mock_to_thrift_field.assert_called_once_with(now, 1, foo)
        foo.created_at
        mock_from_thrift_field.assert_called_once_with(now_ts, 1, foo)

        mock_from_thrift_field.reset_mock()
        mock_to_thrift_field.reset_mock()
        bar = Bar(ts=now)
        mock_to_thrift_field.assert_called_once_with(now, 2, bar)
        bar.ts
        mock_from_thrift_field.assert_called_once_with(now_ts, 2, bar)
Exemple #3
0
 def test_adapted_container_of_adapted_type(self) -> None:
     str_list = ["1", "1", "2", "3", "5", "8", "13"]
     foo = Foo(adapted_list=str_list)
     self.assertEqual(foo.adapted_list, str_list)
Exemple #4
0
 def test_double_adapters(self) -> None:
     now = datetime.fromtimestamp(int(time.time()))
     foo = Foo(another_time=now)
     self.assertIsInstance(foo.another_time, datetime)
     self.assertEqual(foo.another_time, now)
Exemple #5
0
 def test_typedef_field(self) -> None:
     now = datetime.fromtimestamp(int(time.time()))
     foo = Foo(updated_at=now)
     self.assertIsInstance(foo.updated_at, datetime)
     self.assertEqual(foo.updated_at, now)
Exemple #6
0
 def test_update(self) -> None:
     now = datetime.fromtimestamp(int(time.time()))
     foo = Foo(created_at=now)
     future = datetime.fromtimestamp(int(time.time()) + 100)
     foo = foo(created_at=future)
     self.assertEqual(foo.created_at, future)
Exemple #7
0
 def test_round_trip(self) -> None:
     now = datetime.fromtimestamp(int(time.time()))
     foo = Foo(created_at=now)
     self.assertIsInstance(foo.created_at, datetime)
     self.assertEqual(foo.created_at, now)
Exemple #8
0
 def test_directly_annotated(self) -> None:
     foo = Foo()
     self.assertEqual(Baz, Wrapped)
     self.assertIsInstance(foo.baz, Wrapped)
     self.assertIsInstance(foo.baz.obj, _fbthrift_unadapted_Baz)