示例#1
0
def test_info():

    info = """
package:
  name: the name
  version: 1.0
  description: some text here

a:
  - 1
  - 42
b: bla
c:
  answer: 42
  foo: bar
  key: value
"""

    with tempdir() as dirpath:
        filename = join(dirpath, 'test.pkg')
        with open(filename, 'w') as f:
            f.write(info)

        doc = load_info(filename)
        assert doc.package.name == 'the name'
        assert doc.package.version == 1.0
        assert doc.package.description == 'some text here'
        assert doc.a[0] == 1
        assert doc.c.answer == 42
        assert doc.c.key == 'value'
示例#2
0
def test_simple():

    script="""
from faber.tools.compiler import include
i = include('.')"""

    with tempdir() as dirpath:
        write_fabscript(dirpath, script)
        m = module(dirpath)
        assert dirpath in m.i
示例#3
0
def test_no_feature():

    script = """
from faber.feature import set
from faber.tools.compiler import include

fs = set()
d = fs.define"""

    with tempdir() as dirpath:
        write_fabscript(dirpath, script)
        with pytest.raises(ScriptError) as e:
            m = module(dirpath)  # noqa F841
        assert e.value.lineno == 6 and 'no feature' in e.value.message
示例#4
0
def test_kwds():

    outer="""
from faber.tools.compiler import include, linkpath
value = 24
inner = module('inner', value=value)"""

    inner="""
"""

    with tempdir() as root:
        subdir = os.path.join(root, 'inner')
        os.mkdir(subdir)
        write_fabscript(root, outer)
        write_fabscript(subdir, inner)
        m = module(root, builddir='build')
        assert m.inner.value == m.value
示例#5
0
def test_no_compiler():

    script = """
from faber.types import cxx
from faber.tools.compiler import target
from faber.config.try_compile import try_compile
features |= target(arch='impossible')
src='int main() {}'
t=try_compile('test', src, cxx, features=features)
default=t
"""

    with tempdir() as dirpath:
        write_fabscript(dirpath, script)
        with pytest.raises(ScriptError) as e:
            m = module(dirpath)  # noqa F841
        assert 'no C++ compiler found' in e.value.message
        # close open files so we can remove dirpath
        from faber import config
        config.finish()
示例#6
0
def test_failure(fail):

    script = """
from faber.test import test, report
passing = rule(action('true', 'echo 1'), 'passing', attrs=always|notfile)
failing = rule(action('false', 'unknown'), 'failing', attrs=always|notfile)
test1 = test('t1', passing)
test2 = test('t2', failing)
r = report('report', [test1, test2], fail_on_failures={})
default = r
""".format(fail)

    python = sys.executable
    faber = abspath(join('scripts', 'faber'))
    cmd = [python, faber]

    with tempdir() as dirpath:
        write_fabscript(dirpath, script)
        if fail:
            with pytest.raises(subprocess.CalledProcessError):
                subprocess.check_output(cmd + ['--srcdir={}'.format(dirpath)])
        else:
            subprocess.check_output(cmd + ['--srcdir={}'.format(dirpath)])