def Failure_repr_includes_stderr(self): try: run("./err ohnoz && exit 1", hide='both') assert false # Ensure failure to Failure fails except Failure as f: r = repr(f) assert 'ohnoz' in r, "Sentinel 'ohnoz' not found in %r" % r
def Failure_repr_includes_stderr(self): try: run("./err ohnoz && exit 1") assert false # Ensure failure to Failure fails except Failure as f: r = repr(f) assert 'ohnoz' in r, "Sentinel 'ohnoz' not found in %r" % r
def core_help_option_prints_core_help(self): # TODO: change dynamically based on parser contents? # e.g. no core args == no [--core-opts], # no tasks == no task stuff? # NOTE: test will trigger default pty size of 80x24, so the below # string is formatted appropriately. # TODO: add more unit-y tests for specific behaviors: # * fill terminal w/ columns + spacing # * line-wrap help text in its own column expected = """ Usage: inv[oke] [--core-opts] task1 [--task1-opts] ... taskN [--taskN-opts] Core options: --no-dedupe Disable task deduplication. -c STRING, --collection=STRING Specify collection name to load. May be given >1 time. -d, --debug Enable debug output. -e, --echo Echo executed commands before running. -h [STRING], --help[=STRING] Show core or per-task help and exit. -H STRING, --hide=STRING Set default value of run()'s 'hide' kwarg. -l, --list List available tasks. -p, --pty Use a pty when executing shell commands. -r STRING, --root=STRING Change root directory used for finding task modules. -V, --version Show version and exit. -w, --warn-only Warn, instead of failing, when shell commands fail. """.lstrip() r1 = run("inv -h", hide='out') r2 = run("inv --help", hide='out') eq_(r1.stdout, expected) eq_(r2.stdout, expected)
def core_help_option_prints_core_help(self): # TODO: change dynamically based on parser contents? # e.g. no core args == no [--core-opts], # no tasks == no task stuff? # NOTE: test will trigger default pty size of 80x24, so the below # string is formatted appropriately. # TODO: add more unit-y tests for specific behaviors: # * fill terminal w/ columns + spacing # * line-wrap help text in its own column expected = """ Usage: inv[oke] [--core-opts] task1 [--task1-opts] ... taskN [--taskN-opts] Core options: --no-dedupe Disable task deduplication -c STRING, --collection=STRING Specify collection name to load. May be given >1 time. -h, --help Show this help message and exit. -l, --list List available tasks. -r STRING, --root=STRING Change root directory used for finding task modules. -V, --version Show version and exit """.lstrip() r1 = run("inv -h", hide='out') r2 = run("inv --help", hide='out') eq_(r1.stdout, expected) eq_(r2.stdout, expected)
def core_help_option_prints_core_help(self): # TODO: change dynamically based on parser contents? # e.g. no core args == no [--core-opts], # no tasks == no task stuff? # NOTE: test will trigger default pty size of 80x24, so the below # string is formatted appropriately. # TODO: add more unit-y tests for specific behaviors: # * fill terminal w/ columns + spacing # * line-wrap help text in its own column expected = """ Usage: inv[oke] [--core-opts] task1 [--task1-opts] ... taskN [--taskN-opts] Core options: --no-dedupe Disable task deduplication. -c STRING, --collection=STRING Specify collection name to load. May be given >1 time. -e, --echo Echo executed commands before running. -h [STRING], --help[=STRING] Show core or per-task help and exit. -H STRING, --hide=STRING Set default value of run()'s 'hide' kwarg. -l, --list List available tasks. -p, --pty Use a pty when executing shell commands. -r STRING, --root=STRING Change root directory used for finding task modules. -V, --version Show version and exit. -w, --warn-only Warn, instead of failing, when shell commands fail. """.lstrip() r1 = run("inv -h", hide='out') r2 = run("inv --help", hide='out') eq_(r1.stdout, expected) eq_(r2.stdout, expected)
def hide_unknown_vals_mention_value_given_in_error(self): value = "penguinmints" try: run("command", hide=value) except ValueError, e: msg = "Error from run(hide=xxx) did not tell user what the bad value was!" msg += "\nException msg: %s" % e ok_(value in str(e), msg)
def hide_unknown_vals_mention_value_given_in_error(self): value = "penguinmints" try: run("command", hide=value) except ValueError as e: msg = "Error from run(hide=xxx) did not tell user what the bad value was!" msg += "\nException msg: %s" % e ok_(value in str(e), msg) else: assert False, "run() did not raise ValueError for bad hide= value"
def no_deduping(self): expected = """ foo foo bar """.lstrip() eq_(run("invoke -c integration --no-dedupe foo bar").stdout, expected)
def return_code_in_result(self): """ Result has .return_code (and .exited) containing exit code int """ r = run(self.out, hide='both') eq_(r.return_code, 0) eq_(r.exited, 0)
def default_tasks(self): # sub-ns default task display as "real.name (collection name)" expected = self._listing( 'top_level (othertop)', 'sub.sub_task (sub, sub.othersub)', ) eq_(run("invoke -c explicit_root --list").stdout, expected)
def per_task_help_prints_help_for_task_only(self): expected = """ Usage: inv[oke] [--core-opts] punch [--options] [other tasks here ...] Docstring: none Options: -h STRING, --why=STRING Motive -w STRING, --who=STRING Who to punch """.lstrip() r1 = run("inv -c decorator -h punch", hide='out') r2 = run("inv -c decorator --help punch", hide='out') eq_(r1.stdout, expected) eq_(r2.stdout, expected)
def subcollections_sorted_in_depth_order(self): expected = self._listing( 'toplevel', 'a.subtask', 'a.nother.subtask', ) eq_(run("invoke -c deeper_ns_list --list").stdout, expected)
def namespacing(self): # TODO: break out the listing behavior into a testable method, down # with subprocesses! expected = self._listing( 'toplevel', 'module.mytask', ) eq_(run("invoke -c namespacing --list").stdout, expected)
def complex_nesting_doesnt_break(self): # GH issue 191 substr = " hello\t\t\nworld with spaces" cmd = """ eval 'echo "{0}" ' """.format(substr) # TODO: consider just mocking os.execv here (and in the other # tests) though that feels like too much of a tautology / testing # pexpect expected = ' hello\t\t\r\nworld with spaces\r\n' eq_(run(cmd, pty=True, hide='both').stdout, expected)
def docstrings_shown_alongside(self): expected = self._listing( 'leading_whitespace foo', 'no_docstring', 'one_line foo', 'two_lines foo', 'with_aliases (a, b) foo', ) eq_(run("invoke -c docstrings --list").stdout, expected)
def simple_output(self): expected = self._listing( 'bar', 'foo', 'print_foo', 'print_name', ) for flag in ('-l', '--list'): eq_(run("invoke -c integration %s" % flag).stdout, expected)
def docstrings(self): expected = self._listing( 'empty_first_line foo', 'no_line', 'one_line foo', 'second_lines foo', 'with_aliases (a, b) foo', ) eq_(run("invoke -c docstrings --list").stdout, expected)
def task_list(self): expected = """ Available tasks: print_foo print_name """.lstrip() for flag in ('-l', '--list'): eq_(run("invoke -c integration %s" % flag).stdout, expected)
def publish(path, version, args): if '.' in version: package = 'dist' cache = get_cache_headers(FAR_FUTURE) branch = version else: package = 'build' cache = get_cache_headers(SHORT_FUTURE) branch = get_branch() upload(path, args + cache, package, branch) if package == 'dist': run('mkdir -p dist/%s' % version) run('cp build/%s dist/%s' % (path, version)) version = version.split('.') version.pop() cache = get_cache_headers(MEDIUM_FUTURE) while version: upload(path, args + cache, package, '.'.join(version)) version.pop()
def per_task_help_works_for_unparameterized_tasks(self): expected = """ Usage: inv[oke] [--core-opts] biz [other tasks here ...] Docstring: none Options: none """.lstrip() r = run("inv -c decorator -h biz", hide='out') eq_(r.stdout, expected)
def per_task_help_displays_docstrings_if_given(self): expected = """ Usage: inv[oke] [--core-opts] foo [other tasks here ...] Docstring: Foo the bar. Options: none """.lstrip() r = run("inv -c decorator -h foo", hide='out') eq_(r.stdout, expected)
def _run(returns=None, **kwargs): """ Create a Runner w/ retval reflecting ``returns`` & call ``run(**kwargs)``. """ # Set up return value tuple for Runner.run returns = returns or {} returns.setdefault('exited', 0) value = map( lambda x: returns.get(x, None), ('stdout', 'stderr', 'exited', 'exception'), ) class MockRunner(Runner): def run(self, command, warn, hide): return value # Ensure top level run() uses that runner, provide dummy command. kwargs['runner'] = MockRunner return run("whatever", **kwargs)
def per_task_help_dedents_correctly(self): expected = """ Usage: inv[oke] [--core-opts] foo2 [other tasks here ...] Docstring: Foo the bar: example code Added in 1.0 Options: none """.lstrip() r = run("inv -c decorator -h foo2", hide='out') eq_(r.stdout, expected)
def _output_eq(cmd, expected): return eq_(run(cmd).stdout, expected)
def _hide_both(self, val): run(self.both, hide=val) eq_(sys.stdall.getvalue(), "")
def version_info(self): eq_(run("invoke -V").stdout, "Invoke %s\n" % invoke.__version__)
def should_not_show_tracebacks(self): result = run("inv -c fail missing_pos", warn=True, hide='both') assert TB_SENTINEL not in result.stderr
def aliases_sorted_alphabetically(self): expected = self._listing( 'toplevel (a, z)', ) eq_(run("invoke -c alias_sorting --list").stdout, expected)
def command_failure(self): "Command failure doesn't show tracebacks" result = run("inv -c fail simple", warn=True, hide='both') assert TB_SENTINEL not in result.stderr assert result.exited != 0
def gzip(path): run('gzip -6 build/%s' % path) run('mv build/%s.gz build/%s' % (path, path))
def make(version): run('VERSION=%s make raven' % version) for raven in ('raven.js', 'raven.min.js'): gzip(raven) publish(raven, version, BASE_S3_ARGS + JS_S3_ARGS) publish('raven.min.map', version, BASE_S3_ARGS)
def test(): run('node_modules/.bin/jshint .') run('node_modules/.bin/mocha-phantomjs -R dot test/index.html')
def top_level_tasks_listed_first(self): expected = self._listing( 'z_toplevel', 'a.subtask' ) eq_(run("invoke -c simple_ns_list --list").stdout, expected)
def aliases_sorted_alphabetically(self): expected = self._listing('toplevel (a, z)', ) eq_(run("invoke -c alias_sorting --list").stdout, expected)
def warn_kwarg_allows_continuing_past_failures(self): eq_(run("false", warn=True).exited, 1)
def hide_out_only_hides_stdout(self): run(self.both, hide='out') eq_(sys.stdout.getvalue().strip(), "") eq_(sys.stderr.getvalue().strip(), "bar")
def tag(version): run('git add dist/%s' % version) run('git commit -m "%s"' % version) run('git tag %s' % version) run('git push origin %s' % version)
def _basic(self): self.result = run("invoke -c integration print_foo", hide='both')
def upload(path, args, package, build): run('s3cmd put %s build/%s s3://getsentry-cdn/%s/%s/%s' % (' '.join(args), path, package, build, path))
def get_branch(): return run('git rev-parse --short --abbrev-ref HEAD', hide='both').stdout.strip()
def get_rev(): return run('git rev-parse --short HEAD', hide='both').stdout.strip()
def debug_flag(self): assert 'my-sentinel' in run("invoke -d -c debugging foo").stderr
def top_level_tasks_listed_first(self): expected = self._listing('z_toplevel', 'a.subtask') eq_(run("invoke -c simple_ns_list --list").stdout, expected)