python行為驅(qū)動(dòng)小筆記-創(chuàng)新互聯(lián)

執(zhí)行方式:

創(chuàng)新互聯(lián)不只是一家網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司;我們對(duì)營(yíng)銷(xiāo)、技術(shù)、服務(wù)都有自己獨(dú)特見(jiàn)解,公司采取“創(chuàng)意+綜合+營(yíng)銷(xiāo)”一體化的方式為您提供更專(zhuān)業(yè)的服務(wù)!我們經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。我們珍視每一份信任,關(guān)注我們的做網(wǎng)站、成都網(wǎng)站建設(shè)質(zhì)量和服務(wù)品質(zhì),在得到用戶(hù)滿(mǎn)意的同時(shí),也能得到同行業(yè)的專(zhuān)業(yè)認(rèn)可,能夠?yàn)樾袠I(yè)創(chuàng)新發(fā)展助力。未來(lái)將繼續(xù)專(zhuān)注于技術(shù)創(chuàng)新,服務(wù)升級(jí),滿(mǎn)足企業(yè)一站式成都全網(wǎng)營(yíng)銷(xiāo)推廣需求,讓再小的成都品牌網(wǎng)站建設(shè)也能產(chǎn)生價(jià)值!

lettuce features1
python行為驅(qū)動(dòng)小筆記

D:\TOOL\PycharmProjects\python2\CS\xingweiqudong>lettuce features1
d:\program files\python\lib\site-packages\fuzzywuzzy\fuzz.py:35: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
 warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')

Feature: Compute factorial       # \features1\zero.feature:1
  In order to play with Lettuce  # \features1\zero.feature:2
  As beginners                   # \features1\zero.feature:3
 we'll implement factorial      # \features1\zero.feature:4

  Scenario: Factorial of 0       # \features1\zero.feature:6
    Given I have the number 0    # \features1\steps.py:37
   when I compute its factorial # \features1\steps.py:44
    Then I see the number 1      # \features1\steps.py:51

  Scenario: Factorial of 1       # \features1\zero.feature:11
    Given I have the number 1    # \features1\steps.py:37
   when I compute its factorial # \features1\steps.py:44
    Then I see the number 1      # \features1\steps.py:51

  Scenario: Factorial of 2       # \features1\zero.feature:16
    Given I have the number 2    # \features1\steps.py:37
   when I compute its factorial # \features1\steps.py:44
    Then I see the number 2      # \features1\steps.py:51

  Scenario: Factorial of 3       # \features1\zero.feature:21
    Given I have the number 3    # \features1\steps.py:37
   when I compute its factorial # \features1\steps.py:44
    Then I see the number 6      # \features1\steps.py:51

1 feature (1 passed)
4 scenarios (4 passed)
12 steps (12 passed)

D:\TOOL\PycharmProjects\python2\CS\xingweiqudong>lettuce features
d:\program files\python\lib\site-packages\fuzzywuzzy\fuzz.py:35: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
 warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')

Feature: Compute factorial       # \features\zero.feature:1
  In order to play with Lettuce  # \features\zero.feature:2
  As beginners                   # \features\zero.feature:3
 we'll implement factorial      # \features\zero.feature:4

  Scenario: Factorial of 0       # \features\zero.feature:6
    Given I have the number 0    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 1      # \features\step.py:24

  Scenario: Factorial of 1       # \features\zero.feature:11
    Given I have the number 1    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 1      # \features\step.py:24

  Scenario: Factorial of 2       # \features\zero.feature:16
    Given I have the number 2    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 2      # \features\step.py:24

  Scenario: Factorial of 3       # \features\zero.feature:21
    Given I have the number 3    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 6      # \features\step.py:24

  Scenario: Factorial of 4       # \features\zero.feature:26
    Given I have the number 3    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 6      # \features\step.py:24

  Scenario: Factorial of 5       # \features\zero.feature:31
    Given I have the number 3    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 6      # \features\step.py:24

  Scenario: Factorial of 6       # \features\zero.feature:36
    Given I have the number 3    # \features\step.py:13
   when I compute its factorial # \features\step.py:18
    Then I see the number 6      # \features\step.py:24

1 feature (1 passed)
7 scenarios (7 passed)
21 steps (21 passed)

D:\TOOL\PycharmProjects\python2\CS\xingweiqudong>

代碼1

# encoding=utf-8
from lettuce import world, steps

def factorial(number):
    number = int(number)
    if (number == 0) or (number == 1):
        return 1
    else:
        return reduce(lambda x, y: x * y, range(1, number + 1))

@steps
class FactorialSteps(object):
    """Methods in exclude or starting with _ will not be considered as step"""

    exclude = ['set_number', 'get_number']

    def __init__(self, environs):
        # 初始全局變量
        self.environs = environs

    def set_number(self, value):
        # 設(shè)置全局變量中的number變量的值
        self.environs.number = int(value)

    def get_number(self):
        # 從全局變量中取出number的值
        return self.environs.number

    def _assert_number_is(self, expected, msg="Got %d"):
        number = self.get_number()
        # 斷言
        assert number == expected, msg % number

    def have_the_number(self, step, number):
        '''I have the number (\d+)'''
        # 上面的三引號(hào)引起的代碼必須寫(xiě),并且必須是三引號(hào)引起
        # 表示從場(chǎng)景步驟中獲取需要的數(shù)據(jù)
        # 并將獲得數(shù)據(jù)存到環(huán)境變量number中
        self.set_number(number)

    def i_compute_its_factorial(self, step):
        """When I compute its factorial"""
        number = self.get_number()
        # 調(diào)用factorial方法進(jìn)行階乘結(jié)算,
        # 并將結(jié)算結(jié)果存于全局變量中的number中
        self.set_number(factorial(number))

    def check_number(self, step, expected):
        '''I see the number (\d+)'''
        # 上面的三引號(hào)引起的代碼必須寫(xiě),并且必須是三引號(hào)引起
        # 表示從場(chǎng)景步驟中獲取需要的數(shù)據(jù)以便斷言測(cè)試結(jié)果
        self._assert_number_is(int(expected))

FactorialSteps(world)

用例

Feature: Compute factorial
  In order to play with Lettuce
  As beginners
 we'll implement factorial

  Scenario: Factorial of 0
    Given I have the number 0
   when I compute its factorial
    Then I see the number 1

  Scenario: Factorial of 1
    Given I have the number 1
   when I compute its factorial
    Then I see the number 1

  Scenario: Factorial of 2
    Given I have the number 2
   when I compute its factorial
    Then I see the number 2

  Scenario: Factorial of 3
    Given I have the number 3
   when I compute its factorial
    Then I see the number 6

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前標(biāo)題:python行為驅(qū)動(dòng)小筆記-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://muchs.cn/article44/djhohe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、定制開(kāi)發(fā)、網(wǎng)站收錄、響應(yīng)式網(wǎng)站面包屑導(dǎo)航、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作