コード例 #1
0
    def test_global_shell_configuration_zshell(self):
        """ The global shell should dictate what files are injected (zsh, no bash, no gui)"""
        # test zshell, no bash, no gui
        global_shell_configuration_zshell = """[shell]
bash = false
zsh = true
gui = false

[global]
env_source_rc = False
        """
        environment = create_mock_environment(
            target_config=test_target,
            global_config=global_shell_configuration_zshell,
            mock_injections=False)
        environment.warmup()
        environment.injections.commit = Mock()
        environment.formula_dict['sprinter.formulabase'] = Mock(return_value=create_mock_formulabase())
        environment.install()
        assert [x for x in environment.injections.inject_dict.keys() if x.endswith('.zshrc')]
        env_injected = False
        for profile in ['.zprofile', '.zlogin']:
            env_injected = env_injected or filter(lambda x: x.endswith(profile), environment.injections.inject_dict.keys())
        assert env_injected
        assert not [x for x in environment.injections.inject_dict.keys() if x.endswith('.bashrc')]
        for profile in ['.bash_profile', '.bash_login']:
            assert not [x for x in environment.injections.inject_dict.keys() if x.endswith(profile)]
コード例 #2
0
ファイル: test_environment.py プロジェクト: WmoT/sprinter
 def test_feature_run_order_install(self):
     """ A feature install should have it's methods run in the proper order """
     with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase:
         with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment:
             environment.install()
             eq_(
                 formulabase().method_calls,
                 [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.sync()],
             )
コード例 #3
0
    def test_feature_run_remove_failure(self):
        """ A feature remove should not throw SprinterException on failure - it should
            raise a FeatureException that is handle in remove() """

        with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase:
            formulabase.sync.side_effect = Exception
            with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment:
                environment.directory = Mock(spec=environment.directory)
                environment.directory.new = False
                environment.remove()
コード例 #4
0
    def test_errors_fail_out_immediately(self):
        """ Failures in the update should fail out right then and there,
            not afterward.
            See https://github.com/toumorokoshi/sprinter/issues/56
        """

        with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase:
            formulabase.install.side_effect = Exception
            with MockEnvironment(None, test_target, mock_formulabase=formulabase) as environment:
                environment.run_feature("testfeature", "install")
コード例 #5
0
ファイル: test_environment.py プロジェクト: WmoT/sprinter
 def test_feature_run_order_deactivate(self):
     """ A feature deactivate should have it's methods run in the proper order """
     with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase:
         with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment:
             environment.directory = Mock(spec=environment.directory)
             environment.directory.new = False
             environment.deactivate()
             eq_(
                 formulabase().method_calls,
                 [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.deactivate()],
             )
コード例 #6
0
    def test_feature_run_remove_failure(self):
        """ A feature remove should not throw SprinterException on failure - it should
            raise a FeatureException that is handle in remove() """

        with patch('sprinter.formula.base.FormulaBase',
                   new=create_mock_formulabase()) as formulabase:
            formulabase.sync.side_effect = Exception
            with MockEnvironment(test_source,
                                 test_target,
                                 mock_formulabase=formulabase) as environment:
                environment.directory = Mock(spec=environment.directory)
                environment.directory.new = False
                environment.remove()
コード例 #7
0
    def test_errors_fail_out_immediately(self):
        """ Failures in the update should fail out right then and there,
            not afterward.
            See https://github.com/toumorokoshi/sprinter/issues/56
        """

        with patch('sprinter.formula.base.FormulaBase',
                   new=create_mock_formulabase()) as formulabase:
            formulabase.install.side_effect = Exception
            with MockEnvironment(None,
                                 test_target,
                                 mock_formulabase=formulabase) as environment:
                environment.run_feature('testfeature', 'install')
コード例 #8
0
 def test_feature_run_order_install(self):
     """ A feature install should have it's methods run in the proper order """
     with patch('sprinter.formula.base.FormulaBase',
                new=create_mock_formulabase()) as formulabase:
         with MockEnvironment(test_source,
                              test_target,
                              mock_formulabase=formulabase) as environment:
             environment.install()
             eq_(formulabase().method_calls, [
                 call.should_run(),
                 call.validate(),
                 call.resolve(),
                 call.prompt(),
                 call.sync()
             ])
コード例 #9
0
 def test_utilssh_file_written(self):
     """ The latest utilssh file should be written at the end of an install """
     temp_dir = tempfile.mkdtemp()
     try:
         with patch('sprinter.lib.prompt') as prompt:
             prompt.return_value = "1,2"
             env = Environment(root=temp_dir)
             env.formula_dict['sprinter.formulabase'] = Mock(return_value=create_mock_formulabase())
             env.target = StringIO(test_target)
             env.warmup()
             env.injections.commit = Mock()
             env.install()
             global_path = os.path.join(temp_dir, '.global')
             assert os.path.exists(os.path.join(global_path, 'utils.sh'))
     finally:
         shutil.rmtree(temp_dir)
コード例 #10
0
 def test_feature_run_order_activate(self):
     """ A feature should have it's methods run in the proper order """
     with patch('sprinter.formula.base.FormulaBase',
                new=create_mock_formulabase()) as formulabase:
         with MockEnvironment(test_source,
                              test_target,
                              mock_formulabase=formulabase) as environment:
             environment.directory = Mock(spec=environment.directory)
             environment.directory.new = False
             environment.activate()
             eq_(formulabase().method_calls, [
                 call.should_run(),
                 call.validate(),
                 call.resolve(),
                 call.prompt(),
                 call.activate()
             ])
コード例 #11
0
    def test_env_to_rc_injection(self):
        """ If env_source_rc is set to true, the env environments should source the rc """
        # test bash, gui, no zshell
        global_shell_configuration_bash = """[shell]
bash = true
zsh = true
gui = false

[global]
env_source_rc = True
        """
        environment = create_mock_environment(
            target_config=test_target,
            global_config=global_shell_configuration_bash,
            mock_injections=False,
            mock_global_injections=False)
        environment.warmup()
        environment.injections.commit = Mock()
        environment.global_injections.commit = Mock()
        environment.formula_dict['sprinter.formulabase'] = Mock(return_value=create_mock_formulabase())
        environment.install()

        # bash
        env_injected = False
        full_rc_path = os.path.expanduser(os.path.join("~", ".bashrc"))
        for profile in ['.bash_profile', '.bash_login', '.profile']:
            full_profile_path = os.path.expanduser(os.path.join("~", profile))
            specific_env_injected = full_profile_path in environment.global_injections.inject_dict
            if specific_env_injected:
                env_injected = True
                assert (source_template % (full_rc_path, full_rc_path) in
                        environment.global_injections.inject_dict[full_profile_path])
        assert env_injected

        # zshell
        env_injected = False
        full_rc_path = os.path.expanduser(os.path.join("~", ".zshrc"))
        for profile in ['.zprofile', '.zlogin']:
            full_profile_path = os.path.expanduser(os.path.join("~", profile))
            specific_env_injected = full_profile_path in environment.global_injections.inject_dict
            if specific_env_injected:
                env_injected = True
                assert (source_template % (full_rc_path, full_rc_path) in
                        environment.global_injections.inject_dict[full_profile_path])
        assert env_injected