Skip to content

Commit

Permalink
Add a base case unit test for instance/subclass checks in py3 and python
Browse files Browse the repository at this point in the history
Summary:
I was going to commit these along with my subclass/instance changes but I realized that with `brokenInAutoMigrate` I can just commit these now, so doing that.

Adds a unit test that checks that instance/subclass checks work as expected for thrift-py3 and thrift-python.

Reviewed By: yoney

Differential Revision: D68168761

fbshipit-source-id: d156c79ab6f8e0c6a09e57575cef28ca0a43180f
  • Loading branch information
Filip Francetic authored and facebook-github-bot committed Jan 14, 2025
1 parent 9cc2110 commit d63316a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions thrift/lib/py3/test/auto_migrate/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,8 @@ def test_included_struct_const(self) -> None:
FANCY_CONST.color_map,
{IncludedColour.red: Basic(), IncludedColour.blue: Basic(nom="b")},
)

@brokenInAutoMigrate()
def test_instance_base_class(self) -> None:
self.assertTrue(issubclass(Nested1, Struct))
self.assertIsInstance(Nested1(), Struct)
5 changes: 5 additions & 0 deletions thrift/lib/py3/test/auto_migrate/unions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,8 @@ def test_reserved_union(self) -> None:
self.assertEqual(x.type, ReservedUnion.Type.ok)
self.assertEqual(x.value, "bar")
self.assertEqual(x.ok, "bar")

@brokenInAutoMigrate()
def test_instance_base_class(self) -> None:
self.assertTrue(issubclass(ComplexUnion, Union))
self.assertIsInstance(ComplexUnion(tiny=1), Union)
6 changes: 5 additions & 1 deletion thrift/lib/python/test/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
to_thrift_set,
)

from thrift.python.types import isset, update_nested_field
from thrift.python.types import isset, Struct, update_nested_field

ListT = TypeVar("ListT")
SetT = TypeVar("SetT")
Expand Down Expand Up @@ -701,3 +701,7 @@ def test_compare_optional(self) -> None:
with self.assertRaises(TypeError):
# TODO(ffrancet): pyre should complain about this
z < y # noqa: B015

def test_instance_base_class(self) -> None:
self.assertTrue(issubclass(Nested1, Struct))
self.assertIsInstance(Nested1(), Struct)
4 changes: 4 additions & 0 deletions thrift/lib/python/test/unions.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,7 @@ def test_union_ordering(self) -> None:
# equality
y = self.Integers(tiny=4)
self.assertEqual(x, y)

def test_instance_base_class(self) -> None:
self.assertTrue(issubclass(ComplexUnion, Union))
self.assertIsInstance(ComplexUnion(tiny=1), Union)

0 comments on commit d63316a

Please sign in to comment.