V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
reloop
V2EX  ›  V2EX

nose 里的 assert_equal() 方法是什么意思?

  •  
  •   reloop · 2013-11-15 17:55:49 +08:00 · 5002 次点击
    这是一个创建于 4115 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在 <笨办法学python> 看到的 , 找不到相关的内容解释
    摸索中... 希望能解释的详细一点 , 谢谢!!
    #coding:UTF-8
    from nose.tools import *
    import nose
    import sys
    sys.path.append("../ex47") # 把 这个文件的上级目录的 ex47 加下 python 的模组 索引路径目录
    from ex47.game import Room # 把 ex47这个文件夹下的 game.py 里的 Room 类导入进来
    def test_room():
    gold = Room("GoldRoom",
    """This room has gold in it you can grab. There's a
    door to the north.""") # 创建一个 Room 类的对象 gold , 参数1表示name 2表示description
    assert_equal(gold.name, "GoldRoom")
    assert_equal(gold.paths, {}) # {} 表示空字典
    view raw s.py hosted with ❤ by GitHub
    第 1 条附言  ·  2013-11-15 18:29:55 +08:00
    意思好像就是左右两个东西在做比较 , 不相等就报错
    可能是比较两个字符串 , 甚至两个对象也可以

    然后我不明白 , 这整个测试流程是什么意思? 或者说为什么是这样在做测试? 他的意义是什么? 要得出什么结论?

    这个是 game.py
    class Room(object):
    def __init__(self , name , description):
    self.name = name
    self.description = description
    self.paths = {}
    def go(self , direction):
    return self.paths.get(direction , None)
    def add_paths(self , paths):
    self.paths.update(paths)
    view raw game.py hosted with ❤ by GitHub


    这个是 ex47_tests.py
    https://gist.github.com/rtDNVdza/7482271
    第 2 条附言  ·  2013-11-15 18:30:19 +08:00
    class Room(object):
    def __init__(self , name , description):
    self.name = name
    self.description = description
    self.paths = {}
    def go(self , direction):
    return self.paths.get(direction , None)
    def add_paths(self , paths):
    self.paths.update(paths)
    view raw game.py hosted with ❤ by GitHub
    第 3 条附言  ·  2013-11-15 18:35:15 +08:00
    不能编辑 , 不能删除 , 不能预览 orz.....
    from nose.tools import *
    import nose
    import sys
    sys.path.append("../ex47")
    from ex47.game import Room
    def test_room():
    gold = Room("GoldRoom",
    """This room has gold in it you can grab. There's a
    door to the north.""")
    assert_equal(gold.name, "GoldRoom")
    assert_equal(gold.paths, {})
    def test_room_paths():
    center = Room("Center", "Test room in the center.")
    north = Room("North", "Test room in the north.")
    south = Room("South", "Test room in the south.")
    center.add_paths({'north': north, 'south': south})
    assert_equal(center.go('north'), north)
    assert_equal(center.go('south'), south)
    def test_map():
    start = Room("Start", "You can go west and down a hole.")
    west = Room("Trees", "There are trees here, you can go east.")
    down = Room("Dungeon", "It's dark down here, you can go up.")
    start.add_paths({'west': west, 'down': down})
    west.add_paths({'east': start})
    down.add_paths({'up': start})
    assert_equal(start.go('west'), west)
    assert_equal(start.go('west').go('east'), start)
    assert_equal(start.go('down').go('up'), start)
    view raw ex47_tests.py hosted with ❤ by GitHub
    5 条回复    1970-01-01 08:00:00 +08:00
    rrfeng
        1
    rrfeng  
       2013-11-15 18:07:13 +08:00
    help(assert_equal())
    reloop
        2
    reloop  
    OP
       2013-11-15 18:18:09 +08:00
    @rrfeng 要在哪里打这句话?
    rrfeng
        3
    rrfeng  
       2013-11-15 20:38:03 +08:00
    @reloop
    先 import
    再 help
    rrfeng
        4
    rrfeng  
       2013-11-15 20:38:42 +08:00
    或者直接去看源码呀。。。
    reloop
        5
    reloop  
    OP
       2013-11-16 03:45:40 +08:00
    @rrfeng 恩 , 谢谢!!!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1302 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:32 · PVG 01:32 · LAX 09:32 · JFK 12:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.