def test_calling_int_is_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("len(a)") visitor.visit(node)
def test_calling_len_is_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("int('10')") visitor.visit(node)
def test_importing_disallowed(self): visitor = ResourceNodeVisitor() node = ast.parse("import foo") self.assertRaises(CodeNotAllowed, visitor.visit, node)
def test_function_calls_disallowed(self): visitor = ResourceNodeVisitor() node = ast.parse("foo()") self.assertRaises(CodeNotAllowed, visitor.visit, node)
def test_index_assignment_disallowed(self): visitor = ResourceNodeVisitor() node = ast.parse("package[0] = 'fwts'") self.assertRaises(CodeNotAllowed, visitor.visit, node)
def test_smoke(self): visitor = ResourceNodeVisitor() self.assertEqual(visitor.ids_seen_set, set()) self.assertEqual(visitor.ids_seen_list, [])
def test_in_expresions_are_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("'foo' in package.name") visitor.visit(node)
def test_in_expresions_with_list_are_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("package.name in ['foo', 'bar']") visitor.visit(node)
def test_comparisons_are_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("package.name == 'foo'") visitor.visit(node)
def test_boolean_ops_are_allowed(self): visitor = ResourceNodeVisitor() node = ast.parse("package.name and package.version") visitor.visit(node)
def test_smoke(self): visitor = ResourceNodeVisitor() self.assertEqual(visitor.names_seen, set())
def test_names_seen(self): visitor = ResourceNodeVisitor() node = ast.parse("package.name == 'fwts' and package.version == '1.2'") visitor.visit(node) self.assertEqual(visitor.names_seen, {'package'})