本文整理汇总了Python中doctest.REPORT_NDIFF属性的典型用法代码示例。如果您正苦于以下问题:Python doctest.REPORT_NDIFF属性的具体用法?Python doctest.REPORT_NDIFF怎么用?Python doctest.REPORT_NDIFF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类doctest
的用法示例。
在下文中一共展示了doctest.REPORT_NDIFF属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [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)
示例2: _get_report_choice
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _get_report_choice(key):
"""
This function returns the actual `doctest` module flag value, we want to do it as late as possible to avoid
importing `doctest` and all its dependencies when parsing options, as it adds overhead and breaks tests.
"""
import doctest
return {
DOCTEST_REPORT_CHOICE_UDIFF: doctest.REPORT_UDIFF,
DOCTEST_REPORT_CHOICE_CDIFF: doctest.REPORT_CDIFF,
DOCTEST_REPORT_CHOICE_NDIFF: doctest.REPORT_NDIFF,
DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILURE: doctest.REPORT_ONLY_FIRST_FAILURE,
DOCTEST_REPORT_CHOICE_NONE: 0,
}[key]
示例3: _get_report_choice
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _get_report_choice(key: str) -> int:
"""
This function returns the actual `doctest` module flag value, we want to do it as late as possible to avoid
importing `doctest` and all its dependencies when parsing options, as it adds overhead and breaks tests.
"""
import doctest
return {
DOCTEST_REPORT_CHOICE_UDIFF: doctest.REPORT_UDIFF,
DOCTEST_REPORT_CHOICE_CDIFF: doctest.REPORT_CDIFF,
DOCTEST_REPORT_CHOICE_NDIFF: doctest.REPORT_NDIFF,
DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILURE: doctest.REPORT_ONLY_FIRST_FAILURE,
DOCTEST_REPORT_CHOICE_NONE: 0,
}[key]
示例4: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _test():
import doctest
import os
import tempfile
from pyspark.sql import Row, SparkSession, SQLContext
import pyspark.sql.streaming
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.streaming.__dict__.copy()
try:
spark = SparkSession.builder.getOrCreate()
except py4j.protocol.Py4JError:
spark = SparkSession(sc)
globs['tempfile'] = tempfile
globs['os'] = os
globs['spark'] = spark
globs['sqlContext'] = SQLContext.getOrCreate(spark.sparkContext)
globs['sdf'] = \
spark.readStream.format('text').load('python/test_support/sql/streaming')
globs['sdf_schema'] = StructType([StructField("data", StringType(), False)])
globs['df'] = \
globs['spark'].readStream.format('text').load('python/test_support/sql/streaming')
(failure_count, test_count) = doctest.testmod(
pyspark.sql.streaming, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
globs['spark'].stop()
if failure_count:
sys.exit(-1)
示例5: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _test():
import doctest
from pyspark.context import SparkContext
from pyspark.sql import Row, SQLContext, SparkSession
import pyspark.sql.dataframe
from pyspark.sql.functions import from_unixtime
globs = pyspark.sql.dataframe.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
globs['sc'] = sc
globs['sqlContext'] = SQLContext(sc)
globs['spark'] = SparkSession(sc)
globs['df'] = sc.parallelize([(2, 'Alice'), (5, 'Bob')])\
.toDF(StructType([StructField('age', IntegerType()),
StructField('name', StringType())]))
globs['df2'] = sc.parallelize([Row(name='Tom', height=80), Row(name='Bob', height=85)]).toDF()
globs['df3'] = sc.parallelize([Row(name='Alice', age=2),
Row(name='Bob', age=5)]).toDF()
globs['df4'] = sc.parallelize([Row(name='Alice', age=10, height=80),
Row(name='Bob', age=5, height=None),
Row(name='Tom', age=None, height=None),
Row(name=None, age=None, height=None)]).toDF()
globs['df5'] = sc.parallelize([Row(name='Alice', spy=False, age=10),
Row(name='Bob', spy=None, age=5),
Row(name='Mallory', spy=True, age=None)]).toDF()
globs['sdf'] = sc.parallelize([Row(name='Tom', time=1479441846),
Row(name='Bob', time=1479442946)]).toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.dataframe, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
globs['sc'].stop()
if failure_count:
sys.exit(-1)
示例6: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _test():
import doctest
from pyspark.sql import Row, SparkSession
import pyspark.sql.group
globs = pyspark.sql.group.__dict__.copy()
spark = SparkSession.builder\
.master("local[4]")\
.appName("sql.group tests")\
.getOrCreate()
sc = spark.sparkContext
globs['sc'] = sc
globs['spark'] = spark
globs['df'] = sc.parallelize([(2, 'Alice'), (5, 'Bob')]) \
.toDF(StructType([StructField('age', IntegerType()),
StructField('name', StringType())]))
globs['df3'] = sc.parallelize([Row(name='Alice', age=2, height=80),
Row(name='Bob', age=5, height=85)]).toDF()
globs['df4'] = sc.parallelize([Row(course="dotNET", year=2012, earnings=10000),
Row(course="Java", year=2012, earnings=20000),
Row(course="dotNET", year=2012, earnings=5000),
Row(course="dotNET", year=2013, earnings=48000),
Row(course="Java", year=2013, earnings=30000)]).toDF()
globs['df5'] = sc.parallelize([
Row(training="expert", sales=Row(course="dotNET", year=2012, earnings=10000)),
Row(training="junior", sales=Row(course="Java", year=2012, earnings=20000)),
Row(training="expert", sales=Row(course="dotNET", year=2012, earnings=5000)),
Row(training="junior", sales=Row(course="dotNET", year=2013, earnings=48000)),
Row(training="expert", sales=Row(course="Java", year=2013, earnings=30000))]).toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.group, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
spark.stop()
if failure_count:
sys.exit(-1)
示例7: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def _test():
import doctest
import os
import tempfile
import py4j
from pyspark.context import SparkContext
from pyspark.sql import SparkSession, Row
import pyspark.sql.readwriter
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.readwriter.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
try:
spark = SparkSession.builder.getOrCreate()
except py4j.protocol.Py4JError:
spark = SparkSession(sc)
globs['tempfile'] = tempfile
globs['os'] = os
globs['sc'] = sc
globs['spark'] = spark
globs['df'] = spark.read.parquet('python/test_support/sql/parquet_partitioned')
(failure_count, test_count) = doctest.testmod(
pyspark.sql.readwriter, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
sc.stop()
if failure_count:
sys.exit(-1)
示例8: test_acceptance
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def test_acceptance(self):
output = self.format_tree(ACCEPTANCE_INPUT)
self.assertThat(
output,
DocTestMatches(
ACCEPTANCE_OUTPUT,
doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE |
doctest.REPORT_NDIFF))
示例9: test_stopTestRun_shows_details
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def test_stopTestRun_shows_details(self):
def run_tests():
self.result.startTestRun()
make_erroring_test().run(self.result)
make_unexpectedly_successful_test().run(self.result)
make_failing_test().run(self.result)
self.reset_output()
self.result.stopTestRun()
run_with_stack_hidden(True, run_tests)
self.assertThat(self.getvalue(),
DocTestMatches("""...======================================================================
ERROR: testtools.tests.test_testresult.Test.error
----------------------------------------------------------------------
Traceback (most recent call last):
File "...testtools...tests...test_testresult.py", line ..., in error
1/0
ZeroDivisionError:... divi... by zero...
======================================================================
FAIL: testtools.tests.test_testresult.Test.failed
----------------------------------------------------------------------
Traceback (most recent call last):
File "...testtools...tests...test_testresult.py", line ..., in failed
self.fail("yo!")
AssertionError: yo!
======================================================================
UNEXPECTED SUCCESS: testtools.tests.test_testresult.Test.succeeded
----------------------------------------------------------------------
...""", doctest.ELLIPSIS | doctest.REPORT_NDIFF))
示例10: test_suite
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def test_suite():
m = doctest.Manuel(optionflags=REPORT_NDIFF|ELLIPSIS)
return TestSuite(m, *tests,
setUp=setUp,
tearDown=tearDown)
示例11: test_other_docs
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def test_other_docs(mod, capsys):
fail, total = doctest.testmod(mod, optionflags=doctest.REPORT_NDIFF)
if fail > 0:
captured = capsys.readouterr()
pytest.fail("{} out of {} examples failed:\n{}\n{}".format(
fail, total, captured.err, captured.out), pytrace=False)
示例12: test_no_trailing_whitespace_stripping
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import REPORT_NDIFF [as 别名]
def test_no_trailing_whitespace_stripping():
r"""
The fancy reports had a bug for a long time where any trailing whitespace on
the reported diff lines was stripped, making it impossible to see the
differences in line reported as different that differed only in the amount of
trailing whitespace. The whitespace still isn't particularly visible unless
you use NDIFF, but at least it is now there to be found.
*NOTE*: This snippet was intentionally put inside a raw string to get rid of
leading whitespace error in executing the example below
>>> def f(x):
... r'''
... >>> print('\n'.join(['a ', 'b']))
... a
... b
... '''
"""
"""
*NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
using `\x20`
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.REPORT_NDIFF
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
... # doctest: +ELLIPSIS
**********************************************************************
File ..., line 3, in f
Failed example:
print('\n'.join(['a ', 'b']))
Differences (ndiff with -expected +actual):
- a
+ a
b
TestResults(failed=1, attempted=1)
*NOTE*: `\x20` is for checking the trailing whitespace on the +a line above.
We cannot use actual spaces there, as a commit hook prevents from committing
patches that contain trailing whitespace. More info on Issue 24746.
"""
######################################################################
## Main
######################################################################