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
|
import imp
import os
from spec import Spec, eq_, raises
from invoke.loader import Loader, FilesystemLoader as FSLoader
from invoke.collection import Collection
from invoke.exceptions import CollectionNotFound
from _utils import support
class _BasicLoader(Loader):
"""
Tests top level Loader behavior with basic finder stub.
Used when we want to make sure we're testing Loader.load and not e.g.
FilesystemLoader's specific implementation.
"""
def find(self, name):
self.fd, self.path, self.desc = t = imp.find_module(name, [support])
return t
class Loader_(Spec):
def adds_module_parent_dir_to_sys_path(self):
# Crummy doesn't-explode test.
_BasicLoader().load('namespacing')
def closes_opened_file_object(self):
loader = _BasicLoader()
loader.load('foo')
assert loader.fd.closed
def can_load_package(self):
loader = _BasicLoader()
# make sure it doesn't explode
loader.load('package')
class FilesystemLoader_(Spec):
def setup(self):
self.l = FSLoader(start=support)
def exposes_discovery_start_point(self):
start = '/tmp/'
eq_(FSLoader(start=start).start, start)
def has_a_default_discovery_start_point(self):
eq_(FSLoader().start, os.getcwd())
def returns_collection_object_if_name_found(self):
result = self.l.load('foo')
eq_(type(result), Collection)
@raises(CollectionNotFound)
def raises_CollectionNotFound_if_not_found(self):
self.l.load('nope')
@raises(ImportError)
def raises_ImportError_if_found_collection_cannot_be_imported(self):
# Instead of masking with a CollectionNotFound
self.l.load('oops')
def searches_towards_root_of_filesystem(self):
# Loaded while root is in same dir as .py
directly = self.l.load('foo')
# Loaded while root is multiple dirs deeper than the .py
deep = os.path.join(support, 'ignoreme', 'ignoremetoo')
indirectly = FSLoader(start=deep).load('foo')
eq_(directly, indirectly)
def defaults_to_tasks_collection(self):
"defaults to 'tasks' collection"
result = FSLoader(start=support + '/implicit/').load()
eq_(type(result), Collection)
|