Skip to content

Commit

Permalink
document invalid enum __init__ behavior
Browse files Browse the repository at this point in the history
Summary: Somehow we don't have any tests for py3 or python enum `raises ValueError` on invalid int arg to `__init__`

Reviewed By: yoney

Differential Revision: D65001970

fbshipit-source-id: e5a26e995eb56a801d9e1d37fa79d3e80adf27ac
  • Loading branch information
ahilger authored and facebook-github-bot committed Oct 26, 2024
1 parent b260c35 commit 15940d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions thrift/lib/py3/test/auto_migrate/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_normal_enum(self) -> None:
self.assertNotEqual(x.type, Kind.SOCK)
self.assertIn(x.type, Kind)
self.assertEqual(int(x.type), 4)
self.assertRaises(ValueError, lambda: Kind(47))

def test_normal_enum_not_int(self) -> None:
x = File(name="/etc", type=Kind.DIR)
Expand Down
1 change: 1 addition & 0 deletions thrift/lib/python/test/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_normal_enum(self) -> None:
self.assertIsInstance(self.Kind.DIR, int, "Enums are Ints")
self.assertIn(x.type, self.Kind)
self.assertEqual(x.type.value, 4)
self.assertRaises(ValueError, lambda: self.Kind(47))

def test_enum_value_rename(self) -> None:
"""The value name is None but we auto rename it to None_"""
Expand Down

0 comments on commit 15940d1

Please sign in to comment.