3

Docopt (Python) で書かれた cli アプリをテストする方法を教えてもらえますか? GitHub の誰かがこれを投稿しました。

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):
        ...

私はこれを持っていますが、誰かがプログラムの出力をテストする方法を教えてもらえますか? この例では、引数のみをテストします

4

1 に答える 1