Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否有任何“工作”的例子;pytap“;点击Python的发射器_Python_Unit Testing_Tap - Fatal编程技术网

是否有任何“工作”的例子;pytap“;点击Python的发射器

是否有任何“工作”的例子;pytap“;点击Python的发射器,python,unit-testing,tap,Python,Unit Testing,Tap,如果我们看如例3所示: #TEST SOME STUFF from TAP.Simple import * plan(3) def in_between(value, bottom, top, msg): ret = ok(((bottom = value) and (value = top)), msg) if (not ret): diag("value %s is not between %s and %s" % (value, bottom, top)

如果我们看如例3所示:

#TEST SOME STUFF
from TAP.Simple import *

plan(3)

def in_between(value, bottom, top, msg):
    ret = ok(((bottom = value) and (value = top)), msg)
    if (not ret):
        diag("value %s is not between %s and %s" % (value, bottom, top))
    return ret

in_between(5, 3, 10, "5 is OK.")

in_between(5.5, 5, 6, "5[2] is OK.")

# This will fail.
in_between(1, 20, 30, "1 is in range.")
我正在尝试看看如何将其用于真正的Python代码

注意:ret=ok语句不是just=,而是没有显示代码,因此我将它们取出,我不确定如何转义它们

下面是一个可以用作源的示例

'''Convert to and from Roman numerals

This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers.  Visit http://diveintopython3.ep.io/ for the
latest version. - old website http://diveintopython3.org/ is not available anymore.
'''

roman_numeral_map = (('M',  1000),
                     ('CM', 900),
                     ('D',  500),
                     ('CD', 400),
                     ('C',  100),
                     ('XC', 90),
                     ('L',  50),
                     ('XL', 40),
                     ('X',  10),
                     ('IX', 9),
                     ('V',  5),
                     ('IV', 4),
                     ('I',  1))

def to_roman(n):
    '''convert integer to Roman numeral'''
    result = ''
    for numeral, integer in roman_numeral_map:
        while n >= integer:
            result += numeral
            n -= integer
    return result

# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 
# * Redistributions of source code must retain the above copyright notice,
#   this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

好的,我通过查看perl的TAP示例并将其转换为适合Python的形式,自己找到了答案

#!/usr/bin/env python
import TAP

ok = TAP.Builder.create(3).ok
def hello_world():
    return "Hello, World!"
ok(hello_world() ==  "Hello, World!", "First Test")
ok(hello_world() is  "Hello, World!", "Second Test")
ok(isinstance(hello_world(),str), "Third Test")
说明:

  • 在主机上安装后,点击导入
  • ok=TAP.Builder.create(3)。ok
    :3表示您计划了3个测试,其余的测试只需进行,没有问题
  • 第一个测试使用“代码”,然后是条件(
    ==
    ),然后是预期结果

  • 这同样适用于
    is
    ,或
    isinstance()

    好的,我自己通过查看perl的TAP示例,并将其转换为适合Python的形式,找到了答案

    #!/usr/bin/env python
    import TAP
    
    ok = TAP.Builder.create(3).ok
    def hello_world():
        return "Hello, World!"
    ok(hello_world() ==  "Hello, World!", "First Test")
    ok(hello_world() is  "Hello, World!", "Second Test")
    ok(isinstance(hello_world(),str), "Third Test")
    
    说明:

  • 在主机上安装后,点击导入
  • ok=TAP.Builder.create(3)。ok
    :3表示您计划了3个测试,其余的测试只需进行,没有问题
  • 第一个测试使用“代码”,然后是条件(
    ==
    ),然后是预期结果

  • 这同样适用于
    is
    ,或
    isinstance()

    ,因此,您将类似Perl的示例转换为(至少是公开可用的)。因此,您将类似Perl的示例转换为(至少是公开可用的)。