Beispiel #1
0
class FilesystemLoader_(Spec):
    def setup(self):
        self.l = FSLoader(start=support)

    def discovery_start_point_defaults_to_cwd(self):
        eq_(FSLoader().start, os.getcwd())

    def exposes_start_point_as_attribute(self):
        eq_(FSLoader().start, os.getcwd())

    def start_point_is_configurable_via_kwarg(self):
        start = '/tmp/'
        eq_(FSLoader(start=start).start, start)

    def start_point_is_configurable_via_config(self):
        config = Config({'tasks': {'search_root': 'nowhere'}})
        eq_(FSLoader(config=config).start, 'nowhere')

    @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)
Beispiel #2
0
class FilesystemLoader_:
    def setup(self):
        self.l = FSLoader(start=support)

    def discovery_start_point_defaults_to_cwd(self):
        assert FSLoader().start == os.getcwd()

    def exposes_start_point_as_attribute(self):
        assert FSLoader().start == os.getcwd()

    def start_point_is_configurable_via_kwarg(self):
        start = "/tmp/"
        assert FSLoader(start=start).start == start

    def start_point_is_configurable_via_config(self):
        config = Config({"tasks": {"search_root": "nowhere"}})
        assert FSLoader(config=config).start == "nowhere"

    def raises_CollectionNotFound_if_not_found(self):
        with raises(CollectionNotFound):
            self.l.load("nope")

    def raises_ImportError_if_found_collection_cannot_be_imported(self):
        # Instead of masking with a CollectionNotFound
        with raises(ImportError):
            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")
        assert directly == indirectly
Beispiel #3
0
def print_all_help():
    """
    Print help for all commands.
    """
    loader = FilesystemLoader()
    collection = loader.load()

    task_names = collection.task_names.keys()
    task_names.sort()
    for task_name in task_names:
        sys.stdout.write('\n{}:\n'.format(task_name))
        try:
            parse([invoke_bin_path(), '--help', task_name], collection)
        except Exit:
            pass
Beispiel #4
0
def print_all_help():
    """
    Print help for all commands.
    """
    loader = FilesystemLoader()
    collection = loader.load()

    task_names = collection.task_names.keys()
    task_names.sort()
    for task_name in task_names:
        sys.stdout.write('\n{}:\n'.format(task_name))
        try:
            parse([invoke_bin_path(), '--help', task_name], collection)
        except Exit:
            pass
Beispiel #5
0
def run_local_task(argv):
    """
    Run task in user's project directory.
    """
    task = argv[1]
    from invoke.loader import FilesystemLoader
    try:
        tasks = FilesystemLoader().load().task_names
    except CollectionNotFound:
        raise TaskNotAvailable(task)
    if task == '.':
        display_local_tasks()
        return
    if not task in tasks.keys():
        raise TaskNotAvailable(task)
    cli.dispatch(argv)
Beispiel #6
0
def run_local_task(argv):
    """
    Run task in user's project directory.
    """
    task = argv[1]
    from invoke.loader import FilesystemLoader
    try:
        tasks = FilesystemLoader().load().task_names
    except CollectionNotFound:
        raise TaskNotAvailable(task)
    if task == '.':
        display_local_tasks()
        return
    if not task in tasks.keys():
        raise TaskNotAvailable(task)
    cli.dispatch(argv)
Beispiel #7
0
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"
        # There's a basic tasks.py in tests/_support
        result = self.l.load()
        eq_(type(result), Collection)
Beispiel #8
0
 def setup(self):
     self.loader = Loader(start=support)
     self.vanilla = self.loader.load("decorator")
Beispiel #9
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(start=support)
        self.vanilla = self.loader.load("decorator")

    def allows_access_to_wrapped_object(self):
        def lolcats():
            pass

        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla["foo"], self.vanilla["bar"])

    def allows_multiple_aliases(self):
        eq_(self.vanilla["foo"], self.vanilla["otherbar"])

    def allows_default_specification(self):
        eq_(self.vanilla[""], self.vanilla["biz"])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load("decorator_multi_default")

    def sets_arg_help(self):
        eq_(self.vanilla["punch"].help["why"], "Motive")

    def sets_arg_kind(self):
        skip()

    def sets_which_args_are_optional(self):
        eq_(self.vanilla["optional_values"].optional, ("myopt",))

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla["one_positional"].positional, ["pos"])
        eq_(self.vanilla["two_positionals"].positional, ["pos1", "pos2"])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla["implicit_positionals"].positional, ["pos1", "pos2"])

    def context_arguments_should_not_appear_in_implicit_positional_list(self):
        @ctask
        def mytask(ctx):
            pass

        eq_(len(mytask.positional), 0)

    def pre_tasks_stored_as_simple_list_of_strings(self):
        @task(pre=["whatever"])
        def func():
            pass

        eq_(func.pre, ["whatever"])

    def allows_star_args_as_shortcut_for_pre(self):
        @task("my", "pre", "tasks")
        def func():
            pass

        eq_(func.pre, ("my", "pre", "tasks"))

    @raises(TypeError)
    def no_ambiguity_between_star_args_and_pre_kwarg(self):
        @task("lol", "wut", pre=["no", "wai"])
        def func():
            pass

    def passes_in_contextualized_kwarg(self):
        @task
        def task1():
            pass

        @task(contextualized=True)
        def task2(ctx):
            pass

        assert not task1.contextualized
        assert task2.contextualized

    def sets_name(self):
        @task(name="foo")
        def bar():
            pass

        eq_(bar.name, "foo")
Beispiel #10
0
 def setup(self):
     self.l = FSLoader(start=support)
Beispiel #11
0
 def setup(self):
     self.loader = Loader(start=support)
     self.vanilla = self.loader.load('decorator')
Beispiel #12
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(start=support)
        self.vanilla = self.loader.load('decorator')

    def allows_access_to_wrapped_object(self):
        def lolcats(ctx):
            pass

        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_multiple_aliases(self):
        eq_(self.vanilla['foo'], self.vanilla['otherbar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    def has_autoprint_option(self):
        ap = self.loader.load('autoprint')
        eq_(ap['nope'].autoprint, False)
        eq_(ap['yup'].autoprint, True)

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load('decorator_multi_default')

    def sets_arg_help(self):
        eq_(self.vanilla['punch'].help['why'], 'Motive')

    def sets_arg_kind(self):
        skip()

    def sets_which_args_are_optional(self):
        eq_(self.vanilla['optional_values'].optional, ('myopt', ))

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla['one_positional'].positional, ['pos'])
        eq_(self.vanilla['two_positionals'].positional, ['pos1', 'pos2'])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla['implicit_positionals'].positional, ['pos1', 'pos2'])

    def context_arguments_should_not_appear_in_implicit_positional_list(self):
        @task
        def mytask(ctx):
            pass

        eq_(len(mytask.positional), 0)

    def pre_tasks_stored_directly(self):
        @task
        def whatever(ctx):
            pass

        @task(pre=[whatever])
        def func(ctx):
            pass

        eq_(func.pre, [whatever])

    def allows_star_args_as_shortcut_for_pre(self):
        @task
        def pre1(ctx):
            pass

        @task
        def pre2(ctx):
            pass

        @task(pre1, pre2)
        def func(ctx):
            pass

        eq_(func.pre, (pre1, pre2))

    @raises(TypeError)
    def disallows_ambiguity_between_star_args_and_pre_kwarg(self):
        @task
        def pre1(ctx):
            pass

        @task
        def pre2(ctx):
            pass

        @task(pre1, pre=[pre2])
        def func(ctx):
            pass

    def sets_name(self):
        @task(name='foo')
        def bar(ctx):
            pass

        eq_(bar.name, 'foo')
Beispiel #13
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(start=support)
        self.vanilla = self.loader.load('decorator')

    def allows_access_to_wrapped_object(self):
        def lolcats():
            pass
        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_multiple_aliases(self):
        eq_(self.vanilla['foo'], self.vanilla['otherbar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load('decorator_multi_default')

    def sets_arg_help(self):
        eq_(self.vanilla['punch'].help['why'], 'Motive')

    def sets_arg_kind(self):
        skip()

    def sets_which_args_are_optional(self):
        eq_(self.vanilla['optional_values'].optional, ('myopt',))

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla['one_positional'].positional, ['pos'])
        eq_(self.vanilla['two_positionals'].positional, ['pos1', 'pos2'])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla['implicit_positionals'].positional, ['pos1', 'pos2'])

    def context_arguments_should_not_appear_in_implicit_positional_list(self):
        @ctask
        def mytask(ctx):
            pass
        eq_(len(mytask.positional), 0)

    def pre_tasks_stored_directly(self):
        @task
        def whatever():
            pass
        @task(pre=[whatever])
        def func():
            pass
        eq_(func.pre, [whatever])

    def allows_star_args_as_shortcut_for_pre(self):
        @task
        def pre1():
            pass
        @task
        def pre2():
            pass
        @task(pre1, pre2)
        def func():
            pass
        eq_(func.pre, (pre1, pre2))

    @raises(TypeError)
    def disallows_ambiguity_between_star_args_and_pre_kwarg(self):
        @task
        def pre1():
            pass
        @task
        def pre2():
            pass
        @task(pre1, pre=[pre2])
        def func():
            pass

    def passes_in_contextualized_kwarg(self):
        @task
        def task1():
            pass
        @task(contextualized=True)
        def task2(ctx):
            pass
        assert not task1.contextualized
        assert task2.contextualized

    def sets_name(self):
        @task(name='foo')
        def bar():
            pass
        eq_(bar.name, 'foo')