summaryrefslogtreecommitdiff
path: root/tests/format
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-07-09 16:49:13 +0200
committerJürg Billeter <j@bitron.ch>2019-07-16 15:36:10 +0200
commit0bfad0b0eac1400573f06b134583365f620f1a8e (patch)
tree1011d115164159f7deaf5447160aa50ad8464c88 /tests/format
parentf62b5f26adcdee8ab7cbf739cc5d2388ba25aefe (diff)
downloadbuildstream-0bfad0b0eac1400573f06b134583365f620f1a8e.tar.gz
tests/format/include_composition.py: Use dummy_context()
Diffstat (limited to 'tests/format')
-rw-r--r--tests/format/include_composition.py163
1 files changed, 84 insertions, 79 deletions
diff --git a/tests/format/include_composition.py b/tests/format/include_composition.py
index f764b16a6..ec48d82a2 100644
--- a/tests/format/include_composition.py
+++ b/tests/format/include_composition.py
@@ -1,146 +1,151 @@
import os
-from buildstream._context import Context
+
+from contextlib import contextmanager
+
from buildstream._project import Project
from buildstream._includes import Includes
from buildstream import _yaml
+from tests.testutils import dummy_context
+
+@contextmanager
def make_includes(basedir):
_yaml.roundtrip_dump({'name': 'test'}, os.path.join(basedir, 'project.conf'))
- context = Context()
- project = Project(basedir, context)
- loader = project.loader
- return Includes(loader)
+ with dummy_context() as context:
+ project = Project(basedir, context)
+ loader = project.loader
+ yield Includes(loader)
def test_main_has_priority(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': ['main']},
- str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': ['main']},
+ str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['main']
+ assert main.get_sequence('test').as_str_list() == ['main']
def test_include_cannot_append(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': ['main']},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': ['main']},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': {'(>)': ['a']}},
- str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': {'(>)': ['a']}},
+ str(tmpdir.join('a.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['main']
+ assert main.get_sequence('test').as_str_list() == ['main']
def test_main_can_append(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': {'(>)': ['main']}},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml'], 'test': {'(>)': ['main']}},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['a', 'main']
+ assert main.get_sequence('test').as_str_list() == ['a', 'main']
def test_sibling_cannot_append_backward(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': {'(>)': ['a']}},
- str(tmpdir.join('a.yml')))
- _yaml.roundtrip_dump({'test': ['b']},
- str(tmpdir.join('b.yml')))
+ _yaml.roundtrip_dump({'test': {'(>)': ['a']}},
+ str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': ['b']},
+ str(tmpdir.join('b.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['b']
+ assert main.get_sequence('test').as_str_list() == ['b']
def test_sibling_can_append_forward(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': ['a']},
- str(tmpdir.join('a.yml')))
- _yaml.roundtrip_dump({'test': {'(>)': ['b']}},
- str(tmpdir.join('b.yml')))
+ _yaml.roundtrip_dump({'test': ['a']},
+ str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': {'(>)': ['b']}},
+ str(tmpdir.join('b.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['a', 'b']
+ assert main.get_sequence('test').as_str_list() == ['a', 'b']
def test_lastest_sibling_has_priority(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml']},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': ['a']},
- str(tmpdir.join('a.yml')))
- _yaml.roundtrip_dump({'test': ['b']},
- str(tmpdir.join('b.yml')))
+ _yaml.roundtrip_dump({'test': ['a']},
+ str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': ['b']},
+ str(tmpdir.join('b.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['b']
+ assert main.get_sequence('test').as_str_list() == ['b']
def test_main_keeps_keys(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml'], 'something': 'else'},
- str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml'], 'something': 'else'},
+ str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
+ _yaml.roundtrip_dump({'test': ['a']}, str(tmpdir.join('a.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['a']
- assert main.get_str('something') == 'else'
+ assert main.get_sequence('test').as_str_list() == ['a']
+ assert main.get_str('something') == 'else'
def test_overwrite_directive_on_later_composite(tmpdir):
- includes = make_includes(str(tmpdir))
+ with make_includes(str(tmpdir)) as includes:
- _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml'], 'test': {'(=)': ['Overwritten']}},
- str(tmpdir.join('main.yml')))
+ _yaml.roundtrip_dump({'(@)': ['a.yml', 'b.yml'], 'test': {'(=)': ['Overwritten']}},
+ str(tmpdir.join('main.yml')))
- main = _yaml.load(str(tmpdir.join('main.yml')))
+ main = _yaml.load(str(tmpdir.join('main.yml')))
- # a.yml
- _yaml.roundtrip_dump({'test': ['some useless', 'list', 'to be overwritten'],
- 'foo': 'should not be present'},
- str(tmpdir.join('a.yml')))
+ # a.yml
+ _yaml.roundtrip_dump({'test': ['some useless', 'list', 'to be overwritten'],
+ 'foo': 'should not be present'},
+ str(tmpdir.join('a.yml')))
- # b.yaml isn't going to have a 'test' node to overwrite
- _yaml.roundtrip_dump({'foo': 'should be present'},
- str(tmpdir.join('b.yml')))
+ # b.yaml isn't going to have a 'test' node to overwrite
+ _yaml.roundtrip_dump({'foo': 'should be present'},
+ str(tmpdir.join('b.yml')))
- includes.process(main)
+ includes.process(main)
- assert main.get_sequence('test').as_str_list() == ['Overwritten']
- assert main.get_str('foo') == 'should be present'
+ assert main.get_sequence('test').as_str_list() == ['Overwritten']
+ assert main.get_str('foo') == 'should be present'