def load_imports_arguments_test(self):
        file_content = '''
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib @ root_package=Pkg
OpenCV/data, * -> ./data @ root_package=Pkg, folder=True # Irrelevant
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c" # Other
licenses, * -> ./licenses @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c", keep_path=False # Other
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, TestBufferConanOutput(), None)
        ret = loader.load_conanfile_txt(file_path, test_profile())

        ret.copy = Mock()
        ret.imports()
        expected = [
            call(u'*', u'./bin', u'OpenCV/bin', None, False, False, None,
                 True),
            call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, False, None,
                 True),
            call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, False, None,
                 True),
            call(u'*', u'./docs', u'docs', u'Pkg', True, True,
                 [u'"a', u'b', u'c"'], True),
            call(u'*', u'./licenses', u'licenses', u'Pkg', True, True,
                 [u'"a', u'b', u'c"'], False)
        ]
        self.assertEqual(ret.copy.call_args_list, expected)
 def build_graph(self, content, update=False):
     self.loader._cached_conanfile_classes = {}
     profile = test_profile()
     root_conan = self.retriever.root(str(content), profile)
     deps_graph = self.builder.load_graph(root_conan, update, update,
                                          self.remotes, profile)
     self.output.write("\n".join(self.resolver.output))
     return deps_graph
Exemple #3
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))
        ret = loader.load_consumer(file_path, test_profile())
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEqual(content, msg)
Exemple #4
0
 def load_options_error_test(self):
     conanfile_txt = textwrap.dedent("""
         [options]
         myoption: myvalue
     """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "file.txt")
     save(file_path, conanfile_txt)
     loader = ConanFileLoader(None, TestBufferConanOutput(), None)
     with six.assertRaisesRegex(
             self, ConanException,
             r"Error while parsing \[options\] in conanfile\n"
             "Options should be specified as 'pkg:option=value'"):
         loader.load_conanfile_txt(file_path, test_profile())
    def requires_init_test(self):
        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    def requirements(self):
        self.requires("MyPkg/0.1@user/channel")
"""
        for requires in ("''", "[]", "()", "None"):
            save(conanfile_path, conanfile.format(requires))
            result = loader.load_consumer(conanfile_path, profile_host=test_profile())
            result.requirements()
            self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
    def inherit_short_paths_test(self):
        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = loader.load_basic(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_consumer(conanfile_path, profile_host=test_profile())
        self.assertEqual(result.short_paths, True)
Exemple #7
0
    def complete_test(self):
        """ basic installation of a new conans
        """
        client = TestClient()
        files = cpp_hello_source_files()

        ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable")
        reg_folder = client.cache.package_layout(ref).export()

        client.save(files, path=reg_folder)
        client.save(
            {
                CONANFILE: myconan1,
                "infos/%s" % CONANINFO: "//empty",
                "include/no_copy/lib0.h": "NO copy",
                "include/math/lib1.h": "copy",
                "include/math/lib2.h": "copy",
                "include/physics/lib.hpp": "copy",
                "my_lib/debug/libd.a": "copy",
                "my_data/readme.txt": "copy",
                "my_data/readme.md": "NO copy",
                "contrib/math/math.h": "copy",
                "contrib/physics/gravity.h": "copy",
                "contrib/contrib.h": "copy",
                "include/opencv/opencv.hpp": "copy",
                "include/opencv2/opencv2.hpp": "copy",
                "modules/simu/src/simu.cpp": "NO copy",
                "modules/simu/include/opencv2/simu/simu.hpp": "copy",
                "modules/3D/doc/readme.md": "NO copy",
                "modules/3D/include/opencv2/3D/3D.hpp": "copy",
                "modules/dev/src/dev.cpp": "NO copy",
                "modules/dev/include/opencv2/dev/dev.hpp": "copy",
                "modules/opencv_mod.hpp": "copy"
            },
            path=reg_folder)

        conanfile_path = os.path.join(reg_folder, CONANFILE)
        pref = PackageReference(ref, "myfakeid")
        build_folder = client.cache.package_layout(pref.ref).build(pref)
        package_folder = client.cache.package_layout(pref.ref).package(pref)
        install_folder = os.path.join(build_folder, "infos")

        shutil.copytree(reg_folder, build_folder)

        loader = ConanFileLoader(None, TestBufferConanOutput(),
                                 ConanPythonRequire(None, None))
        conanfile = loader.load_consumer(conanfile_path, test_profile())

        run_package_method(conanfile,
                           None,
                           build_folder,
                           build_folder,
                           package_folder,
                           install_folder,
                           Mock(),
                           conanfile_path,
                           ref,
                           copy_info=True)

        # test build folder
        self.assertTrue(os.path.exists(build_folder))
        self.assertTrue(os.path.exists(os.path.join(package_folder,
                                                    CONANINFO)))

        # test pack folder
        self.assertTrue(os.path.exists(package_folder))

        def exist(rel_path):
            return os.path.exists(os.path.join(package_folder, rel_path))

        # Expected files
        self.assertTrue(exist("include/lib1.h"))
        self.assertTrue(exist("include/lib2.h"))
        self.assertTrue(exist("include/physics/lib.hpp"))
        self.assertTrue(exist("include/contrib/math/math.h"))
        self.assertTrue(exist("include/contrib/physics/gravity.h"))
        self.assertTrue(exist("include/contrib/contrib.h"))
        self.assertTrue(exist("include/opencv/opencv.hpp"))
        self.assertTrue(exist("include/opencv2/opencv2.hpp"))
        self.assertTrue(exist("include/opencv2/simu/simu.hpp"))
        self.assertTrue(exist("include/opencv2/3D/3D.hpp"))
        self.assertTrue(exist("include/opencv2/dev/dev.hpp"))
        self.assertTrue(exist("lib/my_lib/libd.a"))
        self.assertTrue(exist("res/shares/readme.txt"))

        # Not expected files
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/opencv2/simu.hpp"))
        self.assertFalse(exist("include/opencv2/3D.hpp"))
        self.assertFalse(exist("include/opencv2/dev.hpp"))
        self.assertFalse(exist("include/modules/simu/src/simu.cpp"))
        self.assertFalse(exist("include/modules/3D/doc/readme.md"))
        self.assertFalse(exist("include/modules/dev/src/dev.cpp"))
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/include/no_copy/lib0.h"))
        self.assertFalse(exist("res/my_data/readme.md"))
    def load_conan_txt_test(self):
        file_content = '''[requires]
OpenCV/2.4.10@phil/stable
OpenCV2/2.4.10@phil/stable
[build_requires]
MyPkg/1.0.0@phil/stable
[generators]
one
two
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib
[options]
OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, TestBufferConanOutput(), None)
        ret = loader.load_conanfile_txt(file_path, test_profile())
        options1 = OptionsValues.loads("""OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa""")
        requirements = Requirements()
        requirements.add("OpenCV/2.4.10@phil/stable")
        requirements.add("OpenCV2/2.4.10@phil/stable")
        build_requirements = []
        build_requirements.append("MyPkg/1.0.0@phil/stable")

        self.assertEqual(ret.requires, requirements)
        self.assertEqual(ret.build_requires, build_requirements)
        self.assertEqual(ret.generators, ["one", "two"])
        self.assertEqual(ret.options.values.dumps(), options1.dumps())

        ret.copy = Mock()
        ret.imports()

        self.assertTrue(ret.copy.call_args_list,
                        [('*', './bin', 'OpenCV/bin'),
                         ('*', './lib', 'OpenCV/lib')])

        # Now something that fails
        file_content = '''[requires]
OpenCV/2.4.104phil/stable
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, TestBufferConanOutput(), None)
        with six.assertRaisesRegex(self, ConanException,
                                   "The reference has too many '/'"):
            loader.load_conanfile_txt(file_path, test_profile())

        file_content = '''[requires]
OpenCV/2.4.10@phil/stable111111111111111111111111111111111111111111111111111111111111111
[imports]
OpenCV/bin/* - ./bin
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, TestBufferConanOutput(), None)
        with six.assertRaisesRegex(self, ConanException,
                                   "is too long. Valid names must contain"):
            loader.load_conanfile_txt(file_path, test_profile())