summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2016-12-17 21:01:11 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2016-12-19 17:00:17 +0900
commit94c5bf788e50fed647eeb5e3dbfd9142dabcd7b0 (patch)
tree7c35311e089595117f1f239e01a23638be309324
parentcde8473361316d3218dbce485660d42106bd9670 (diff)
downloadbuildstream-94c5bf788e50fed647eeb5e3dbfd9142dabcd7b0.tar.gz
local source test: Use the common fixture thingy
-rw-r--r--tests/sources/local.py66
1 files changed, 18 insertions, 48 deletions
diff --git a/tests/sources/local.py b/tests/sources/local.py
index 23e89c324..7c7dd57bb 100644
--- a/tests/sources/local.py
+++ b/tests/sources/local.py
@@ -2,11 +2,10 @@ import os
import pytest
import tempfile
-from pluginbase import PluginBase
-from buildstream import Context, Project
from buildstream import SourceError
-from buildstream._loader import Loader
-from buildstream._sourcefactory import SourceFactory
+
+# import our common fixture
+from .fixture import Setup
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -14,42 +13,15 @@ DATA_DIR = os.path.join(
)
-# Hacked hand fashioned fixture, just a helper function
-# because it's tricky to have a pytest fixture take arguments
-#
-# datafiles: A project directory datafiles
-# target: A target element bst file
-#
-class Setup():
-
- def __init__(self, datafiles, target):
- directory = os.path.join(datafiles.dirname, datafiles.basename)
-
- self.context = Context('x86_64')
- self.project = Project(directory)
-
- loader = Loader(directory, target, None, None)
- element = loader.load()
- assert(len(element.sources) == 1)
- self.meta_source = element.sources[0]
-
- base = PluginBase(package='buildstream.plugins')
- self.factory = SourceFactory(base)
- self.source = self.factory.create(self.meta_source.kind,
- self.context,
- self.project,
- self.meta_source)
-
-
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
-def test_create_source(datafiles):
- setup = Setup(datafiles, 'target.bst')
+def test_create_source(tmpdir, datafiles):
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
-def test_preflight(datafiles):
- setup = Setup(datafiles, 'target.bst')
+def test_preflight(tmpdir, datafiles):
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
# Just expect that this passes without throwing any exception
@@ -57,8 +29,8 @@ def test_preflight(datafiles):
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
-def test_preflight_fail(datafiles):
- setup = Setup(datafiles, 'target.bst')
+def test_preflight_fail(tmpdir, datafiles):
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
# Delete the file which the local source wants
@@ -71,8 +43,8 @@ def test_preflight_fail(datafiles):
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
-def test_unique_key(datafiles):
- setup = Setup(datafiles, 'target.bst')
+def test_unique_key(tmpdir, datafiles):
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
# Get the unique key
@@ -90,20 +62,18 @@ def test_unique_key(datafiles):
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
def test_stage_file(tmpdir, datafiles):
- setup = Setup(datafiles, 'target.bst')
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
- with tempfile.TemporaryDirectory(dir=str(tmpdir)) as directory:
- setup.source.stage(directory)
- assert(os.path.exists(os.path.join(directory, 'file.txt')))
+ setup.source.stage(setup.context.builddir)
+ assert(os.path.exists(os.path.join(setup.context.builddir, 'file.txt')))
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'directory'))
def test_stage_directory(tmpdir, datafiles):
- setup = Setup(datafiles, 'target.bst')
+ setup = Setup(datafiles, 'target.bst', tmpdir)
assert(setup.source.get_kind() == 'local')
- with tempfile.TemporaryDirectory(dir=str(tmpdir)) as directory:
- setup.source.stage(directory)
- assert(os.path.exists(os.path.join(directory, 'file.txt')))
- assert(os.path.exists(os.path.join(directory, 'subdir', 'anotherfile.txt')))
+ setup.source.stage(setup.context.builddir)
+ assert(os.path.exists(os.path.join(setup.context.builddir, 'file.txt')))
+ assert(os.path.exists(os.path.join(setup.context.builddir, 'subdir', 'anotherfile.txt')))