def _assert_has_side_effects_and_not( self, code: str, expec_has_side_effects: scan.HasSideEffects, expec_not_side_effects=frozenset(), ): analyzer = scan.SideEffectsAnalyzer() analyzer.visit(ast.parse(code)) assert analyzer.has_side_effects() is expec_has_side_effects self._assert_not_side_effects(analyzer._not_side_effects, expec_not_side_effects)
def test_check_names(self, names, expec_has_side_effects): aliases = [ast.alias(name=n, asname=None) for n in names] analyzer = scan.SideEffectsAnalyzer() assert analyzer._check_names(aliases) is expec_has_side_effects
def test_compute_not_side_effects(self, code, expec_not_side_effects): analyzer = scan.SideEffectsAnalyzer() analyzer._compute_not_side_effects(ast.parse(code).body[0]) self._assert_not_side_effects( analyzer._not_side_effects, expec_not_side_effects )