コード例 #1
0
    def test_find_program(self):
        # If we add the path, we should found the env/executable instead of ori/executable
        # Watch out! 'cmd' returns all the paths where the executable is found, so we need to
        #   take into account the first match (iterate in reverse order)
        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {"PATH": [self.env_path], }

        stdout, environment = self._run_virtualenv(generator)

        cpaths = dict(l.split("=", 1) for l in reversed(stdout.splitlines()) if l.startswith("__conan_"))
        self.assertEqual(cpaths["__conan_pre_path__"], cpaths["__conan_post_path__"])
        self.assertEqual(cpaths["__conan_env_path__"], cpaths["__conan_post_path__"])

        epaths = dict(l.split("=", 1) for l in reversed(stdout.splitlines()) if l.startswith("__exec_"))
        self.assertEqual(epaths["__exec_pre_path__"], epaths["__exec_post_path__"])
        self.assertEqual(epaths["__exec_env_path__"], os.path.join(self.env_path, self.app))

        # With any other path, we keep finding the original one
        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {"PATH": [os.path.join(self.test_folder, "wrong")], }

        stdout, environment = self._run_virtualenv(generator)
        epaths = dict(l.split("=", 1) for l in reversed(stdout.splitlines()) if l.startswith("__exec_"))
        self.assertEqual(epaths["__exec_pre_path__"], epaths["__exec_post_path__"])
        self.assertEqual(epaths["__exec_env_path__"], epaths["__exec_post_path__"])
コード例 #2
0
    def test_conanfile(self):
        base_ref = ConanFileReference.loads("base/0.1")
        dummy_ref = ConanFileReference.loads("dummy/0.1")

        self._cache_recipe(base_ref, self.base)
        self._cache_recipe(dummy_ref, self.dummy)
        deps_graph = self.build_graph(
            GenConanfile().with_requirement(dummy_ref))
        generator = VirtualEnvGenerator(deps_graph.root.conanfile)

        self.assertEqual(
            generator.env["BASE_LIST"],
            ['dummyValue1', 'dummyValue2', 'baseValue1', 'baseValue2'])
        self.assertEqual(generator.env["BASE_VAR"], 'baseValue')
        self.assertEqual(generator.env["BCKW_SLASH"], 'dummy\\value')
        self.assertEqual(generator.env["CPPFLAGS"],
                         ['-flag1', '-flag2', '-baseFlag1', '-baseFlag2'])
        self.assertEqual(
            generator.env["LD_LIBRARY_PATH"],
            [os.path.join("dummydir", "lib"),
             os.path.join("basedir", "lib")])
        self.assertEqual(generator.env["PATH"], [
            os.path.join("dummydir", "bin"),
            os.path.join("basedir", "bin"), 'samebin'
        ])
        self.assertEqual(generator.env["SPECIAL_VAR"], 'dummyValue')
コード例 #3
0
    def test_list_variable(self):
        self.assertNotIn("WHATEVER", os.environ)
        self.assertIn("PATH", os.environ)
        existing_path = os.environ.get("PATH")
        # Avoid duplicates in the path
        existing_path = os.pathsep.join(
            OrderedDict.fromkeys(existing_path.split(os.pathsep)))

        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {
            "PATH": [os.path.join(self.test_folder, "bin"), r'other\path'],
            "WHATEVER": ["list", "other"]
        }

        _, environment = self._run_virtualenv(generator)

        self.assertEqual(
            environment["PATH"],
            os.pathsep.join([
                os.path.join(self.test_folder, "bin"), r'other\path',
                self.ori_path, existing_path
            ]))
        # FIXME: extra separator in Windows
        extra_separator = os.pathsep if platform.system() == "Windows" else ""
        self.assertEqual(
            environment["WHATEVER"],
            "{}{}{}{}".format("list", os.pathsep, "other", extra_separator))
コード例 #4
0
    def test_find_program(self):
        # If we add the path, we should found the env/executable instead of ori/executable
        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {
            "PATH": [self.env_path],
        }

        stdout, environment = self._run_virtualenv(generator)

        cpaths = dict(
            l.split("=", 1) for l in stdout.splitlines()
            if l.startswith("__conan_"))
        self.assertEqual(cpaths["__conan_pre_path__"],
                         cpaths["__conan_post_path__"])
        self.assertEqual(cpaths["__conan_env_path__"],
                         cpaths["__conan_post_path__"])

        epaths = dict(
            l.split("=", 1) for l in stdout.splitlines()
            if l.startswith("__exec_"))
        self.assertEqual(epaths["__exec_pre_path__"],
                         epaths["__exec_post_path__"])
        if self.commands.id == "cmd":  # FIXME: This is a bug, it doesn't take into account the new path
            self.assertNotEqual(epaths["__exec_env_path__"],
                                os.path.join(self.env_path, self.app))
        else:
            self.assertEqual(epaths["__exec_env_path__"],
                             os.path.join(self.env_path, self.app))

        # With any other path, we keep finding the original one
        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {
            "PATH": [os.path.join(self.test_folder, "wrong")],
        }

        stdout, environment = self._run_virtualenv(generator)
        epaths = dict(
            l.split("=", 1) for l in stdout.splitlines()
            if l.startswith("__exec_"))
        self.assertEqual(epaths["__exec_pre_path__"],
                         epaths["__exec_post_path__"])
        self.assertEqual(epaths["__exec_env_path__"],
                         epaths["__exec_post_path__"])
コード例 #5
0
ファイル: virtualenv_test.py プロジェクト: yochju/conan
 def prepend_values_test(self):
     """
     Check list values are only prepended once
     """
     conanfile = ConanFile(TestBufferConanOutput(), None)
     conanfile.initialize(Settings({}), EnvValues.loads("PATH=[1,2,three]"))
     gen = VirtualEnvGenerator(conanfile)
     content = gen.content
     self.assertIn("PATH=\"1\":\"2\":\"three\"${PATH+:$PATH}", content["activate.sh"])
     if platform.system() == "Windows":
         self.assertIn("PATH=1;2;three;%PATH%", content["activate.bat"])
コード例 #6
0
ファイル: virtualenv_test.py プロジェクト: stkw0/conan
    def setUpClass(cls):
        env = EnvValues()
        env.add("USER_FLAG", "user_value")
        env.add("CL", ["cl1", "cl2"])
        env.add("PATH", ["another_path", ])
        env.add("PATH2", ["p1", "p2"])
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), env)

        cls.generator = VirtualEnvGenerator(conanfile)
        cls.generator.output_path = "not-used"
        cls.result = cls.generator.content
コード例 #7
0
ファイル: virtualenv_test.py プロジェクト: lexknuther/conan
    def test_empty_undefined_list_variable(self):
        self.assertNotIn("WHATEVER", os.environ)

        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {"WHATEVER": ["list", "other"]}

        _, environment = self._run_virtualenv(generator)

        # FIXME: extra separator in Windows
        extra_separator = os.pathsep if platform.system() == "Windows" else ""
        self.assertEqual(environment["WHATEVER"],
                         "{}{}{}{}".format("list", os.pathsep, "other", extra_separator))
コード例 #8
0
ファイル: virtualenv_test.py プロジェクト: lexknuther/conan
    def test_empty_defined_list_variable(self):
        self.assertNotIn("WHATEVER", os.environ)
        try:
            os.environ["WHATEVER"] = ""

            generator = VirtualEnvGenerator(ConanFileMock())
            generator.env = {"WHATEVER": ["list", "other"]}

            _, environment = self._run_virtualenv(generator)

            self.assertEqual(environment["WHATEVER"], "{}{}{}".format("list", os.pathsep, "other"))
        finally:
            del os.environ["WHATEVER"]
コード例 #9
0
    def test_basic_variable(self):
        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {"USER_VAR": r"some value with space and \ (backslash)",
                         "ANOTHER": "data"}

        _, environment = self._run_virtualenv(generator)

        self.assertEqual(environment["USER_VAR"], r"some value with space and \ (backslash)")
        self.assertEqual(environment["ANOTHER"], "data")

        with environment_append({"USER_VAR": "existing value", "ANOTHER": "existing_value"}):
            _, environment = self._run_virtualenv(generator)

            self.assertEqual(environment["USER_VAR"], r"some value with space and \ (backslash)")
            self.assertEqual(environment["ANOTHER"], "data")
コード例 #10
0
    def test_list_with_spaces(self):
        generator = VirtualEnvGenerator(ConanFileMock())
        self.assertIn("CFLAGS", VirtualEnvGenerator.append_with_spaces)
        self.assertIn("CL", VirtualEnvGenerator.append_with_spaces)
        generator.env = {"CFLAGS": ["-O2"],
                         "CL": ["-MD", "-DNDEBUG", "-O2", "-Ob2"]}

        _, environment = self._run_virtualenv(generator)

        self.assertEqual(environment["CFLAGS"], "-O2 ")  # FIXME: Trailing blank
        self.assertEqual(environment["CL"], "-MD -DNDEBUG -O2 -Ob2 ")  # FIXME: Trailing blank

        with environment_append({"CFLAGS": "cflags", "CL": "cl"}):
            _, environment = self._run_virtualenv(generator)
            extra_blank = " " if platform.system() != "Windows" else ""  # FIXME: Extra blank
            self.assertEqual(environment["CFLAGS"], "-O2 {}cflags".format(extra_blank))
            self.assertEqual(environment["CL"], "-MD -DNDEBUG -O2 -Ob2 {}cl".format(extra_blank))
コード例 #11
0
ファイル: virtualenv_test.py プロジェクト: lexknuther/conan
    def test_list_variable(self):
        self.assertIn("PATH", os.environ)
        existing_path = os.environ.get("PATH")
        # Avoid duplicates in the path
        existing_path = os.pathsep.join(OrderedDict.fromkeys(existing_path.split(os.pathsep)))

        generator = VirtualEnvGenerator(ConanFileMock())
        generator.env = {"PATH": [os.path.join(self.test_folder, "bin"), r'other\path']}

        _, environment = self._run_virtualenv(generator)

        self.assertEqual(environment["PATH"], os.pathsep.join([
            os.path.join(self.test_folder, "bin"),
            r'other\path',
            self.ori_path,
            existing_path
        ]))