liunx nose 测试-在liunx中测试nose软件包输入 nosete

作者:编程技术

Traceback(mostrecentcalllast):File"test.py",line84,inmodulemain()File"test.py",line64,inmainres=torch.cat([c_denorm,out_denorm],dim=0)RuntimeError:invalidargument0:Sizesoftensorsmustmatchexceptindimension0.Got459and456indimension2atC:w1swindowspytorchatensrcTH/generic/THTensor.cpp:689在测试新图片的时候,总是提示这种错误,测试图片只有RGB三个通道,请教大神解答

在liunx中测试nose软件包输入 nosetests -v sknn.tests出现错误
/usr/local/lib/python2.7/dist-packages/sklearn/cross_美高梅4858官方网站,validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Failure: ImportError (cannot import name downsample) ... ERROR

FAIL: test_convert_to_roman3 (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_clear.py", line 33, in test_convert_to_roman3
    self.assertEquals("V", self.cvt.convert_to_roman(5))
AssertionError: 'V' != 'IIII'

======================================================================

ERROR: Failure: ImportError (cannot import name downsample)

Traceback (most recent call last):
File "/tmp/pip-build-M9Ng2M/nose/nose/loader.py", line 418, in loadTestsFromName
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/tianxiao/scikit-neuralnetwork/sknn/tests/__init__.py", line 1, in
from sknn.backend import lasagne
File "/home/tianxiao/scikit-neuralnetwork/sknn/backend/lasagne/__init__.py", line 5, in
from .mlp import MultiLayerPerceptronBackend
File "/home/tianxiao/scikit-neuralnetwork/sknn/backend/lasagne/mlp.py", line 25, in
import lasagne.layers
File "/usr/local/lib/python2.7/dist-packages/lasagne/__init__.py", line 19, in
from . import layers
File "/usr/local/lib/python2.7/dist-packages/lasagne/layers/__init__.py", line 7, in
from .pool import *
File "/usr/local/lib/python2.7/dist-packages/lasagne/layers/pool.py", line 6, in
from theano.tensor.signal import downsample
ImportError: cannot import name downsample

Ran 1 test in 0.001s

FAILED

.FFFFF....

FAIL: test_convert_to_roman5 (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_clear.py", line 41, in test_convert_to_roman5
    self.cvt.convert_to_roman(2010))
AssertionError: 'MMX' != 'MMVIIII'

======================================================================

FAIL: test_convert_to_roman4 (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_clear.py", line 37, in test_convert_to_roman4
    self.cvt.convert_to_roman(12))
AssertionError: 'XII' != 'XI'

======================================================================

结果输出:(这样的结果让人弄不明白倒底哪些用例发生了错误,不如下面用例那样的一目了然)

 

FAIL: test_convert_to_roman2 (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_clear.py", line 30, in test_convert_to_roman2
    self.assertEquals("II", self.cvt.convert_to_roman(2))
AssertionError: 'II' != 'I'

======================================================================

Code
# !usr/bin/env python 2.7
# coding: utf-8
# filename: recipe8_obscure.py

import unittest
from recipe8 import *

class RomanNumeralTest(unittest.TestCase):
    def setUp(self):
        self.cvt = RomanNumeralConverter()

    def test_convert_to_decimal(self):
        self.assertEquals(0, self.cvt.convert_to_decimal(""))
        self.assertEquals(1, self.cvt.convert_to_decimal("I"))
        self.assertEquals(2010, 
                          self.cvt.convert_to_decimal("MMX"))
        self.assertEquals(4000, 
                          self.cvt.convert_to_decimal("MMMM"))

    def test_convert_to_roman(self):
        self.assertEquals("", self.cvt.convert_to_roman(0))
        self.assertEquals("II", self.cvt.convert_to_roman(2))
        self.assertEquals("V", self.cvt.convert_to_roman(5))
        self.assertEquals("XII", 
                          self.cvt.convert_to_roman(12))
        self.assertEquals("MMX", 
                          self.cvt.convert_to_roman(2010))
        self.assertEquals("MMMM", 
                          self.cvt.convert_to_roman(4000))

if __name__ == "__main__":
    unittest.main()

美高梅4858官方网站 1美高梅4858官方网站 2

  1. Create a new file named recipe8.py in which to put our application code for this
    recipe.

  2. Pick a class to test. In this case, we will use an alternative version of the Roman
    numeral converter, which converts both ways.

  3. Create a new file called recipe8_obscure.py in which to put some longer
    test methods.

  4. Create some test methods that combine several test assertions.

  5. Run the obscure tests. Why did it fail? Where is the bug? It reports that II is not
    equal to I, so something appears to be off. If this the only bug?

  6. Create another file called recipe8_clear.py to create a more fine-grained set of
    test methods.

  7. Split up the assertions into separate test methods to give a higher fidelity of output.

  8. Run the clearer test suite. Is it a bit clearer where the bug is? What did we trade in to
    get this higher degree of test failure? Was it worth the effort?

美高梅4858官方网站 3美高梅4858官方网站 4

 

FAIL: test_convert_to_roman (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_obscure.py", line 22, in test_convert_to_roman
    self.assertEquals("II", self.cvt.convert_to_roman(2))
AssertionError: 'II' != 'I'


Ran 2 tests in 0.001s

FAILED (failures=1)
Process terminated with an exit code of 1

 

测试代码2:

美高梅4858官方网站 5美高梅4858官方网站 6

Code
# !usr/bin/env python 2.7
# coding: utf-8
# filename: recipe8_clear.py

import unittest
from recipe8 import *

class RomanNumeralTest(unittest.TestCase):
    def setUp(self):
        self.cvt = RomanNumeralConverter()

    def test_to_decimal1(self):
        self.assertEquals(0, self.cvt.convert_to_decimal(""))

    def test_to_decimal2(self):
        self.assertEquals(1, self.cvt.convert_to_decimal("I"))

    def test_to_decimal3(self):
        self.assertEquals(2010, 
                          self.cvt.convert_to_decimal("MMX"))

    def test_to_decimal4(self):
        self.assertEquals(4000, 
                          self.cvt.convert_to_decimal("MMMM"))

    def test_convert_to_roman1(self):
        self.assertEquals("", self.cvt.convert_to_roman(0))

    def test_convert_to_roman2(self):
        self.assertEquals("II", self.cvt.convert_to_roman(2))

    def test_convert_to_roman3(self):
        self.assertEquals("V", self.cvt.convert_to_roman(5))

    def test_convert_to_roman4(self):
        self.assertEquals("XII", 
                          self.cvt.convert_to_roman(12))

    def test_convert_to_roman5(self):
        self.assertEquals("MMX", 
                          self.cvt.convert_to_roman(2010))

    def test_convert_to_roman6(self):
        self.assertEquals("MMMM", 
                          self.cvt.convert_to_roman(4000))

if __name__ == "__main__":
    unittest.main()

结果输出:

将晦涩难懂的测试分解成简单的测试

FAIL: test_convert_to_roman6 (__main__.RomanNumeralTest)

Traceback (most recent call last):
  File "e:studypython4668_CodeChapter 1\01recipe8_clear.py", line 45, in test_convert_to_roman6
    self.cvt.convert_to_roman(4000))
AssertionError: 'MMMM' != 'MMMDCCCCLXXXXVIIII'


Ran 10 tests in 0.001s

FAILED (failures=5)
Process terminated with an exit code of 1

.F

本篇的目的是解说晦涩的测试不易一目了然,然后用一个例子将晦涩的测试用例化为简单的测试用例,使得测试结果一目了然。

Unittest provides the means to test the code through a series of assertions. I have often felt
the temptation to exercise many aspects of a particular piece of code within a single test
method. If any part fails, it becomes obscured as to which part failed. It is preferable to split
things up into several smaller test methods, so that when some part of the code under test
fails, it is obvious.

测试代码1:

Code
# !usr/bin/env python 2.7
# coding: utf-8
# filename: recipe8.py
class RomanNumeralConverter(object):
    def __init__(self):
        self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1}

    def convert_to_decimal(self, roman_numeral):
        val = 0
        for char in roman_numeral:
            val  = self.digit_map[char]
        return val

    def convert_to_roman(self, decimal):
        val = ""
        while decimal > 1000:
            val  = "M"
            decimal -= 1000
        while decimal > 500:
            val  = "D"
            decimal -= 500
        while decimal > 100:
            val  = "C"
            decimal -= 100
        while decimal > 50:
            val  = "L"
            decimal -= 50
        while decimal > 10:
            val  = "X"
            decimal -= 10
        while decimal > 5:
            val  = "V"
            decimal -= 5
        while decimal > 1:
            val  = "I"
            decimal -= 1
        return val

Breaking down obscure tests into simple ones.

本文由美高梅4858官方网站发布,转载请注明来源

关键词: 图片 错误 提示 测试