Skip to content

Commit 4981d42

Browse files
committed
Raises error when unsupported mode is passed
1 parent 18318f5 commit 4981d42

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

piranha_python/codemods.py

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def add_args(arg_parser): # pragma: no cover
4646

4747
def __init__(self, context, flag_name, flag_resolution_methods, ignored_module_check_fn_path=None, mode="treated"):
4848
super().__init__(context)
49+
if mode not in ("treated", "control"):
50+
raise ValueError("mode parameter must be 'treated' or 'control' - '%s' was passed" % mode)
51+
4952
self.flag_name = flag_name
5053
self.is_in_feature_flag_block = False
5154
self.found_return_stmt_in_ff_block = False

test/test_codemods.py

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ def test_lack_of_custom_method_name_raises_exception(self):
1919

2020
self.assertIn("flag_resolution_methods", thrown_exception.exception.args[0])
2121

22+
def test_unsupported_mode_name_raises_exception(self):
23+
with self.assertRaises(ValueError) as thrown_exception:
24+
self.assertCodemod(
25+
"print('This is not related to the feature flag value at all')",
26+
"print('This is not related to the feature flag value at all')",
27+
flag_name=FEATURE_FLAG_NAME,
28+
flag_resolution_methods="is_flag_active",
29+
mode="not-a-supported-mode",
30+
)
31+
32+
self.assertIn("mode", thrown_exception.exception.args[0])
33+
2234

2335
class PiranhaTreatmentFlagTest(CodemodTest):
2436
TRANSFORM = PiranhaCommand

0 commit comments

Comments
 (0)