示例#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_config = create_default_config()
        global_config.set('shell', 'bash', 'false')
        global_config.set('shell', 'zsh', 'true')
        global_config.set('shell', 'gui', 'false')
        with MockEnvironment(target_config=test_target,
                             global_config=global_config) as environment:
            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
    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_config = create_default_config()
        global_config.set("global", "env_source_rc", True)
        with MockEnvironment(test_source, test_target, global_config=global_config) as environment:
            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
示例#3
0
def create_mock_environment(source_config=None, target_config=None,
                            global_config=None, mock_formulabase=None):
        temp_directory = tempfile.mkdtemp()
        environment = Environment(root=temp_directory,
                                  sprinter_namespace='test',
                                  global_config=(global_config or create_default_config()))
        environment.namespace = "test"
        if source_config:
            environment.source = load_manifest(StringIO(source_config), namespace="test")

        if target_config:
            environment.target = load_manifest(StringIO(target_config), namespace="test")

        environment.warmup()
        # TODO: implement sandboxing so no need to mock these
        environment.injections.commit = Mock()
        environment.global_injections.commit = Mock()
        environment.write_manifest = Mock()
        if mock_formulabase:
            formula_dict = {'sprinter.formula.base': mock_formulabase}
            environment.features = FeatureDict(environment,
                                               environment.source, environment.target,
                                               environment.global_path,
                                               formula_dict=formula_dict)
        return environment, temp_directory
示例#4
0
 def test_global_shell_configuration_bash(self):
     """ The global shell should dictate what files are injected (bash, gui, no zsh)"""
     # test bash, gui, no zshell
     global_config = create_default_config()
     global_config.set('shell', 'bash', 'true')
     global_config.set('shell', 'zsh', 'false')
     global_config.set('shell', 'gui', 'true')
     with MockEnvironment(test_source, test_target, global_config=global_config) as environment:
         environment.install()
         assert [x for x in environment.injections.inject_dict.keys() if x.endswith('.bashrc')]
         env_injected = False
         for profile in ['.bash_profile', '.bash_login', '.profile']:
             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('.zshrc')]
         for profile in ['.zprofile', '.zlogin']:
             assert not [x for x in environment.injections.inject_dict.keys() if x.endswith(profile)]
示例#5
0
 def test_global_shell_configuration_bash(self):
     """ The global shell should dictate what files are injected (bash, gui, no zsh)"""
     # test bash, gui, no zshell
     global_config = create_default_config()
     global_config.set("shell", "bash", "true")
     global_config.set("shell", "zsh", "false")
     global_config.set("shell", "gui", "true")
     with MockEnvironment(test_source, test_target, global_config=global_config) as environment:
         environment.install()
         assert [x for x in environment.injections.inject_dict.keys() if x.endswith(".bashrc")]
         env_injected = False
         for profile in [".bash_profile", ".bash_login", ".profile"]:
             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(".zshrc")]
         for profile in [".zprofile", ".zlogin"]:
             assert not [x for x in environment.injections.inject_dict.keys() if x.endswith(profile)]
示例#6
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_config = create_default_config()
        global_config.set('global', 'env_source_rc', True)
        with MockEnvironment(test_source,
                             test_target,
                             global_config=global_config) as environment:
            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
示例#7
0
 def setUp(self):
     self.config = create_default_config()
示例#8
0
 def setUp(self):
     self.global_config = create_default_config()
     self.global_config.set('shell', 'bash', 'false')
     self.global_config.set('shell', 'zsh', 'false')
     self.global_config.set('shell', 'gui', 'false')
示例#9
0
 def setup(self):
     self.config = create_default_config()
示例#10
0
 def setup(self):
     self.global_config = create_default_config()
     self.global_config.set('shell', 'bash', 'false')
     self.global_config.set('shell', 'zsh', 'false')
     self.global_config.set('shell', 'gui', 'false')