3
누구나 내가 DocI (Python)로 작성된 cli 앱을 테스트 할 수 있습니까? GitHub의에 누군가가이,테스트 Unittest에 Docopt 명령 줄 앱이 있습니까?
import unittest
from docopt import docopt
import your.entry.point.of.sum as sum
# you can import the doc string from the sum module
doc = sum.__doc__
# suppose now the doc is:
# Sum two numbers.
# Usage: summation.py <x> <y>
# then write your test cases
class TestCLIParser(unittest.TestCase):
def test_sum(self):
args = docopt(doc, ["1", "3"])
self.assertEqual(args["<x>"], "1")
self.assertEqual(args["<y>"], "3")
def and_so_on(self):
...
내가이 문제를 가지고 있지만이 프로그램의 출력을 테스트 할 수있는 방법을 누군가가 나를 보여줄 수 게시? 당신이 이러한 종류의 테스트를 구동 unittest
모듈을 사용할 수 있지만이 예에서는 엄격 단위 테스트 아니라, 인수
그래서이 질문에 stdout을 캡처하려는 http://stackoverflow.com/questions/4219717/how-to-assert-output-with-nosetest-unittest-in-python? –