nosetests 命令卡死
笨方法学Python练习48:nosetests 命令卡死
(初次发帖,如果有什么做的不好的地方,还请指出。)
在笨方法学Python的ex48中,我编写的lexicon类使得测试命令nosetests卡死了。
而我自己将test中的每个函数在控制台人肉run过一遍,并没有出现卡死的情况。
I need help...
运行nosetests之后:
CTRL+C之后 :
运行很久之后 CTRL+C :
lexicon 代码如下:
class Lexicon( object ) :
def __init__( self ) :
self.directions = [ 'north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back' ]
self.verbs = [ 'go', 'stop', 'kill', 'eat' ]
self.stops= [ 'the', 'in', 'of', 'form', 'at', 'it' ]
self.nouns = [ 'door', 'bear', 'princess', 'cabinet' ]
self.numbers = []
def lexicon( self ) :
stuff = raw_input( "> " )
words = stuff.split(" ")
result = self.scan( words )
print result
def isNumber ( self, word ) :
try :
int( word )
return True
except ValueError :
return False
def scan( self, words ) :
result = []
for word in words :
if word in self.directions :
result.append( ('direction', word) )
elif word in self.verbs :
result.append( ('verb', word) )
elif word in self.verbs :
result.append( ('stop', word ) )
elif word in self.nouns :
result.append( ('noun', word ) )
elif word in self.stops :
result.append( ('stop', word) )
elif self.isNumber( word ) :
result.append( ('number', int( word ) ) )
else :
result.append( ( 'error' , word ) )
return result
单元测试代码如下 :
from nose.tools import*
from ex48.ex48 import Lexicon
def test_directions() :
assert_equal( Lexicon().scan("north"), [( 'direction', 'north' )] )
result = Lexicon().scan( "north south east" )
assert_equal( result, [ ('direction', 'north'),
('direction', 'south'),
('direction', 'east') ] )
def test_verbs() :
assert_equal( Lexicon().scan("go"), ['verb', 'go'] )
result = Lexicon().scan( "go kill eat" )
assert_equal( result, [ ('verb', 'go' ),
('verb', 'kill'),
('verb', 'eat') ] )
def test_stops() :
assert_equal( Lexicon().scan("the"), [ ('stop', 'the') ] )
result = Lexicon().scan( "the in of" )
assert_equal( result, [ ('stop', 'the' ),
('stop', 'in'),
('stop', 'of') ] )
def test_nouns() :
assert_equal( Lexicon().scan("bear"), [ ('noun', 'bear') ] )
result = Lexicon().scan( "bear princess" )
assert_equal ( result, [ ('noun', 'bear'),
('noun', 'princess') ] )
def test_numbers() :
assert_equal ( Lexicon().scan("1234"), [('number', 1234) ] )
result = Lexicon().scan( "3 91234" )
assert_equal( result, [('number', 3 ),
('number', 91234 ) ] )
def test_errors() :
assert_equal( Lexicon().scan("asdf"), [('error', 'asdf')] )
result = Lexicon().scan( "bear IAS princess" )
assert_equal( result, [('noun', 'bear'),
('error', 'IAS'),
('noun', 'princess') ] )
测试代码出处 : http://www.kancloud.cn/kancloud/learn-python-hard-way/49926
实在是找不到解决方法了,特来求助。
不论如何,感谢浏览。
Ubuntu 14.04 亲测没有卡死,但是测试没有通过