コード例 #1
0
def test_ma_schools():
  with session(MASCHOOLS_DIR):
    msglimit = None if pytest.config.option.verbose else 1000
    vn.run_and_verify_notebook(
      os.path.join(MASCHOOLS_DIR, "MASchoolDistricts"),
      msglimit=msglimit,
      required=[('schools2.quick_explore_vars\(\[',
                 [vn.allow_warns('matplotlib.*backend'),
                  vn.allow_warns('VisibleDeprecationWarning')]),
                ('ESTIMATE DEPENDENCE PROBABILITY',
                 [vn.assert_has_png(), vn.allow_warns('FutureWarning'),
                  vn.allow_warns('VisibleDeprecationWarning')]),
                ('schools0.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                ('schools1.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                # Once solved, this will not contain categorical, but as
                # set up to be solved, it does:
                ('schools2.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                # As set up, this should have "cannot convert" messages,
                # Not once it's solved though.
                ('df.applymap', [vn.assert_stream_matches('Cannot convert')]),
                (r'schools2.quick_explore_vars',
                 [vn.allow_warns('VisibleDeprecationWarning')])
                ])
コード例 #2
0
ファイル: test_maschools.py プロジェクト: jayelm/bdbcontrib
def test_ma_schools():
  do_not_track(MASCHOOLS_DIR)
  msglimit = None if pytest.config.option.verbose else 1000
  vn.run_and_verify_notebook(
      os.path.join(MASCHOOLS_DIR, "MASchoolDistricts"),
      msglimit=msglimit,
      required=[('schools2.quick_explore_vars\(\[',
                 [vn.assert_warns('matplotlib.*backend')]),
                ('schools0.quick_describe_columns()', [r'categorical']),
                ('schools1.quick_describe_columns()', [r'categorical']),
                # Once solved, this will not contain categorical, but as
                # set up to be solved, it does:
                ('schools2.quick_describe_columns()', [r'categorical']),
                # As set up, this should have "cannot convert" messages,
                # Not once it's solved though.
                ('df.applymap', [vn.assert_stream_matches('Cannot convert')]),
                ])
コード例 #3
0
def test_exhaustive():
    errs = []
    vn.check_results(datafiles('missing-bdb'), errstream=errs,
        exhaustive=[
            (r'quickstart', [vn.assert_raises("No bdb in")]),
            (r'import matplotlib', [vn.assert_warns(r'prop_cycle')])])
    assert 40 == len(errs)
    assert "Expected /quickstart/\nFound: # Exploring" in str(errs[0])
    assert "Expected /import matplotlib/\nFound: # Load" in str(errs[1])
    assert "Unexpected cell at end: Cell[2]:" in str(errs[2])
    assert "SessionOrchestrator" in str(errs[2])

    errs = []
    def recordTrue(i, c, d):
        errs.append((i, c, d))
        return True


    expected = [
        (r'# Exploring',
         [vn.assert_markdown_matches(r'Union of Concerned Scientists'),
          r'database',
          vn.assert_markdown_not("foobarbaz")]),
        (r'quickstart', [vn.assert_raises("No bdb in")]),
        (r'session-saving', [vn.assert_no_pyout()]),
        (r'Querying the data', [recordTrue, "SQL", recordTrue]),
        (r'satellites', ["Purpose", recordTrue, "Multinational",
                         vn.assert_pyout_matches("launch_vehicle", flags=re.I),
                         vn.assert_stream_matches(r"BQL \[SELECT \* FROM"),
                         # "well-known satellites" is in the input:
                         vn.assert_pyout_not("well-known satellites")]),
        # From here on out, tests fail in various ways.
        (r'do not match', []),   # 5
        ('do not match', []),    # 6
        (''),                    # 7
        ([]),                    # 8
        (),                      # 9
        ('', [], 'foo'),         # 10
        ('', [vn.assert_no_pyout(),  # One failure per cell,
              lambda i, c, d: 'c' + 5]),  # So this never runs, so no TypeError.
        ('', [vn.assert_markdown_matches('')]),  # 12
        ('', [vn.assert_pyout_matches('')]),     # 13
        ('', [vn.assert_markdown_not('')]),      # 14
        ('', [vn.assert_pyout_not('')]),         # 15
        ('', [vn.assert_markdown_not('')]),      # 16
        ('', [vn.assert_markdown_not('')]),      # 17
        ('', [vn.assert_pyout_not('')]),         # 18
        ('', []),
        ('', []),
        ('', [vn.assert_has_png()]),
        ('', []),
        ('', [vn.assert_has_png()]),
        ('', []),
        ('', []),
        ('', [vn.assert_stream_not('')]),
        ('', [lambda i, c, d: False]),
        ('', [lambda i, c, d: []]),
        ('', [lambda i, c, d: None]),
        ]
    expected += [('', [])] * (40 - len(expected) - 1)  # 40 total cells.
    vn.check_results(datafiles('missing-bdb'), errstream=errs,
                     exhaustive=expected)
    assert 3 == errs.pop(0)[0] # cell_i from the first recordTrue
    assert 3 == errs.pop(0)[0]
    assert 4 == errs.pop(0)[0]
    assert "/do not match/" in str(errs.pop(0))
    assert "/do not match/" in str(errs.pop(0))
    assert "Expected an input pattern and a list of tests" in str(errs.pop(0))
    assert "Expected an input pattern and a list of tests" in str(errs.pop(0))
    assert "Expected an input pattern and a list of tests" in str(errs.pop(0))
    assert "Expected an input pattern and a list of tests" in str(errs.pop(0))
    assert "Expected code cell" in str(errs.pop(0))
    assert "Expected markdown cell" in str(errs.pop(0))
    assert "Expected code cell" in str(errs.pop(0))
    assert "Expected markdown cell" in str(errs.pop(0))
    assert "Expected code cell" in str(errs.pop(0))
    assert "Expected markdown cell" in str(errs.pop(0))
    assert "Expected not to find" in str(errs.pop(0))
    assert "Expected not to find" in str(errs.pop(0))
    assert "Expected not to find" in str(errs.pop(0))
    assert "returned False" in str(errs.pop(0))
    assert "returned []" in str(errs.pop(0))
    assert "returned None" in str(errs.pop(0))
    assert "Undeclared png" in str(errs.pop(0))
    assert "Unexpected cell at end" in str(errs.pop(0))
    assert [] == errs

    expected = [('', [])] * 40   # 40 total cells
    expected += [('foobarbaz', [])] * 2
    vn.check_results(datafiles('missing-bdb'), errstream=errs,
                     exhaustive=expected)
    assert "Expected pattern /foobarbaz/ not found" in str(errs[-1])
    assert "Expected pattern /foobarbaz/ not found" in str(errs[-2])
    assert 8 == len(errs)  # Those two plus the six undeclared displays.