예제 #1
0
    def test_invalid_flat(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            # Not a single dir containing everything
            file1 = os.path.join(tmp_folder, "subfolder-1.2.3", "folder2",
                                 "file1")
            file2 = os.path.join(tmp_folder, "other-1.2.3", "folder", "file2")

            save(file1, "")
            save(file2, "")

        zip_folder = temp_folder()
        zip_file = os.path.join(zip_folder, "file.zip")
        self._zipdir(tmp_folder, zip_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(
                self, ConanException,
                "The zip file contains more than 1 folder "
                "in the root"):
            unzip(zip_file,
                  destination=extract_folder,
                  strip_root=True,
                  output=Mock())
예제 #2
0
 def test_env_variable(self):
     file_path = os.path.join(temp_folder(), "whatever_cacert")
     save(file_path, "dummy content")
     with environment_append({"CONAN_CACERT_PATH": file_path}):
         requester, mocked_requester, _ = self._create_requesters()
         requester.get(url="aaa", verify=True)
         self.assertEqual(mocked_requester.verify, file_path)
예제 #3
0
 def root(self, content, profile):
     conan_path = os.path.join(self.folder, "data", "root.py")
     save(conan_path, content)
     conanfile = self.loader.load_consumer(conan_path, profile)
     node = Node(None, conanfile, "rootpath")
     node.recipe = RECIPE_CONSUMER
     return node
예제 #4
0
 def save_recipe(self, ref, content):
     content = str(content)
     if isinstance(ref, str):
         ref = ConanFileReference.loads(ref)
     conan_path = os.path.join(self.folder, "data", ref.dir_repr(),
                               CONANFILE)
     save(conan_path, content)
예제 #5
0
    def _run_test(self, tuples):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            for f, _ in tuples:
                save(f, "")

            apple_dot_clean(".")

            for f, expected_after in tuples:
                self.assertEqual(expected_after, os.path.exists(f))
예제 #6
0
파일: xz_test.py 프로젝트: Imerso3D/conan
    def test(self):
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "a_file.txt")
        save(file_path, "my content!")
        txz = os.path.join(tmp_dir, "sample.tar.xz")
        with tarfile.open(txz, "w:xz") as tar:
            tar.add(file_path, "a_file.txt")

        dest_folder = temp_folder()
        unzip(txz, dest_folder, output=ConanOutput(StringIO()))
        content = load(os.path.join(dest_folder, "a_file.txt"))
        self.assertEqual(content, "my content!")
예제 #7
0
    def test_invalid_flat_single_file(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            save("file1", "contentsfile1")

        zip_folder = temp_folder()
        zip_file = os.path.join(zip_folder, "file.zip")
        self._zipdir(tmp_folder, zip_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(self, ConanException, "The zip file contains a file in the root"):
            unzip(zip_file, destination=extract_folder, strip_root=True)
예제 #8
0
    def test_cache_config(self):
        file_path = os.path.join(temp_folder(), "whatever_cacert")
        save(file_path, "dummy")

        requester, mocked_requester, cache = self._create_requesters()
        replace_in_file(cache.conan_conf_path,
                        "# cacert_path",
                        "cacert_path={}".format(file_path),
                        output=TestBufferConanOutput())
        cache.invalidate()

        requester.get(url="bbbb", verify=True)
        self.assertEqual(mocked_requester.verify, file_path)
예제 #9
0
    def test_invalid_flat_single_file(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            save("file1", "contentsfile1")

        zip_folder = temp_folder()
        tgz_file = os.path.join(zip_folder, "file.tar.gz")
        self._compress_folder(tmp_folder, tgz_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(self, ConanException, "The tgz file contains a file in the root"):
            unzip(tgz_file, destination=extract_folder, strip_root=True, output=Mock())
예제 #10
0
    def test_linkame_striproot_folder(self):
        tmp_folder = temp_folder()
        other_tmp_folder = temp_folder()
        save(os.path.join(other_tmp_folder, "foo.txt"), "")
        tgz_path = os.path.join(tmp_folder, "foo.tgz")

        with open(tgz_path, "wb") as tgz_handle:
            tgz = gzopen_without_timestamps("name",
                                            mode="w",
                                            fileobj=tgz_handle)

            # Regular file
            info = tarfile.TarInfo(name="common/foo.txt")
            info.name = "common/subfolder/foo.txt"
            info.path = "common/subfolder/foo.txt"
            with open(os.path.join(other_tmp_folder, "foo.txt"),
                      'rb') as file_handler:
                tgz.addfile(tarinfo=info, fileobj=file_handler)

            # A hardlink to the regular file
            info = tarfile.TarInfo(name="common/foo.txt")
            info.linkname = "common/subfolder/foo.txt"
            info.linkpath = "common/subfolder/foo.txt"
            info.name = "common/subfolder/bar/foo.txt"
            info.path = "common/subfolder/bar/foo.txt"
            info.type = b'1'  # This indicates a hardlink to the tgz file "common/subfolder/foo.txt"
            tgz.addfile(tarinfo=info, fileobj=None)
            tgz.close()

        assert not os.path.exists(
            os.path.join(tmp_folder, "subfolder", "foo.txt"))
        assert not os.path.exists(
            os.path.join(tmp_folder, "subfolder", "bar", "foo.txt"))
        untargz(tgz_path, destination=tmp_folder, strip_root=True)
        assert os.path.exists(os.path.join(tmp_folder, "subfolder", "foo.txt"))
        assert os.path.exists(
            os.path.join(tmp_folder, "subfolder", "bar", "foo.txt"))

        # Check develop2 public unzip
        rmdir(os.path.join(tmp_folder, "subfolder"))
        assert not os.path.exists(
            os.path.join(tmp_folder, "subfolder", "foo.txt"))
        assert not os.path.exists(
            os.path.join(tmp_folder, "subfolder", "bar", "foo.txt"))
        unzip_dev2(ConanFileMock(),
                   tgz_path,
                   destination=tmp_folder,
                   strip_root=True)
        assert os.path.exists(os.path.join(tmp_folder, "subfolder", "foo.txt"))
        assert os.path.exists(
            os.path.join(tmp_folder, "subfolder", "bar", "foo.txt"))
예제 #11
0
 def test_cache_config(self):
     file_path = os.path.join(temp_folder(), "whatever_cacert")
     save(file_path, "")
     conan_conf = os.path.join(temp_folder(), "conan.conf")
     save(conan_conf, normalize(default_client_conf))
     replace_in_file(conan_conf,
                     "# cacert_path",
                     "cacert_path={}".format(file_path),
                     output=TestBufferConanOutput())
     config = ConanClientConfigParser(conan_conf)
     mocked_requester = MockRequesterGet()
     requester = ConanRequester(config, mocked_requester)
     requester.get(url="bbbb", verify=True)
     self.assertEqual(mocked_requester.verify, file_path)
예제 #12
0
    def test_cache_config(self):
        cache = ClientCache(temp_folder(), TestBufferConanOutput())
        file_path = os.path.join(cache.cache_folder, "whatever_cacert")
        replace_in_file(cache.conan_conf_path,
                        "# cacert_path",
                        "cacert_path={}".format(file_path),
                        output=TestBufferConanOutput())
        save(file_path, "")
        cache.invalidate()

        requester = ConanRequester(cache.config)
        mocked_requester = MockRequesterGet()
        requester._http_requester = mocked_requester
        requester.get(url="bbbb", verify=True)
        self.assertEqual(mocked_requester.verify, file_path)
예제 #13
0
    def test_invalid_flat(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            # Not a single dir containing everything
            file1 = os.path.join(tmp_folder, "subfolder-1.2.3", "folder2", "file1")
            file2 = os.path.join(tmp_folder, "other-1.2.3", "folder", "file2")

            save(file1, "")
            save(file2, "")

        tgz_folder = temp_folder()
        tgz_file = os.path.join(tgz_folder, "file.tar.gz")
        self._compress_folder(tmp_folder, tgz_file)

        extract_folder = temp_folder()
        with six.assertRaisesRegex(self, ConanException, "The tgz file contains more than 1 folder "
                                                         "in the root"):
            untargz(tgz_file, destination=extract_folder, strip_root=True)
예제 #14
0
    def test_plain_tgz_common_base(self):

        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            # Create a couple of files
            ori_files_dir = os.path.join(tmp_folder, "subfolder-1.2.3")
            file1 = os.path.join(ori_files_dir, "folder", "file1")
            file2 = os.path.join(ori_files_dir, "folder", "file2")
            file3 = os.path.join(ori_files_dir, "folder", "file3")

            save(file1, "")
            save(file2, "")
            save(file3, "")

        tgz_folder = temp_folder()
        tgz_file = os.path.join(tgz_folder, "file.tar.gz")
        self._compress_folder(tmp_folder, tgz_file)

        # Tgz unzipped regularly
        extract_folder = temp_folder()
        untargz(tgz_file, destination=extract_folder, strip_root=True)
        self.assertFalse(
            os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3")))
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "folder", "file1")))
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "folder", "file2")))
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "folder", "file3")))
예제 #15
0
def test_configure_arguments():
    tmp = temp_folder()
    os.chdir(tmp)
    save(
        CONAN_TOOLCHAIN_ARGS_FILE, """
    {"configure_args": "my_configure_args",
     "make_args": "my_make_args"}
    """)
    runner = RunnerMock()
    conanfile = ConanFile(Mock(), runner=runner)
    conanfile.settings = MockSettings({})
    conanfile.folders.set_base_install(tmp)
    conanfile.folders.set_base_source(tmp)
    conanfile.conf = Conf()
    conanfile.conf["tools.gnu:make_program"] = "my_make"
    conanfile.conf["tools.gnu.make:jobs"] = "23"
    ab = Autotools(conanfile)
    ab.configure()
    assert "configure my_configure_args" in runner.command_called

    ab = Autotools(conanfile)
    ab.make()
    assert "my_make my_make_args -j23" in runner.command_called
예제 #16
0
    def test_plain_zip(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            ori_files_dir = os.path.join(tmp_folder, "subfolder-1.2.3")
            file1 = os.path.join(ori_files_dir, "file1")
            file2 = os.path.join(ori_files_dir, "folder", "file2")
            file3 = os.path.join(ori_files_dir, "file3")

            save(file1, "")
            save(file2, "")
            save(file3, "")

        zip_file = os.path.join(tmp_folder, "myzip.zip")
        # Zip with a "folder_entry" in the zip (not only for the files)
        self._zipdir(tmp_folder, zip_file, folder_entry="subfolder-1.2.3")

        # ZIP unzipped regularly
        extract_folder = temp_folder()
        output = TestBufferConanOutput()
        unzip(zip_file,
              destination=extract_folder,
              strip_root=False,
              output=output)
        self.assertNotIn("ERROR: Error extract", output)
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "file1")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "folder",
                             "file2")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "file3")))

        # Extract without the subfolder
        extract_folder = temp_folder()
        output = TestBufferConanOutput()
        unzip(zip_file,
              destination=extract_folder,
              strip_root=True,
              output=output)
        self.assertNotIn("ERROR: Error extract", output)
        self.assertFalse(
            os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3")))
        self.assertTrue(os.path.exists(os.path.join(extract_folder, "file1")))
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "folder", "file2")))
        self.assertTrue(os.path.exists(os.path.join(extract_folder, "file3")))
예제 #17
0
 def root(self, content, processed_profile):
     conan_path = os.path.join(self.folder, ".conan", "data", "root.py")
     save(conan_path, content)
     conanfile = self.loader.load_consumer(conan_path, processed_profile)
     return Node(None, conanfile, "rootpath")
예제 #18
0
 def conan(self, conan_ref, content):
     if isinstance(conan_ref, str):
         conan_ref = ConanFileReference.loads(conan_ref)
     conan_path = os.path.join(self.folder, conan_ref.dir_repr(), CONANFILE)
     save(conan_path, content)
예제 #19
0
 def root(self, content, processed_profile):
     conan_path = os.path.join(self.folder, "root.py")
     save(conan_path, content)
     conanfile = self.loader.load_conanfile(conan_path, self.output, processed_profile,
                                            consumer=True)
     return Node(None, conanfile)