當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python test.support.check__all__用法及代碼示例

用法:

test.support.check__all__(test_case, module, name_of_module=None, extra=(), not_exported=())

斷言module__all__ 變量包含所有公共名稱。

模塊的公共名稱(其 API)會根據它們是否符合公共名稱約定並在 module 中定義來自動檢測。

name_of_module 參數可以指定(作為字符串或其元組)API 可以定義哪些模塊以便被檢測為公共 API。一種情況是 module 從其他模塊導入其部分公共 API,可能是 C 後端(如 csv 及其 _csv )。

extra 參數可以是一組名稱,否則這些名稱不會被自動檢測為 “public”,例如沒有正確 __module__ 屬性的對象。如果提供,它將被添加到自動檢測到的中。

not_exported 參數可以是一組名稱,即使它們的名稱另有說明,也不能將其視為公共 API 的一部分。

示例使用:

import bar
import foo
import unittest
from test import support

class MiscTestCase(unittest.TestCase):
    def test__all__(self):
        support.check__all__(self, foo)

class OtherTestCase(unittest.TestCase):
    def test__all__(self):
        extra = {'BAR_CONST', 'FOO_CONST'}
        not_exported = {'baz'}  # Undocumented name.
        # bar imports part of its API from _bar.
        support.check__all__(self, bar, ('bar', '_bar'),
                             extra=extra, not_exported=not_exported)

3.6 版中的新函數。

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 test.support.check__all__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。