Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
 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)
Exemple #7
0
 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"
Exemple #8
0
    def no_deduping(self):
        expected = """
foo
foo
bar
""".lstrip()
        eq_(run("invoke -c integration --no-dedupe foo bar").stdout, expected)
Exemple #9
0
 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)
Exemple #10
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)
Exemple #11
0
    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)
Exemple #12
0
    def no_deduping(self):
        expected = """
foo
foo
bar
""".lstrip()
        eq_(run("invoke -c integration --no-dedupe foo bar").stdout, expected)
Exemple #13
0
    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)
Exemple #14
0
 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)
Exemple #15
0
 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)
Exemple #16
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)
Exemple #17
0
 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)
Exemple #18
0
 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)
Exemple #19
0
 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)
Exemple #20
0
 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)
Exemple #21
0
 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)
Exemple #22
0
 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)
Exemple #23
0
 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)
Exemple #24
0
 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)
Exemple #25
0
 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)
Exemple #26
0
    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)
Exemple #27
0
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()
Exemple #28
0
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()
Exemple #29
0
    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)
Exemple #30
0
    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)
Exemple #31
0
    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)
Exemple #32
0
    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)
Exemple #33
0
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)
Exemple #34
0
    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)
Exemple #35
0
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)
Exemple #36
0
def _output_eq(cmd, expected):
    return eq_(run(cmd).stdout, expected)
Exemple #37
0
 def _hide_both(self, val):
     run(self.both, hide=val)
     eq_(sys.stdall.getvalue(), "")
Exemple #38
0
 def version_info(self):
     eq_(run("invoke -V").stdout, "Invoke %s\n" % invoke.__version__)
Exemple #39
0
def _output_eq(cmd, expected):
    return eq_(run(cmd).stdout, expected)
Exemple #40
0
 def version_info(self):
     eq_(run("invoke -V").stdout, "Invoke %s\n" % invoke.__version__)
Exemple #41
0
 def should_not_show_tracebacks(self):
     result = run("inv -c fail missing_pos", warn=True, hide='both')
     assert TB_SENTINEL not in result.stderr
Exemple #42
0
 def aliases_sorted_alphabetically(self):
     expected = self._listing(
         'toplevel (a, z)',
     )
     eq_(run("invoke -c alias_sorting --list").stdout, expected)
Exemple #43
0
 def should_not_show_tracebacks(self):
     result = run("inv -c fail missing_pos", warn=True, hide='both')
     assert TB_SENTINEL not in result.stderr
Exemple #44
0
 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
Exemple #45
0
 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
Exemple #46
0
def gzip(path):
    run('gzip -6 build/%s' % path)
    run('mv build/%s.gz build/%s' % (path, path))
Exemple #47
0
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)
Exemple #48
0
def test():
    run('node_modules/.bin/jshint .')
    run('node_modules/.bin/mocha-phantomjs -R dot test/index.html')
Exemple #49
0
 def top_level_tasks_listed_first(self):
     expected = self._listing(
         'z_toplevel',
         'a.subtask'
     )
     eq_(run("invoke -c simple_ns_list --list").stdout, expected)
Exemple #50
0
 def aliases_sorted_alphabetically(self):
     expected = self._listing('toplevel (a, z)', )
     eq_(run("invoke -c alias_sorting --list").stdout, expected)
Exemple #51
0
 def warn_kwarg_allows_continuing_past_failures(self):
     eq_(run("false", warn=True).exited, 1)
Exemple #52
0
 def hide_out_only_hides_stdout(self):
     run(self.both, hide='out')
     eq_(sys.stdout.getvalue().strip(), "")
     eq_(sys.stderr.getvalue().strip(), "bar")
Exemple #53
0
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)
Exemple #54
0
 def _basic(self):
     self.result = run("invoke -c integration print_foo", hide='both')
Exemple #55
0
def upload(path, args, package, build):
    run('s3cmd put %s build/%s s3://getsentry-cdn/%s/%s/%s' %
        (' '.join(args), path, package, build, path))
Exemple #56
0
def get_branch():
    return run('git rev-parse --short --abbrev-ref HEAD',
               hide='both').stdout.strip()
Exemple #57
0
 def _basic(self):
     self.result = run("invoke -c integration print_foo", hide='both')
Exemple #58
0
def get_rev():
    return run('git rev-parse --short HEAD', hide='both').stdout.strip()
Exemple #59
0
 def debug_flag(self):
     assert 'my-sentinel' in run("invoke -d -c debugging foo").stderr
Exemple #60
0
 def top_level_tasks_listed_first(self):
     expected = self._listing('z_toplevel', 'a.subtask')
     eq_(run("invoke -c simple_ns_list --list").stdout, expected)