Python doctest.REPORT_NDIFF Examples
The following are 14
code examples of doctest.REPORT_NDIFF().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
doctest
, or try the search function
.
Example #1
Source File: column.py From LearningApacheSpark with MIT License | 6 votes |
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)
Example #2
Source File: doctest.py From python-netsurv with MIT License | 5 votes |
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]
Example #3
Source File: doctest.py From python-netsurv with MIT License | 5 votes |
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]
Example #4
Source File: doctest.py From pytest with MIT License | 5 votes |
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]
Example #5
Source File: streaming.py From LearningApacheSpark with MIT License | 5 votes |
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)
Example #6
Source File: dataframe.py From LearningApacheSpark with MIT License | 5 votes |
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)
Example #7
Source File: group.py From LearningApacheSpark with MIT License | 5 votes |
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)
Example #8
Source File: readwriter.py From LearningApacheSpark with MIT License | 5 votes |
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)
Example #9
Source File: test_text.py From tree-format with Apache License 2.0 | 5 votes |
def test_acceptance(self): output = self.format_tree(ACCEPTANCE_INPUT) self.assertThat( output, DocTestMatches( ACCEPTANCE_OUTPUT, doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF))
Example #10
Source File: test_testresult.py From pth-toolkit with BSD 2-Clause "Simplified" License | 5 votes |
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))
Example #11
Source File: test_docs.py From lpts with GNU General Public License v2.0 | 5 votes |
def test_suite(): m = doctest.Manuel(optionflags=REPORT_NDIFF|ELLIPSIS) return TestSuite(m, *tests, setUp=setUp, tearDown=tearDown)
Example #12
Source File: test_mod_docs.py From PsyNeuLink with Apache License 2.0 | 5 votes |
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)
Example #13
Source File: test_doctest.py From ironpython2 with Apache License 2.0 | 4 votes |
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 ######################################################################
Example #14
Source File: test_doctest.py From android_universal with MIT License | 4 votes |
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 ######################################################################