本文整理匯總了Python中doctest.NORMALIZE_WHITESPACE屬性的典型用法代碼示例。如果您正苦於以下問題:Python doctest.NORMALIZE_WHITESPACE屬性的具體用法?Python doctest.NORMALIZE_WHITESPACE怎麽用?Python doctest.NORMALIZE_WHITESPACE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類doctest
的用法示例。
在下文中一共展示了doctest.NORMALIZE_WHITESPACE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import os
import doctest
from pyspark.context import SparkContext
from pyspark.sql import Row
import pyspark.sql.session
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.session.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
globs['sc'] = sc
globs['spark'] = SparkSession(sc)
globs['rdd'] = rdd = sc.parallelize(
[Row(field1=1, field2="row1"),
Row(field1=2, field2="row2"),
Row(field1=3, field2="row3")])
globs['df'] = rdd.toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.session, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
globs['sc'].stop()
if failure_count:
sys.exit(-1)
示例2: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import os
import doctest
from pyspark.context import SparkContext
from pyspark.sql import Row
import pyspark.sql.session
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.session.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
globs['sc'] = sc
globs['spark'] = SparkSession(sc)
globs['rdd'] = rdd = sc.parallelize(
[Row(field1=1, field2="row1"),
Row(field1=2, field2="row2"),
Row(field1=3, field2="row3")])
globs['df'] = rdd.toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.session, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
globs['sc'].stop()
if failure_count:
exit(-1)
示例3: makeTest
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def makeTest(self, obj, parent):
"""Look for doctests in the given object, which will be a
function, method or class.
"""
#print 'Plugin analyzing:', obj, parent # dbg
# always use whitespace and ellipsis options
optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
doctests = self.finder.find(obj, module=getmodule(parent))
if doctests:
for test in doctests:
if len(test.examples) == 0:
continue
yield DocTestCase(test, obj=obj,
optionflags=optionflags,
checker=self.checker)
示例4: load_tests
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def load_tests(loader, tests, ignore):
env = os.environ.copy()
env['CR8_NO_TQDM'] = 'True'
node.start()
assert node.http_host, "http_url must be available"
tests.addTests(doctest.DocFileSuite(
os.path.join('..', 'README.rst'),
globs={
'sh': functools.partial(
subprocess.run,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=60,
shell=True,
env=env
)
},
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
setUp=setup,
tearDown=teardown,
parser=Parser()
))
return tests
示例5: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import doctest
import pyspark.ml.image
globs = pyspark.ml.image.__dict__.copy()
spark = SparkSession.builder\
.master("local[2]")\
.appName("ml.image tests")\
.getOrCreate()
globs['spark'] = spark
(failure_count, test_count) = doctest.testmod(
pyspark.ml.image, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
spark.stop()
if failure_count:
sys.exit(-1)
示例6: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import doctest
from pyspark.sql import Row, SparkSession
import pyspark.sql.functions
globs = pyspark.sql.functions.__dict__.copy()
spark = SparkSession.builder\
.master("local[4]")\
.appName("sql.functions tests")\
.getOrCreate()
sc = spark.sparkContext
globs['sc'] = sc
globs['spark'] = spark
globs['df'] = spark.createDataFrame([Row(name='Alice', age=2), Row(name='Bob', age=5)])
(failure_count, test_count) = doctest.testmod(
pyspark.sql.functions, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
spark.stop()
if failure_count:
sys.exit(-1)
示例7: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import doctest
from pyspark.sql import SparkSession
import pyspark.sql.udf
globs = pyspark.sql.udf.__dict__.copy()
spark = SparkSession.builder\
.master("local[4]")\
.appName("sql.udf tests")\
.getOrCreate()
globs['spark'] = spark
(failure_count, test_count) = doctest.testmod(
pyspark.sql.udf, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
spark.stop()
if failure_count:
sys.exit(-1)
示例8: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import os
import doctest
from pyspark.sql import SparkSession
import pyspark.sql.catalog
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.catalog.__dict__.copy()
spark = SparkSession.builder\
.master("local[4]")\
.appName("sql.catalog tests")\
.getOrCreate()
globs['sc'] = spark.sparkContext
globs['spark'] = spark
(failure_count, test_count) = doctest.testmod(
pyspark.sql.catalog,
globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
spark.stop()
if failure_count:
sys.exit(-1)
示例9: _test
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _test():
import doctest
from pyspark.sql import SparkSession
import pyspark.sql.column
globs = pyspark.sql.column.__dict__.copy()
spark = SparkSession.builder\
.master("local[4]")\
.appName("sql.column tests")\
.getOrCreate()
sc = spark.sparkContext
globs['spark'] = spark
globs['df'] = sc.parallelize([(2, 'Alice'), (5, 'Bob')]) \
.toDF(StructType([StructField('age', IntegerType()),
StructField('name', StringType())]))
(failure_count, test_count) = doctest.testmod(
pyspark.sql.column, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
spark.stop()
if failure_count:
sys.exit(-1)
示例10: test_suite
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def test_suite():
suite = unittest.makeSuite(InterfaceTests)
suite.addTest(doctest.DocTestSuite("zope.interface.interface"))
if sys.version_info >= (2, 4):
suite.addTest(doctest.DocTestSuite())
suite.addTest(doctest.DocFileSuite(
'../README.txt',
globs={'__name__': '__main__'},
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
))
suite.addTest(doctest.DocFileSuite(
'../README.ru.txt',
globs={'__name__': '__main__'},
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
))
return suite
示例11: _import_docstring
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _import_docstring(documenter):
code_content = _import_docstring_code_content(documenter)
if code_content:
# noinspection PyBroadException
try:
code, content = code_content
parser = DocTestParser()
runner = DocTestRunner(verbose=0,
optionflags=NORMALIZE_WHITESPACE | ELLIPSIS)
glob = {}
if documenter.modname:
exec('from %s import *\n' % documenter.modname, glob)
tests = parser.get_doctest(code, glob, '', '', 0)
runner.run(tests, clear_globs=False)
documenter.object = tests.globs[documenter.name]
documenter.code = content
documenter.is_doctest = True
return True
except Exception:
pass
示例12: _run_doctest_for_content
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def _run_doctest_for_content(self, name, content):
optionflags = (
doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
| doctest.IGNORE_EXCEPTION_DETAIL
| _get_allow_unicode_flag()
)
runner = doctest.DocTestRunner(
verbose=None,
optionflags=optionflags,
checker=_get_unicode_checker(),
)
globs = {"print_function": print_function}
parser = doctest.DocTestParser()
test = parser.get_doctest(content, globs, name, name, 0)
runner.run(test)
runner.summarize()
assert not runner.failures
示例13: run_test_file
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def run_test_file(filename, globs):
return run_test_file_with_config(
filename,
globs=globs,
optionflags=(
_report_first_flag()
| doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
| NORMALIZE_PATHS
| WINDOWS
| STRIP_U
| STRIP_L
| STRIP_ANSI_FMT
| PY2
| PY3
),
)
示例14: test_print_whats_next
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def test_print_whats_next(self):
profile = {
"name": factory.make_name("profile"),
"url": factory.make_name("url"),
}
stdout = self.patch(sys, "stdout", StringIO())
cli.cmd_login.print_whats_next(profile)
expected = (
dedent(
"""\
You are now logged in to the MAAS server at %(url)s
with the profile name '%(name)s'.
For help with the available commands, try:
maas %(name)s --help
"""
)
% profile
)
observed = stdout.getvalue()
flags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
self.assertThat(observed, DocTestMatches(expected, flags))
示例15: run_func_docstring
# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import NORMALIZE_WHITESPACE [as 別名]
def run_func_docstring(tester, test_func, globs=None, verbose=False, compileflags=None, optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE):
"""
Similar to doctest.run_docstring_examples, but takes a single function/bound method,
extracts it's singular docstring (no looking for subobjects with tests),
runs it, and most importantly raises an exception if the test doesn't pass.
tester should be an instance of dtest.Tester
test_func should be a function/bound method the docstring to be tested
"""
name = test_func.__name__
if globs is None:
globs = build_doc_context(tester, name)
# dumb function that remembers values that it is called with
# the DocTestRunner.run function called below accepts a callable for logging
# and this is a hacky but easy way to capture the nicely formatted value for reporting
def test_output_capturer(content):
if not hasattr(test_output_capturer, 'content'):
test_output_capturer.content = ''
test_output_capturer.content += content
test = doctest.DocTestParser().get_doctest(inspect.getdoc(test_func), globs, name, None, None)
runner = doctest.DocTestRunner(verbose=verbose, optionflags=optionflags)
runner.run(test, out=test_output_capturer, compileflags=compileflags)
failed, attempted = runner.summarize()
if failed > 0:
raise RuntimeError("Doctest failed! Captured output:\n{}".format(test_output_capturer.content))
if failed + attempted == 0:
raise RuntimeError("No tests were run!")