Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/plugin_importer/tests/test_plugin_importer.py
- This file was added.
1 | import os | ||||
---|---|---|---|---|---|
2 | import pytest | ||||
3 | from tempfile import TemporaryDirectory | ||||
4 | from unittest import TestCase | ||||
5 | | ||||
6 | | ||||
7 | from .. plugin_importer import PluginImporter, PluginReadError | ||||
8 | | ||||
9 | | ||||
10 | class PluginImporterTestCase(TestCase): | ||||
11 | | ||||
12 | def setUp(self): | ||||
13 | self.resources_dir = TemporaryDirectory() | ||||
14 | self.plugin_dir = TemporaryDirectory() | ||||
15 | | ||||
16 | def tearDown(self): | ||||
17 | self.resources_dir.cleanup() | ||||
18 | self.plugin_dir.cleanup() | ||||
19 | | ||||
20 | @property | ||||
21 | def zip_filename(self): | ||||
22 | return os.path.join( | ||||
23 | self.resources_dir.name, 'plugin.zip') | ||||
24 | | ||||
25 | def test_zipfile_doesnt_exist(self): | ||||
26 | with pytest.raises(PluginReadError): | ||||
27 | PluginImporter(self.zip_filename, | ||||
28 | self.resources_dir.name, | ||||
29 | lambda x: True) | ||||
30 | | ||||
31 | def test_zipfile_not_a_zip(self): | ||||
32 | with open(self.zip_filename, 'w') as f: | ||||
33 | f.write('foo') | ||||
34 | with pytest.raises(PluginReadError): | ||||
35 | PluginImporter(self.zip_filename, | ||||
36 | self.resources_dir.name, | ||||
37 | lambda x: True) |