32
32
from snapcraft.tests import mock_plugin
35
class TestPlugin(tests.TestCase):
37
def get_test_plugin(self, name='mock', part_name='mock-part',
38
properties=None, load_code=False, load_config=False):
39
if properties is None:
41
return plugin.PluginHandler(
42
name, part_name, properties, load_code=load_code,
43
load_config=load_config)
35
def get_test_plugin(name='mock', part_name='mock-part',
36
properties=None, load_code=False, load_config=False):
37
if properties is None:
39
return plugin.PluginHandler(
40
name, part_name, properties, load_code=load_code,
41
load_config=load_config)
44
class PluginTestCase(tests.TestCase):
45
46
def test_init_unknown_plugin_must_log_error(self):
46
47
fake_logger = fixtures.FakeLogger(level=logging.ERROR)
47
48
self.useFixture(fake_logger)
49
self.get_test_plugin('test_unexisting_name', load_config=True)
50
get_test_plugin('test_unexisting_name', load_config=True)
52
53
'Unknown plugin: test_unexisting_name\n', fake_logger.output)
54
55
def test_is_dirty(self):
55
p = self.get_test_plugin()
56
57
p.statefile = tempfile.NamedTemporaryFile().name
57
58
self.addCleanup(os.remove, p.statefile)
65
66
self.assertFalse(p.code.pull.called)
67
68
def test_collect_snap_files(self):
68
p = self.get_test_plugin()
70
71
tmpdirObject = tempfile.TemporaryDirectory()
71
72
self.addCleanup(tmpdirObject.cleanup)
116
117
fake_logger = fixtures.FakeLogger(level=logging.INFO)
117
118
self.useFixture(fake_logger)
119
p = self.get_test_plugin()
120
p = get_test_plugin()
120
121
p.notify_stage('test stage')
122
123
self.assertEqual('test stage mock-part\n', fake_logger.output)
145
146
"mock", "mock-part", {}, load_config=False, load_code=True)
147
148
def test_collect_snap_files_with_absolute_includes_must_raise_error(self):
148
p = self.get_test_plugin()
149
p = get_test_plugin()
149
150
with self.assertRaises(plugin.PluginError) as raised:
150
151
p.collect_snap_files(includes=['rel', '/abs/include'], excludes=[])
153
154
"path '/abs/include' must be relative", str(raised.exception))
155
156
def test_collect_snap_files_with_absolute_excludes_must_raise_error(self):
156
p = self.get_test_plugin()
157
p = get_test_plugin()
157
158
with self.assertRaises(plugin.PluginError) as raised:
158
159
p.collect_snap_files(includes=[], excludes=['rel', '/abs/exclude'])
173
174
'Unknown plugin: test_unexisting_name\n'
174
175
'Could not load part test_unexisting_name\n',
175
176
fake_logger.output)
179
class PluginMakedirsTestCase(tests.TestCase):
182
('existing_dirs', {'make_dirs': True}),
183
('unexisting_dirs', {'make_dirs': False})
186
def get_plugin_dirs(self, part_name):
187
parts_dir = os.path.join(self.path, 'parts')
189
os.path.join(parts_dir, part_name, 'src'),
190
os.path.join(parts_dir, part_name, 'build'),
191
os.path.join(parts_dir, part_name, 'install'),
192
os.path.join(self.path, 'stage'),
193
os.path.join(self.path, 'snap')
196
def test_makedirs_with_existing_dirs(self):
197
part_name = 'test_part'
198
dirs = self.get_plugin_dirs(part_name)
200
os.makedirs(os.path.join('parts', part_name))
204
p = get_test_plugin(part_name=part_name)
207
self.assertTrue(os.path.exists(d), '{} does not exist'.format(d))