コード例 #1
0
def doctests(path):
    buf = StringIO()
    with(state(sys, stdout=buf)):
        doctest.testfile(path)
    res = buf.getvalue()
    if res != '':
        raise Exception(res)
コード例 #2
0
 def lint() -> Tuple[int, str, str]:
     print('     flake8...')
     from flake8.api import legacy as flake8  # type: ignore
     out, err = io.StringIO(), io.StringIO()
     guide = flake8.get_style_guide()
     with state(sys, stdout=out, stderr=err):
         report = guide.check_files('.')
     return (report.total_errors, out.getvalue(), err.getvalue())
コード例 #3
0
def doctests(path):
    buf = StringIO()
    with state(sys, stdout=buf):
        doctest.testfile(path)
    res = buf.getvalue()
    if res != '':
        # import ipdb; ipdb.set_trace()
        raise Exception(res)
コード例 #4
0
ファイル: testing.py プロジェクト: jacob414/micropy
    def style() -> Tuple[int, str, str]:
        """Runs pycodestyle, unpleasantly white-boxy call.  ..but it doesn't
         seem to be written for integration, so:

        """
        print('     pycodestyle...')
        code = 0
        warn, err = io.StringIO(), io.StringIO()
        with state(sys, argv=[], stdout=warn, stderr=err):
            try:
                pycodestyle._main()
            except SystemExit as exc:
                code = exc.code
        return code, warn.getvalue(), err.getvalue()
コード例 #5
0
def test_state_dict_extra(dct):
    with state(dct, b=2, c=3):
        assert dct == {'a':1, 'b':2, 'c':3}
    assert dct == {'a':1}
コード例 #6
0
def test_state_obj_forget(obj):
    with state(obj, a=forget):
        assert not hasattr(obj, 'a')
    assert obj.a == 1
コード例 #7
0
def test_state_obj_extra(obj):
    with state(obj, b=2, c=3):
        assert obj.b == 2
        assert obj.c == 3
    assert not hasattr(obj, 'b')
    assert not hasattr(obj, 'c')
コード例 #8
0
def test_state_obj_raises(obj):
    with raises(CertainException):
        with state(obj, a=2):
            raise CertainException()
    assert obj.a == 1
コード例 #9
0
def test_deny_module():
    with pytest.raises(ImportError):
        with state(sys.modules, shutil=None):
            import shutil
コード例 #10
0
def test_os_environ():
    with state(os.environ, ALTERED='states'):
        assert os.environ['ALTERED'] == 'states'

    assert 'ALTERED' not in os.environ
コード例 #11
0
def test_state_obj_extra(obj):
    with state(obj, b=2, c=3):
        assert obj.b == 2
        assert obj.c == 3
    assert not hasattr(obj, 'b')
    assert not hasattr(obj, 'c')
コード例 #12
0
def test_nested_context():
    "Should handle nested context managers correctly"
    env = Expando(foo='bar', bar='baz')
    with state(env, foo='baz') as _, state(env, bar='foo') as _:
        assert env.foo == 'baz'
        assert env.bar == 'foo'
コード例 #13
0
def test_deny_module():
    with pytest.raises(ImportError):
        with state(sys.modules, shutil=None):
            import shutil
コード例 #14
0
def test_getitem_overridable(w_getitem):
    with state(w_getitem, any='changed'):
        assert w_getitem.any == 'changed'
コード例 #15
0
def test_os_environ():
    with state(os.environ, ALTERED='states'):
        assert os.environ['ALTERED'] == 'states'

    assert 'ALTERED' not in os.environ
コード例 #16
0
def test_state_dict_forget(dct):
    with state(dct, a=forget):
        assert dct == {}
    assert dct == {'a':1}
コード例 #17
0
def test_patch_sys_modules():
    with (state(sys.modules, fakey=Expando(foo='bar'))):
        import fakey
        assert fakey.foo == 'bar'
    with (pytest.raises(ImportError)):
        import fakey
コード例 #18
0
def test_state_obj_overwrite(obj):
    with state(obj, a=2):
        assert obj.a == 2
    assert obj.a == 1
コード例 #19
0
def test_getitem_overridable(w_getitem):
    with state(w_getitem, any='changed'):
        assert w_getitem.any == 'changed'
コード例 #20
0
def test_state_obj_forget(obj):
    with state(obj, a=forget):
        assert not hasattr(obj, 'a')
    assert obj.a == 1
コード例 #21
0
def test_nested_context():
    "Should handle nested context managers correctly"
    env = Expando(foo='bar', bar='baz')
    with state(env, foo='baz') as _, state(env, bar='foo') as _:
        assert env.foo == 'baz'
        assert env.bar == 'foo'
コード例 #22
0
def test_state_obj_raises(obj):
    with raises(CertainException):
        with state(obj, a=2):
            raise CertainException()
    assert obj.a == 1
コード例 #23
0
def test_state_dct_raises(dct):
    with raises(CertainException):
        with state(dct, a=2):
            raise CertainException()
    assert dct['a'] == 1
コード例 #24
0
def test_state_dict_extra(dct):
    with state(dct, b=2, c=3):
        assert dct == {'a': 1, 'b': 2, 'c': 3}
    assert dct == {'a': 1}
コード例 #25
0
def test_state_dict_overwrite(dct):
    with state(dct, a=2):
        assert dct == {'a': 2}
    assert dct == {'a': 1}
コード例 #26
0
def test_state_dict_forget(dct):
    with state(dct, a=forget):
        assert dct == {}
    assert dct == {'a': 1}
コード例 #27
0
def test_state_obj_overwrite(obj):
    with state(obj, a=2):
        assert obj.a == 2
    assert obj.a == 1
コード例 #28
0
def test_state_dct_raises(dct):
    with raises(CertainException):
        with state(dct, a=2):
            raise CertainException()
    assert dct['a'] == 1
コード例 #29
0
 def b0rked(badness):
     with state(obj, a=2):
         raise badness
コード例 #30
0
def test_capture_stdout():
    buf = py23compat.strio()
    print('Foo')
    with(state(sys, stdout=buf)):
        print('Bar')
    assert buf.getvalue() == 'Bar' + os.linesep
コード例 #31
0
def test_state_dict_overwrite(dct):
    with state(dct, a=2):
        assert dct == {'a':2}
    assert dct == {'a':1}
コード例 #32
0
def test_patch_sys_modules():
    with(state(sys.modules, fakey=Expando(foo='bar'))):
        import fakey
        assert fakey.foo == 'bar'
    with(pytest.raises(ImportError)):
        import fakey
コード例 #33
0
 def b0rked(badness):
     with state(dct, a=2):
         raise badness
コード例 #34
0
def test_capture_stdout():
    buf = py23compat.strio()
    print('Foo')
    with (state(sys, stdout=buf)):
        print('Bar')
    assert buf.getvalue() == 'Bar' + os.linesep