python 调用cmd命令卡死_笨方法学Python练习48:为什么我执行nosetests 命令之后,命令行卡住了?...

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') ] )

实在是找不到解决方法了,特来求助。

不论如何,感谢浏览。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值