1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
import os
import pytest
from buildstream._exceptions import LoadError, LoadErrorReason
from buildstream._loader import Loader, MetaElement
from . import make_loader
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'basics',
)
##############################################################
# Basics: Test behavior loading the simplest of projects #
##############################################################
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_one_file(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/onefile.bst'])
element = loader.load()[0]
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_missing_file(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/missing.bst'])
with pytest.raises(LoadError) as exc:
element = loader.load()[0]
assert (exc.value.reason == LoadErrorReason.MISSING_FILE)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_invalid_reference(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/badreference.bst'])
with pytest.raises(LoadError) as exc:
element = loader.load()[0]
assert (exc.value.reason == LoadErrorReason.INVALID_YAML)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_invalid_yaml(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/badfile.bst'])
with pytest.raises(LoadError) as exc:
element = loader.load()[0]
assert (exc.value.reason == LoadErrorReason.INVALID_YAML)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_fail_fullpath_target(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
fullpath = os.path.join(basedir, 'elements', 'onefile.bst')
with pytest.raises(LoadError) as exc:
loader = make_loader(basedir, [fullpath])
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_invalid_key(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/invalidkey.bst'])
with pytest.raises(LoadError) as exc:
element = loader.load()[0]
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
def test_invalid_directory_load(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = make_loader(basedir, ['elements/'])
with pytest.raises(LoadError) as exc:
element = loader.load()[0]
assert (exc.value.reason == LoadErrorReason.LOADING_DIRECTORY)
|