Ronny Pfannschmidt avatar Ronny Pfannschmidt committed 03cf004

refactor how tests create the source packages they operate on

Comments (0)

Files changed (2)

tests/conftest.py

     globals()['pytest_funcarg__' + name] = lambda request, name=name: getattr(request.getfuncargvalue('config'), name)
 
 
-def pytest_funcarg__fullsource(request):
-    source = request.getfuncargvalue('config').source
-    source.join('kij.yml').write(
-            'name: test\n'
-            'scripts: [foo, bin/bar]\n'
-            'packages: [testpkg]\n'
-            )
-    source.ensure('foo')
-    source.ensure('bin/bar')
-    source.ensure('testpkg/__init__.py')
-    return source
-
 def pytest_funcarg__config(request):
     tmpdir = request.getfuncargvalue('tmpdir')
 
     for name, subdir in dirs.items():
         paths[name] = tmpdir.ensure(subdir, dir=1)
 
+    contents = getattr(request.function, 'has_source', None)
+    if contents is not None:
+        for name, content in contents.args[0].iteritems():
+            file = paths['source'].ensure(name)
+            file.write(content)
+
     return Config(paths)

tests/tasks/test_build.py

+import py
 from kij.tasks.build import CopyPackagesToBuild, CompileByteCode, \
         CopyScripts, Build
 from kij.task_queue import Queue
 
+package_contents = {
+    'testpkg/__init__.py': '',
+    'kij.yml': 'name: test\npackages: [testpkg]\n',
+}
 
-def test_copy_build(source,config):
-    source.ensure('testpkg/__init__.py')
-    source.join('kij.yml').write('name: test\npackages: [testpkg]\n')
+has_source = py.test.mark.has_source(package_contents)
+
+
+@has_source
+def test_copy_build(source, config):
     task = CopyPackagesToBuild(config)
     queue = Queue()
     queue.add(task)
     assert config.build_lib.join('testpkg/__init__.py').check()
 
 
+@has_source
 def test_build_and_compile(source, tmpdir, config, build_lib):
 
     queue = Queue()
 
-    source.ensure('testpkg/__init__.py')
-    source.join('kij.yml').write('name: test\npackages: [testpkg]\n')
-
     compile = CompileByteCode(config)
     queue.add(compile)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.