예제 #1
0
def test_config_marshability():
    tmp = py.test.ensuretemp("configmarshal") 
    tmp.ensure("__init__.py")
    tmp.ensure("conftest.py").write("a = object()")
    config = py.test.config._reparse([tmp])
    py.test.raises(ValueError, "config._makerepr(conftestnames=['a'])")

    config.option.hello = lambda x: None
    py.test.raises(ValueError, "config._makerepr(conftestnames=[])")
    config._makerepr(conftestnames=[], optnames=[])
예제 #2
0
def test_config_make_and__mergerepr():
    tmp = py.test.ensuretemp("reprconfig1")
    tmp.ensure("__init__.py")
    tmp.ensure("conftest.py").write("x=1")
    config = py.test.config._reparse([tmp])
    repr = config._makerepr(conftestnames=['x'])
    config.option.verbose = 42
    repr2 = config._makerepr(conftestnames=[], optnames=['verbose'])
    config = py.test.config._reparse([tmp.dirpath()])
    py.test.raises(KeyError, "config.getvalue('x')")
    config._mergerepr(repr)
    assert config.getvalue('x') == 1
    config._mergerepr(repr2) 
    assert config.option.verbose == 42
예제 #3
0
def test_config_init_direct():
    tmp = py.test.ensuretemp("_initdirect")
    tmp.ensure("__init__.py")
    tmp.ensure("conftest.py").write("x=1 ; y=2")
    hello = tmp.ensure("test_hello.py")
    config = py.test.config._reparse([hello])
    repr = config._makerepr(conftestnames=['x', 'y'])
    config2 = py.test.config._reparse([tmp.dirpath()])
    config2._initialized = False # we have to do that from tests
    config2._initdirect(topdir=tmp.dirpath(), repr=repr)
    for col1, col2 in zip(config.getcolitems(), config2.getcolitems()):
        assert col1.fspath == col2.fspath
    py.test.raises(AssertionError, "config2._initdirect(None, None)")
    from py.__.test.config import Config
    config3 = Config()
    config3._initdirect(topdir=tmp.dirpath(), repr=repr,
        coltrails=[(tmp.basename, (hello.basename,))])
    assert config3.getvalue('x') == 1
    assert config3.getvalue('y') == 2
    cols = config.getcolitems()
    assert len(cols) == 1
    col = cols[0]
    assert col.name == 'test_hello.py'
    assert col.parent.name == tmp.basename 
    assert col.parent.parent is None 
예제 #4
0
def test_config_rconfig():
    tmp = py.test.ensuretemp("rconfigopt")
    tmp.ensure("__init__.py")
    tmp.ensure("conftest.py").write(py.code.Source("""
    import py
    Option = py.test.config.Option
    option = py.test.config.addoptions("testing group", 
            Option('-G', '--glong', action="store", default=42,
                   type="int", dest="gdest", help="g value."))
    """))
    config = py.test.config._reparse([tmp, "-G", "11"])
    assert config.option.gdest == 11
    repr = config._makerepr(conftestnames=[])
    config = py.test.config._reparse([tmp.dirpath()])
    py.test.raises(AttributeError, "config.option.gdest")
    config._mergerepr(repr) 
    assert config.option.gdest == 11