I'm trying to test the following simple object:
class WebCorpus(object):
def __init__(self):
_index = {}
_graph = {}
_ranks = {}
_corpusChanged = False
def lookup(self, keyword):
if keyword in _index:
return _index[keyword]
return None
# (some irrelevant code)
With:
from WebCorpus import WebCorpus
def test_engine():
print "Testing..."
content = """This is a sample <a href="http://www.example.com">webpage</a> with
<a href="http://www.go.to">two links</a> that lead nowhere special."""
outlinks = ["http://www.example.com", "http://www.go.to"]
corpus = WebCorpus()
assert corpus.lookup("anything") == None
#(some more code)
test_engine()
But it gives me an error: NameError: global name '_index' is not defined. I don't understand this, _index is clearly defined in the __init__ !? What is my mistake here?
Help appreciated.