示例#1
0
 def repeat_True_does_not_consume_results(self):
     mc = MockContext(
         repeat=True,
         run=dict(
             singleton=True,  # will repeat
             wassup=Result("yo"),  # ditto
             iterable=[Result("tick"), Result("tock")],  # will not
         ),
     )
     assert mc.run("singleton").ok
     assert mc.run("singleton").ok  # not consumed
     assert mc.run("wassup").ok
     assert mc.run("wassup").ok  # not consumed
     assert mc.run("iterable").stdout == "tick"
     assert mc.run("iterable").stdout == "tock"
     assert mc.run("iterable").stdout == "tick"  # not consumed
     assert mc.run("iterable").stdout == "tock"
    def test_jekyll_build_is_called_correctly(self, patch_clone_dir):
        ctx = MockContext()
        ctx.run = Mock()

        conf_path = patch_clone_dir / JEKYLL_CONFIG_YML
        conf_contents = 'hi: test'
        create_file(conf_path, conf_contents)

        tasks.build_jekyll(ctx,
                           branch='branch',
                           owner='owner',
                           repository='repo',
                           site_prefix='site/prefix',
                           config='boop: beep',
                           base_url='/site/prefix')

        assert ctx.run.call_count == 3

        jekyll_build_call_args = ctx.run.call_args_list[2]
        args, kwargs = jekyll_build_call_args

        # Make sure the call to jekyll build is correct
        assert args[0] == 'jekyll build --destination /work/site_repo/_site'

        # Make sure the env is as expected
        assert kwargs['env'] == {
            'BRANCH': 'branch',
            'OWNER': 'owner',
            'REPOSITORY': 'repo',
            'SITE_PREFIX': 'site/prefix',
            'BASEURL': '/site/prefix',
            'LANG': 'en_US.UTF-8',
            'JEKYLL_ENV': 'production'
        }

        # Check that the config file has had baseurl, branch, and custom
        # config added
        with conf_path.open() as f:
            assert f.read() == ('hi: test\nbaseurl: /site/prefix\n'
                                'branch: branch\nboop: beep\n')
示例#3
0
    def test_jekyll_build_is_called_correctly(self, fs):
        ctx = MockContext(run=[
            Result('gem install jekyll result'),
            Result('jekyll version result'),
            Result('jekyll build result'),
        ])

        ctx.run = Mock()

        with Patcher() as patcher:
            patcher.fs.CreateFile('/tmp/site_repo/_config.yml',
                                  contents='hi: test')

            build_jekyll(ctx,
                         branch='branch',
                         owner='owner',
                         repository='repo',
                         site_prefix='site/prefix',
                         config='boop: beep',
                         base_url='/site/prefix')

            assert ctx.run.call_count == 3

            jekyll_build_call_args = ctx.run.call_args_list[2]
            args, kwargs = jekyll_build_call_args

            # Make sure the call to jekyll build is correct
            assert args[0] == 'jekyll build --destination /tmp/site_repo/_site'

            # Make sure the env is as expected
            assert kwargs['env'] == {
                'BRANCH': 'branch',
                'OWNER': 'owner',
                'REPOSITORY': 'repo',
                'SITE_PREFIX': 'site/prefix',
                'BASEURL': '/site/prefix',
                'LANG': 'en_US.UTF-8',
                'JEKYLL_ENV': 'production'
            }
示例#4
0
 def return_value_kwargs_may_be_command_string_maps(self):
     c = MockContext(run={'foo': Result("bar")})
     eq_(c.run("foo").stdout, "bar")
示例#5
0
文件: context.py 项目: yws/invoke
 def run(self):
     mc = MockContext(run={'foo': Result('bar')})
     assert mc.run('foo').stdout == 'bar'
     mc.set_result_for('run', 'foo', Result('biz'))
     assert mc.run('foo').stdout == 'biz'
示例#6
0
 def as_iterables(self):
     mc = MockContext(run=[True, False])
     assert mc.run("anything").ok
     assert not mc.run("anything", warn=True).ok
示例#7
0
 def return_value_map_kwargs_may_take_iterables_too(self):
     c = MockContext(run={"foo": [Result("bar"), Result("biz")]})
     assert c.run("foo").stdout == "bar"
     assert c.run("foo").stdout == "biz"
示例#8
0
 def return_value_kwargs_can_take_iterables_too(self):
     c = MockContext(run=[Result("some output"), Result("more!")])
     assert c.run("doesn't mattress").stdout == "some output"
     assert c.run("still doesn't mattress").stdout == "more!"
示例#9
0
 def when_not_set_or_falsey(self, kwargs):
     c = MockContext(run={"foo": Result("bar", **kwargs)})
     assert c.run("foo").command == "foo"
示例#10
0
 def does_not_occur_when_truthy(self):
     # Not sure why you'd want this but whatevs!
     c = MockContext(run={"foo": Result("bar", command="nope")})
     assert c.run("foo").command == "nope"  # not "bar"
示例#11
0
 def as_dict_values(self):
     mc = MockContext(run=dict(foo="foo", bar="bar"))
     assert mc.run("foo").stdout == "foo"
     assert mc.run("bar").stdout == "bar"
示例#12
0
 def as_iterables(self):
     mc = MockContext(run=["definition", "of", "insanity"])
     assert mc.run("anything").stdout == "definition"
     assert mc.run("anything").stdout == "of"
     assert mc.run("anything").stdout == "insanity"
示例#13
0
 def as_dict_values(self):
     mc = MockContext(run=dict(foo=True, bar=False))
     assert mc.run("foo").ok
     assert not mc.run("bar", warn=True).ok
示例#14
0
 def return_value_map_kwargs_may_take_iterables_too(self):
     c = MockContext(run={'foo': [Result("bar"), Result("biz")]})
     eq_(c.run("foo").stdout, "bar")
     eq_(c.run("foo").stdout, "biz")
示例#15
0
 def run(self):
     mc = MockContext(run={'foo': Result('bar')})
     assert mc.run('foo').stdout == 'bar'
     mc.set_result_for('run', 'foo', Result('biz'))
     assert mc.run('foo').stdout == 'biz'
示例#16
0
 def non_config_init_kwargs_used_as_return_values_for_methods(self):
     c = MockContext(run=Result("some output"))
     assert c.run("doesn't mattress").stdout == "some output"
示例#17
0
文件: context.py 项目: yws/invoke
 def return_value_kwargs_may_be_command_string_maps(self):
     c = MockContext(run={'foo': Result("bar")})
     eq_(c.run("foo").stdout, "bar")
示例#18
0
 def return_value_kwargs_may_be_command_string_maps(self):
     c = MockContext(run={"foo": Result("bar")})
     assert c.run("foo").stdout == "bar"
示例#19
0
文件: context.py 项目: yws/invoke
 def return_value_map_kwargs_may_take_iterables_too(self):
     c = MockContext(run={'foo': [Result("bar"), Result("biz")]})
     eq_(c.run("foo").stdout, "bar")
     eq_(c.run("foo").stdout, "biz")
示例#20
0
 def run(self):
     mc = MockContext(run={"foo": Result("bar")})
     assert mc.run("foo").stdout == "bar"
     mc.set_result_for("run", "foo", Result("biz"))
     assert mc.run("foo").stdout == "biz"
示例#21
0
 def regexen_return_value_map_keys_match_on_command(self):
     c = MockContext(
         run={"string": Result("yup"), re.compile(r"foo.*"): Result("bar")}
     )
     assert c.run("string").stdout == "yup"
     assert c.run("foobar").stdout == "bar"