Skip to content

Commit

Permalink
verify converter output type
Browse files Browse the repository at this point in the history
Summary: Building on previous test, verify that thrift-generated source cython respects the `auto_migrate` PACKAGE setting. The `converter.pyx` behaves as expected in both auto-migrate mode and default mode, as proven by ability to correctly handle given type and return the expected type.

Reviewed By: createdbysk

Differential Revision: D70591736

fbshipit-source-id: 4e07ec89448ab854dd1383c5c1f41b6017bb96d9
  • Loading branch information
ahilger authored and facebook-github-bot committed Mar 5, 2025
1 parent 842a01b commit 67b3ce6
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import unittest

import convertible.thrift_types as python_convertible

import thrift.py3.test.cpp_converter_helper as converter

from convertible.types import Color, Nested, Simple, Union
from thrift.lib.py3.test.auto_migrate.auto_migrate_util import is_auto_migrated


class CppConverterEcho(unittest.TestCase):
Expand Down Expand Up @@ -71,19 +74,28 @@ def make_nested(self) -> Nested:
)

def test_echo_simple(self) -> None:
self.assertEqual(self.make_simple(), converter.echo_simple(self.make_simple()))
echo = converter.echo_simple(self.make_simple())
self.assertEqual(self.make_simple(), echo)
expected_type = python_convertible.Simple if is_auto_migrated() else Simple
self.assertIsInstance(echo, expected_type)

def test_echo_nested(self) -> None:
self.assertEqual(self.make_nested(), converter.echo_nested(self.make_nested()))
echo = converter.echo_nested(self.make_nested())
self.assertEqual(self.make_nested(), echo)
expected_type = python_convertible.Nested if is_auto_migrated() else Nested
self.assertIsInstance(echo, expected_type)

def test_echo_union(self) -> None:
for ufac in [
for u_factory in [
lambda: Union(intField=42),
lambda: Union(strField="hello"),
lambda: Union(simple_=self.make_simple()),
lambda: Union(intList=[1, 1, 2, 3, 5, 8]),
]:
self.assertEqual(ufac(), converter.echo_union(ufac()))
echo = converter.echo_union(u_factory())
self.assertEqual(u_factory(), echo, str(u_factory()))
expected_type = python_convertible.Union if is_auto_migrated() else Union
self.assertIsInstance(echo, expected_type)

def test_constructor_error(self) -> None:
bad_unicode = b"\xc3\x28"
Expand Down

0 comments on commit 67b3ce6

Please sign in to comment.