def equality_expressions_are_transformed(self): with setup: module_definition = """1 == 2 1 != 2 1 < 2 1 <= 2 1 > 2 1 >= 2 1 is 2 1 is not 2 1 in 2 1 not in 2 'The quick brown fox' @ '.+brown.+' """ node = ast.parse(module_definition, mode='exec') with when: ComparisonExpressionTransformer().visit(node) with then: body_elements = node.body all([ isinstance(body_element.value, _ast.Call) for body_element in body_elements ]) == True all([ body_element.value.func.attr == '_compare' for body_element in body_elements ]) == True
def visit_With(self, with_node): if FeatureBlockTransformer._is_feature_block(with_node): block_type = with_node.items[0].context_expr.id FeatureBlockRuleEnforcer( self.spec_metadata, self.feature_name, with_node).enforce_addition_rules(block_type) self.spec_metadata.add_feature_block(self.feature_name, block_type) if block_type != WHERE: FeatureBlockTransformer._replace_with_block_context( with_node, block_type) if block_type in [THEN, EXPECT]: ComparisonExpressionTransformer().visit(with_node) if block_type == THEN: MockAssertionTransformer().visit(with_node) ThrownExpressionTransformer().visit(with_node) return with_node where_function = self._replace_where_block_with_function(with_node) WhereBlockFunctions( self.spec_metadata, self.feature_name).assign_variables_to_the_context( where_function) self.spec_metadata.add_where_function( self.feature_name, copy.deepcopy(where_function)) return where_function
def nested_for_equality_is_transformed(self): with setup: module_definition = """ for x in [1, 2]: 1 == 2 """ node = ast.parse(module_definition, mode='exec') with when: ComparisonExpressionTransformer().visit(node) with then: body_expression = node.body[0] isinstance(body_expression, _ast.For) == True isinstance(body_expression.body[0].value, _ast.Call) == True body_expression.body[0].value.func.attr == '_compare'