diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index bfbc3e05..52f94458 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -17,6 +17,15 @@ pipeline { sh '.ci/generate_env_macos.sh' } } + stage('Macos - py36 - conandev2') { + environment { + PYVER = 'py36' + TOXENV = 'py36-conandev2' + } + steps { + sh '.ci/run_tox.sh' + } + } stage('Macos - py36 - conandev') { environment { PYVER = 'py36' @@ -50,6 +59,15 @@ pipeline { sh '.ci/generate_env_macos.sh' } } + stage('Macos - py39 - conande2') { + environment { + PYVER = 'py39' + TOXENV = 'py39-conandev2' + } + steps { + sh '.ci/run_tox.sh' + } + } stage('Macos - py39 - conandev') { environment { PYVER = 'py39' diff --git a/hooks/non_ascii.py b/hooks/non_ascii.py index e133d6c4..86df47f8 100644 --- a/hooks/non_ascii.py +++ b/hooks/non_ascii.py @@ -2,7 +2,19 @@ import os import unicodedata -from conans import tools + + +def load(conanfile, filename): + try: + from conans.tools import load + v2 = False + except ImportError: + from conan.tools.files import load + v2 = True + if v2: + return load(conanfile, filename) + else: + return load(filename) def check_non_ascii(filename, content, output): @@ -23,10 +35,10 @@ def check_non_ascii(filename, content, output): def pre_export(output, conanfile, conanfile_path, reference, **kwargs): - conanfile_content = tools.load(conanfile_path) + conanfile_content = load(conanfile, conanfile_path) check_non_ascii("conanfile.py", conanfile_content, output) test_package_dir = os.path.join(os.path.dirname(conanfile_path), "test_package") test_package_path = os.path.join(test_package_dir, "conanfile.py") if os.path.exists(test_package_path): - test_package_content = tools.load(test_package_path) + test_package_content = load(conanfile, test_package_path) check_non_ascii("test_package/conanfile.py", test_package_content) diff --git a/tests/test_hooks/conan-center/test_build_info.py b/tests/test_hooks/conan-center/test_build_info.py index 3db58cd6..b9878a4e 100644 --- a/tests/test_hooks/conan-center/test_build_info.py +++ b/tests/test_hooks/conan-center/test_build_info.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestBuildInfo(ConanClientTestCase): @@ -15,7 +16,7 @@ def _get_environ(self, **kwargs): return kwargs def test_trivial_ok(self): - tools.save("conanfile.py", content=textwrap.dedent("""\ + save("conanfile.py", content=textwrap.dedent("""\ from conans import ConanFile class AConan(ConanFile): @@ -25,7 +26,7 @@ class AConan(ConanFile): self.assertIn("[NO BUILD SYSTEM FUNCTIONS (KB-H061)] OK", output) def test_build_toolsosinfo_ok(self): - tools.save("conanfile.py", content=textwrap.dedent("""\ + save("conanfile.py", content=textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): @@ -37,7 +38,7 @@ def build(self): self.assertIn("[NO BUILD SYSTEM FUNCTIONS (KB-H061)] OK", output) def test_build_platform_ok(self): - tools.save("conanfile.py", content=textwrap.dedent("""\ + save("conanfile.py", content=textwrap.dedent("""\ from conans import ConanFile import platform @@ -50,7 +51,7 @@ def build(self): self.assertIn("[NO BUILD SYSTEM FUNCTIONS (KB-H061)] OK", output) def test_buildreq_toolsosinfo(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): @@ -64,7 +65,7 @@ def build_requirements(self): self.assertIn("conanfile.py:5 Build system dependent", output) def test_buildreq_platform(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools import platform @@ -79,7 +80,7 @@ def build_requirements(self): self.assertIn("conanfile.py:6 Build system dependent", output) def test_req_toolsosinfo(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): @@ -93,7 +94,7 @@ def requirements(self): self.assertIn("conanfile.py:5 Build system dependent", output) def test_req_platform(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools import platform @@ -108,7 +109,7 @@ def requirements(self): self.assertIn("conanfile.py:6 Build system dependent", output) def test_configopts_toolsosinfo(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): @@ -122,7 +123,7 @@ def config_options(self): self.assertIn("conanfile.py:5 Build system dependent", output) def test_configopts_platform(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools import platform @@ -137,7 +138,7 @@ def config_options(self): self.assertIn("conanfile.py:6 Build system dependent", output) def test_config_toolsosinfo(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): @@ -151,7 +152,7 @@ def configure(self): self.assertIn("conanfile.py:5 Build system dependent", output) def test_config_platform(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools import platform @@ -166,7 +167,7 @@ def configure(self): self.assertIn("conanfile.py:6 Build system dependent", output) def test_validate_toolsosinfo(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools from conans.errors import ConanInvalidConfiguration @@ -181,7 +182,7 @@ def validate(self): self.assertIn("conanfile.py:6 Build system dependent", output) def test_validate_platform(self): - tools.save("conanfile.py", textwrap.dedent("""\ + save("conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools from conans.errors import ConanInvalidConfiguration import platform @@ -204,7 +205,7 @@ def config_options(self): if tools.os_info.is_windows: pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) @@ -216,7 +217,7 @@ def configure(self): if tools.os_info.is_linux: pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) @@ -229,6 +230,6 @@ def configure(self): if os_info.is_macos: pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) diff --git a/tests/test_hooks/conan-center/test_cmake_bad_files.py b/tests/test_hooks/conan-center/test_cmake_bad_files.py index 5c323eed..9e293bc1 100644 --- a/tests/test_hooks/conan-center/test_cmake_bad_files.py +++ b/tests/test_hooks/conan-center/test_cmake_bad_files.py @@ -5,6 +5,7 @@ from conans import __version__ as conan_version from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save @unittest.skipUnless(conan_version >= "1.16.0", "Conan > 1.16.0 needed") @@ -41,13 +42,13 @@ def _get_environ(self, **kwargs): def test_find_and_config_files(self): - tools.save('conanfile.py', content=self.conan_file.format("", "WhateverConfig.cmake")) + save('conanfile.py', content=self.conan_file.format("", "WhateverConfig.cmake")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files: ./WhateverConfig.cmake", output) def test_find_and_find_files(self): - tools.save('conanfile.py', content=self.conan_file.format("", "FindXXX.cmake")) + save('conanfile.py', content=self.conan_file.format("", "FindXXX.cmake")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files: ./FindXXX.cmake", output) @@ -63,19 +64,19 @@ def package(self): tools.save(os.path.join(self.package_folder, "FindXXX.cmake"), "foo") tools.save(os.path.join(self.package_folder, "XXXConfig.cmake"), "foo") """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files: ./FindXXX.cmake; ./XXXConfig.cmake", output) def test_find_files_outside_dir(self): - tools.save('conanfile.py', content=self.conan_file.format("folder", "file.cmake")) + save('conanfile.py', content=self.conan_file.format("folder", "file.cmake")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("WARN: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)] Found files: " "./folder/file.cmake", output.replace("\\", "/")) - tools.save('conanfile.py', content=self.conan_file.format("", "file.cmake")) + save('conanfile.py', content=self.conan_file.format("", "file.cmake")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) @@ -92,20 +93,20 @@ def package_info(self): self.cpp_info.builddirs = ["some_build_dir"] """) - tools.save('conanfile.py', content=conanfile2.format("some_build_dir")) + save('conanfile.py', content=conanfile2.format("some_build_dir")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) - tools.save('conanfile.py', content=conanfile2.format("some_build_dir/subdir")) + save('conanfile.py', content=conanfile2.format("some_build_dir/subdir")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) def test_good_files(self): - tools.save('conanfile.py', content=self.conan_file_info.format('os.path.join("lib", "cmake", "script.cmake")', ["lib/cmake"])) + save('conanfile.py', content=self.conan_file_info.format('os.path.join("lib", "cmake", "script.cmake")', ["lib/cmake"])) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) - tools.save('conanfile.py', content=self.conan_file_info.format('os.path.join("lib", "cmake", "script.cmake")', ["lib\\cmake"])) + save('conanfile.py', content=self.conan_file_info.format('os.path.join("lib", "cmake", "script.cmake")', ["lib\\cmake"])) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) @@ -123,6 +124,6 @@ def package_info(self): self.cpp_info.components["baz"].names["cmake_find_package_multi"] = "baz" self.cpp_info.components["baz"].builddirs = [os.path.join("lib", "cmake")] """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) diff --git a/tests/test_hooks/conan-center/test_conan-center.py b/tests/test_hooks/conan-center/test_conan-center.py index 1b9495fd..e1894a6b 100644 --- a/tests/test_hooks/conan-center/test_conan-center.py +++ b/tests/test_hooks/conan-center/test_conan-center.py @@ -9,11 +9,15 @@ from conans import tools -from conans.client.command import ERROR_INVALID_CONFIGURATION, SUCCESS, ERROR_GENERAL +try: + from conans.client.command import ERROR_INVALID_CONFIGURATION, SUCCESS, ERROR_GENERAL +except ImportError: + from conans.cli.exit_codes import ERROR_INVALID_CONFIGURATION, SUCCESS, ERROR_GENERAL from conans.tools import Version from conans import __version__ as conan_version from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class ConanCenterTests(ConanClientTestCase): @@ -94,13 +98,13 @@ def _get_environ(self, **kwargs): return kwargs def test_no_duplicated_messages(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("ERROR: [PACKAGE LICENSE (KB-H012)] No 'licenses' folder found in package", output) self.assertNotIn("[PACKAGE LICENSE (KB-H012)] OK", output) def test_conanfile(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA (KB-H003)] OK", output) self.assertIn("[HEADER_ONLY, NO COPY SOURCE (KB-H005)] OK", output) @@ -124,8 +128,8 @@ def test_conanfile(self): self.assertIn("[SINGLE REQUIRES (KB-H055)] OK", output) def test_conanfile_header_only(self): - tools.save('conanfile.py', content=self.conanfile_header_only) - tools.save('header.h', content="") + save('conanfile.py', content=self.conanfile_header_only) + save('header.h', content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA (KB-H003)] OK", output) self.assertIn("[HEADER_ONLY, NO COPY SOURCE (KB-H005)] This recipe is a header only library", output) @@ -147,8 +151,8 @@ def test_conanfile_header_only(self): self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) def test_conanfile_header_only_with_settings(self): - tools.save('conanfile.py', content=self.conanfile_header_only_with_settings) - tools.save('header.h', content="") + save('conanfile.py', content=self.conanfile_header_only_with_settings) + save('header.h', content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA (KB-H003)] OK", output) self.assertIn("[HEADER_ONLY, NO COPY SOURCE (KB-H005)] OK", output) @@ -168,8 +172,8 @@ def test_conanfile_header_only_with_settings(self): self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) def test_conanfile_settings_clear_with_settings(self): - tools.save('conanfile.py', content=self.conanfile_settings_clear_with_settings) - tools.save('header.h', content="") + save('conanfile.py', content=self.conanfile_settings_clear_with_settings) + save('header.h', content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA (KB-H003)] OK", output) self.assertIn("[HEADER_ONLY, NO COPY SOURCE (KB-H005)] OK", output) @@ -189,7 +193,7 @@ def test_conanfile_settings_clear_with_settings(self): self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) def test_conanfile_installer(self): - tools.save('conanfile.py', content=self.conanfile_installer) + save('conanfile.py', content=self.conanfile_installer) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA (KB-H003)] OK", output) self.assertIn("[HEADER_ONLY, NO COPY SOURCE (KB-H005)] OK", output) @@ -228,7 +232,7 @@ def package(self): # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [META LINES (KB-H025)] PEP 263 (encoding) is not allowed in the " \ "conanfile. Remove the line 2", output) @@ -249,8 +253,8 @@ def test(self): with tools.environment_append(env_build.vars): self.run("echo bar") """) - tools.save('test_package/conanfile.py', content=conanfile_tp) - tools.save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[TEST PACKAGE FOLDER (KB-H024)] OK", output) self.assertIn("ERROR: [TEST PACKAGE - RUN ENVIRONMENT (KB-H029)] The 'RunEnvironment()' " @@ -267,8 +271,8 @@ def test(self): self.run("echo bar", run_environment=True) """) - tools.save('test_package/conanfile.py', content=conanfile_tp) - tools.save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[TEST PACKAGE FOLDER (KB-H024)] OK", output) self.assertIn("[TEST PACKAGE - RUN ENVIRONMENT (KB-H029)] OK", output) @@ -290,8 +294,8 @@ def test(self): self.run("echo bar", run_environment=True) """) - tools.save('test_package/conanfile.py', content=conanfile_tp) - tools.save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[TEST PACKAGE FOLDER (KB-H024)] OK", output) self.assertIn("[TEST PACKAGE - RUN ENVIRONMENT (KB-H029)] OK", output) @@ -299,19 +303,19 @@ def test(self): self.assertIn("[TEST PACKAGE - NO IMPORTS() (KB-H034)] OK", output) def test_exports_licenses(self): - tools.save('conanfile.py', + save('conanfile.py', content=self.conanfile_base.format(placeholder='exports = "LICENSE"')) output = self.conan(['create', '.', 'name/version@name/test']) self.assertIn("ERROR: [EXPORT LICENSE (KB-H023)] This recipe is exporting a license file." \ " Remove LICENSE from `exports`", output) - tools.save('conanfile.py', + save('conanfile.py', content=self.conanfile_base.format(placeholder='exports_sources = "LICENSE"')) output = self.conan(['create', '.', 'name/version@name/test']) self.assertIn("ERROR: [EXPORT LICENSE (KB-H023)] This recipe is exporting a license file." \ " Remove LICENSE from `exports_sources`", output) - tools.save('conanfile.py', + save('conanfile.py', content=self.conanfile_base.format(placeholder='exports = ["foobar", "COPYING.md"]')) output = self.conan(['create', '.', 'name/version@name/test']) self.assertIn("ERROR: [EXPORT LICENSE (KB-H023)] This recipe is exporting a license file." \ @@ -329,7 +333,7 @@ class LinuxOnly(ConanFile): options = {"fPIC": [True, False], "shared": [True, False]} default_options = {"fPIC": True, "shared": False} """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'package/version@conan/test']) self.assertIn("[FPIC OPTION (KB-H006)] OK", output) if tools.os_info.is_windows: @@ -360,7 +364,7 @@ def config_options(self): if self.settings.os == "Windows": del self.options.fPIC """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'package/version@conan/test']) self.assertIn("[FPIC OPTION (KB-H006)] OK", output) if platform.system() == "Windows": @@ -387,7 +391,7 @@ def configure(self): if self.settings.os == "Windows": raise ConanInvalidConfiguration("Windows not supported") """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) if platform.system() == "Windows": expected_return_code = ERROR_INVALID_CONFIGURATION else: @@ -414,8 +418,8 @@ def package(self): self.copy("*", dst="include") """) - tools.save('test.c', content="#define FOO 1") - tools.save('conanfile.py', content=content.format( + save('test.c', content="#define FOO 1") + save('conanfile.py', content=content.format( configure="pass")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [LIBCXX MANAGEMENT (KB-H011)] Can't detect C++ source files but " \ @@ -423,7 +427,7 @@ def package(self): self.assertIn("ERROR: [CPPSTD MANAGEMENT (KB-H022)] Can't detect C++ source files but " \ "recipe does not remove 'self.settings.compiler.cppstd'", output) - tools.save('conanfile.py', content=content.format(configure=""" + save('conanfile.py', content=content.format(configure=""" del self.settings.compiler.libcxx del self.settings.compiler.cppstd""")) output = self.conan(['create', '.', 'name/version@user/test']) @@ -446,13 +450,13 @@ class AConan(ConanFile): "ERROR: [RECIPE METADATA (KB-H003)] Conanfile doesn't have 'topics' attribute." ] - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) for msg in bad_recipe_output: self.assertIn(msg, output) self.assertNotIn("[RECIPE METADATA (KB-H003)] OK", output) - tools.save('conanfile.py', content=self.conanfile_base.format(placeholder='')) + save('conanfile.py', content=self.conanfile_base.format(placeholder='')) output = self.conan(['create', '.', 'name/version@user/test']) for msg in bad_recipe_output: self.assertNotIn(msg, output) @@ -460,7 +464,7 @@ class AConan(ConanFile): for before, after in [('"name" =', '"name" = '), (' "name" =', '\t"name"\t= ')]: - tools.save('conanfile.py', + save('conanfile.py', content=self.conanfile_header_only_with_settings.replace(before, after)) output = self.conan(['create', '.', 'name/version@user/test']) for msg in bad_recipe_output: @@ -478,7 +482,7 @@ class AConan(ConanFile): def package(self): self.copy("*", dst="include") """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[CONAN CENTER INDEX URL (KB-H027)] OK", output) @@ -486,8 +490,8 @@ def test_cmake_minimum_version(self): conanfile = self.conanfile_base.format(placeholder="exports_sources = \"CMakeLists.txt\"") cmake = """project(test) """ - tools.save('conanfile.py', content=conanfile) - tools.save('CMakeLists.txt', content=cmake) + save('conanfile.py', content=conanfile) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) path = os.path.join(".", "CMakeLists.txt") self.assertIn("ERROR: [CMAKE MINIMUM VERSION (KB-H028)] The CMake file '%s' must contain a " @@ -500,7 +504,7 @@ def test_cmake_minimum_version(self): cmake_minimum_required(VERSION 2.8) project(test) """) - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) @@ -509,7 +513,7 @@ def test_cmake_minimum_version(self): cmake_minimum_required(VERSION 2.8) project(test) """) - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) @@ -530,10 +534,10 @@ def test(self): cmake = """cmake_minimum_required(VERSION 2.8.11) project(test) """ - tools.save('conanfile.py', content=conanfile) - tools.save('CMakeLists.txt', content=cmake) - tools.save('test_package/CMakeLists.txt', content=cmake) - tools.save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=conanfile) + save('CMakeLists.txt', content=cmake) + save('test_package/CMakeLists.txt', content=cmake) + save('test_package/conanfile.py', content=conanfile_tp) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) # validate residual cmake files in test_package/build @@ -544,14 +548,14 @@ def test(self): cmake = textwrap.dedent("""CMAKE_MINIMUM_REQUIRED (VERSION 2.8.11) project(test) """) - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) cmake = textwrap.dedent("""cmake_minimum_required(VERSION 2.8.11) project(test) """) - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) self.assertNotIn("ERROR: [CMAKE MINIMUM VERSION (KB-H028)]", output) @@ -559,7 +563,7 @@ def test(self): cmake = textwrap.dedent("""project(test) cmake_minimum_required(VERSION 2.8.11) """) - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE MINIMUM VERSION (KB-H028)]", output) self.assertNotIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) @@ -567,11 +571,11 @@ def test(self): cmake = """cmake_minimum_required(VERSION 2.8.11) project(test) """ - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) cmake = textwrap.dedent("""project(test) cmake_minimum_required(VERSION 2.8.11) """) - tools.save('test_package/CMakeLists.txt', content=cmake) + save('test_package/CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE MINIMUM VERSION (KB-H028)]", output) self.assertNotIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) @@ -587,18 +591,18 @@ class SystemReqConan(ConanFile): def system_requirements(self): installer = SystemPackageTool() """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) conanfile += " installer.install([])" - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [SYSTEM REQUIREMENTS (KB-H032)] The method " \ "'SystemPackageTool.install' is not allowed in the recipe.", output) conanfile = conanfile.replace("installer.install([])", "SystemPackageTool().install([])") - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [SYSTEM REQUIREMENTS (KB-H032)] The method " \ "'SystemPackageTool.install' is not allowed in the recipe.", output) @@ -618,8 +622,8 @@ def test(self): self.run("echo bar", run_environment=True) """) - tools.save('test_package/conanfile.py', content=conanfile_tp) - tools.save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[TEST PACKAGE FOLDER (KB-H024)] OK", output) self.assertIn("[TEST PACKAGE - RUN ENVIRONMENT (KB-H029)] OK", output) @@ -632,7 +636,7 @@ def test_requirements_add(self): class AConan(ConanFile): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[NO REQUIRES.ADD() (KB-H044)] OK", output) @@ -643,12 +647,12 @@ def requirements(self): {} """) - tools.save('conanfile.py', + save('conanfile.py', content=conanfile.replace("{}", 'self.requires("name/version@user/test")')) output = self.conan(['create', '.', 'foo/version@user/test']) self.assertIn("[NO REQUIRES.ADD() (KB-H044)] OK", output) - tools.save('conanfile.py', + save('conanfile.py', content=conanfile.replace("{}", 'self.requires.add("name/version@user/test")')) output = self.conan(['create', '.', 'foo/version@user/test']) self.assertIn("[NO REQUIRES.ADD() (KB-H044)] The method 'self.requires.add()' is not " \ @@ -661,14 +665,14 @@ def build_requirements(self): {} """) - tools.save('conanfile.py', + save('conanfile.py', content=conanfile.replace("{}", 'self.build_requires("name/version@user/test")')) output = self.conan(['create', '.', 'foo/version@user/test']) self.assertIn("[NO REQUIRES.ADD() (KB-H044)] OK", output) # Conan >= 1.23 requires "context" parameter for build_requires.add() if Version(conan_version) < "1.23": - tools.save('conanfile.py', + save('conanfile.py', content=conanfile.replace("{}", 'self.build_requires.add("name/version@user/test")')) output = self.conan(['create', '.', 'foo/version@user/test']) self.assertIn("[NO REQUIRES.ADD() (KB-H044)] The method 'self.build_requires.add()' is not " \ @@ -682,16 +686,16 @@ class AConan(ConanFile): def configure(self): pass """) - tools.save('conanfile.py', content=conanfile.replace("{}", "")) + save('conanfile.py', content=conanfile.replace("{}", "")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[NO AUTHOR (KB-H037)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("{}", "author = 'foobar'")) + save('conanfile.py', content=conanfile.replace("{}", "author = 'foobar'")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn('ERROR: [NO AUTHOR (KB-H037)] Conanfile should not contain author. ' 'Remove \'author = "foobar"\'', output) - tools.save('conanfile.py', content=conanfile.replace("{}", "author = ('foo', 'bar')")) + save('conanfile.py', content=conanfile.replace("{}", "author = ('foo', 'bar')")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn('ERROR: [NO AUTHOR (KB-H037)] Conanfile should not contain author. ' 'Remove \'author = (\'foo\', \'bar\')', output) @@ -705,7 +709,7 @@ def configure(self): pass """) - tools.save('conanfile.py', content=conanfile.replace("{}", "revision_mode = 'scm'")) + save('conanfile.py', content=conanfile.replace("{}", "revision_mode = 'scm'")) output = self.conan(['export', '.', 'name/version@user/test'], expected_return_code=ERROR_GENERAL) self.assertIn("ERROR: [NOT ALLOWED ATTRIBUTES (KB-H039)] Conanfile should not contain attributes: 'revision_mode'", output) @@ -715,7 +719,7 @@ def configure(self): "url": "auto", "revision": "auto"} """) - tools.save('conanfile.py', content=conanfile.replace("{}", scm)) + save('conanfile.py', content=conanfile.replace("{}", scm)) output = self.conan(['export', '.', 'name/version@user/test'], expected_return_code=ERROR_GENERAL) self.assertIn("ERROR: [NOT ALLOWED ATTRIBUTES (KB-H039)] Conanfile should not contain attributes: 'scm'", output) @@ -726,8 +730,8 @@ def test_cmake_verbose_makefile(self): cmake_minimum_required(VERSION 2.8.11) project(test) """) - tools.save('conanfile.py', content=conanfile) - tools.save('CMakeLists.txt', content=cmake) + save('conanfile.py', content=conanfile) + save('CMakeLists.txt', content=cmake) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[CMAKE VERBOSE MAKEFILE (KB-H046)] OK", output) @@ -736,7 +740,7 @@ def test_cmake_verbose_makefile(self): set(CMAKE_VERBOSE_MAKEFILE ON) """ - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) print("CWD: %s" % os.getcwd()) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE VERBOSE MAKEFILE (KB-H046)] The CMake definition " @@ -752,9 +756,9 @@ class TestConan(ConanFile): def test(self): pass """) - tools.save('test_package/conanfile.py', content=conanfile_tp) - tools.save('test_package/CMakeLists.txt', content=cmake) - tools.save('CMakeLists.txt', content=cmake.replace("set(CMAKE_VERBOSE_MAKEFILE ON)", "")) + save('test_package/conanfile.py', content=conanfile_tp) + save('test_package/CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake.replace("set(CMAKE_VERBOSE_MAKEFILE ON)", "")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertNotIn("Remove it from CMakeLists.txt", output) self.assertIn("ERROR: [CMAKE VERBOSE MAKEFILE (KB-H046)] The CMake definition " @@ -771,11 +775,11 @@ class AConan(ConanFile): def config_options(self): {} """) - tools.save('conanfile.py', content=conanfile.replace("{}", "del self.options.foo")) + save('conanfile.py', content=conanfile.replace("{}", "del self.options.foo")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[DELETE OPTIONS (KB-H045)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("{}", 'self.options.remove("foo")')) + save('conanfile.py', content=conanfile.replace("{}", 'self.options.remove("foo")')) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [DELETE OPTIONS (KB-H045)] Found 'self.options.remove'." " Replace it by 'del self.options.'.", output) @@ -786,20 +790,20 @@ def test_cmake_version_required(self): cmake_minimum_required(VERSION 2.8.11) project(test) """) - tools.save('conanfile.py', content=conanfile) - tools.save('CMakeLists.txt', content=cmake) + save('conanfile.py', content=conanfile) + save('CMakeLists.txt', content=cmake) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[CMAKE VERSION REQUIRED (KB-H048)] OK", output) for pair in [("", ""), ("2.8.11", '"2.8.11"'), ("2.8.11", "'2.8.11'")]: - tools.save('test_package/CMakeLists.txt', content=cmake.replace(*pair)) + save('test_package/CMakeLists.txt', content=cmake.replace(*pair)) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE VERSION REQUIRED (KB-H048)] The test_package/CMakeLists.txt " "requires CMake 3.1 at least." " Update to 'cmake_minimum_required(VERSION 3.1)'.", output) cmake += "set(CMAKE_CXX_STANDARD 11)" - tools.save('CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE VERSION REQUIRED (KB-H048)] The test_package/CMakeLists.txt " "requires CMake 3.1 at least." @@ -810,8 +814,8 @@ def test_cmake_version_required(self): project(test) set(CMAKE_CXX_STANDARD 11) """) - tools.save('CMakeLists.txt', content=cmake) - tools.save('test_package/CMakeLists.txt', content=cmake) + save('CMakeLists.txt', content=cmake) + save('test_package/CMakeLists.txt', content=cmake) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[CMAKE VERSION REQUIRED (KB-H048)] OK", output) @@ -823,18 +827,18 @@ def test_cmake_export_all_symbols_version_required(self): project(test) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) """) - tools.save('conanfile.py', content=conanfile) - tools.save('CMakeLists.txt', content=cmake) + save('conanfile.py', content=conanfile) + save('CMakeLists.txt', content=cmake) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[CMAKE WINDOWS EXPORT ALL SYMBOLS (KB-H049)] OK", output) - tools.save('CMakeLists.txt', content=cmake.replace("3.4", "2.8.12")) + save('CMakeLists.txt', content=cmake.replace("3.4", "2.8.12")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [CMAKE WINDOWS EXPORT ALL SYMBOLS (KB-H049)] The CMake definition " "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS requires CMake 3.4 at least. Update " "CMakeLists.txt to 'cmake_minimum_required(VERSION 3.4)'.", output) - tools.save('CMakeLists.txt', + save('CMakeLists.txt', content=cmake.replace("3.4", "3") .replace("CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS", "WINDOWS_EXPORT_ALL_SYMBOLS")) @@ -843,7 +847,7 @@ def test_cmake_export_all_symbols_version_required(self): "WINDOWS_EXPORT_ALL_SYMBOLS requires CMake 3.4 at least. Update " "CMakeLists.txt to 'cmake_minimum_required(VERSION 3.4)'.", output) - tools.save('CMakeLists.txt', content=cmake.replace("3.4", "3.17")) + save('CMakeLists.txt', content=cmake.replace("3.4", "3.17")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[CMAKE WINDOWS EXPORT ALL SYMBOLS (KB-H049)] OK", output) @@ -855,21 +859,21 @@ class AConan(ConanFile): default_options = {"shared": False} """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[DEFAULT SHARED OPTION VALUE (KB-H050)] OK", output) - tools.save('conanfile.py', content=self.conanfile_header_only) + save('conanfile.py', content=self.conanfile_header_only) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[DEFAULT SHARED OPTION VALUE (KB-H050)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("False}", "True}")) + save('conanfile.py', content=conanfile.replace("False}", "True}")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [DEFAULT SHARED OPTION VALUE (KB-H050)] The option 'shared' must be " "'False' by default. Update 'default_options'.", output) def test_missing_version_in_config(self): - tools.save(os.path.join('all', 'conanfile.py'), content=self.conanfile_base.format(placeholder='')) + save(os.path.join('all', 'conanfile.py'), content=self.conanfile_base.format(placeholder='')) conandata = textwrap.dedent(""" sources: 1.0: @@ -884,8 +888,8 @@ def test_missing_version_in_config(self): 1.0: folder:all """) - tools.save("config.yml", content=config) - tools.save(os.path.join("all", "conandata.yml"), content=conandata) + save("config.yml", content=config) + save(os.path.join("all", "conandata.yml"), content=conandata) output = self.conan(['export', 'all', 'name/version@user/test']) self.assertIn("ERROR: [CONFIG.YML HAS NEW VERSION (KB-H052)] The version \"2.0\" exists in", output) @@ -897,42 +901,42 @@ def test_missing_version_in_config(self): 2.0: folder:all """) - tools.save("config.yml", content=config) + save("config.yml", content=config) output = self.conan(['export', 'all', 'name/version@user/test']) self.assertNotIn("ERROR: [CONFIG.YML HAS NEW VERSION (KB-H052)] The version \"2.0\" exists in", output) def test_private_import(self): - tools.save('conanfile.py', content=self.conanfile_base.format(placeholder='')) + save('conanfile.py', content=self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[PRIVATE IMPORTS (KB-H053)] OK", output) - tools.save('conanfile.py', content="from conans.errors import ConanInvalidConfiguration\n" + + save('conanfile.py', content="from conans.errors import ConanInvalidConfiguration\n" + self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[PRIVATE IMPORTS (KB-H053)] OK", output) - tools.save('conanfile.py', content="from conans.tools import Version\n" + + save('conanfile.py', content="from conans.tools import Version\n" + self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[PRIVATE IMPORTS (KB-H053)] OK", output) - tools.save('conanfile.py', content="from conans.client.tools import msvs_toolset\n" + + save('conanfile.py', content="from conans.client.tools import msvs_toolset\n" + self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [PRIVATE IMPORTS (KB-H053)] The file conanfile.py imports private conan API on line 1", output) - tools.save('conanfile.py', content="from conans.model.version import Version\n" + + save('conanfile.py', content="from conans.model.version import Version\n" + self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [PRIVATE IMPORTS (KB-H053)] The file conanfile.py imports private conan API on line 1", output) - tools.save('conanfile.py', content="from conans.model import Generator\n" + + save('conanfile.py', content="from conans.model import Generator\n" + self.conanfile_base.format(placeholder='')) output = self.conan(['export', '.', 'name/version@']) self.assertIn("[PRIVATE IMPORTS (KB-H053)] OK", output) @@ -948,16 +952,16 @@ def {0}requirements(self): self.{0}requires("bar/0.1.0") """.format(prefix)) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[SINGLE REQUIRES (KB-H055)] Both '{0}requires' attribute and '{0}requirements()' " "method should not be declared at same recipe.".format(prefix), output) - tools.save('conanfile.py', content=conanfile.replace('{}requires = "foo/0.1.0"'.format(prefix), "")) + save('conanfile.py', content=conanfile.replace('{}requires = "foo/0.1.0"'.format(prefix), "")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[SINGLE REQUIRES (KB-H055)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("def {}requirements(self):".format(prefix), "") + save('conanfile.py', content=conanfile.replace("def {}requirements(self):".format(prefix), "") .replace('self.{}requires("bar/0.1.0")'.format(prefix), "")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[SINGLE REQUIRES (KB-H055)] OK", output) @@ -969,7 +973,7 @@ class AConan(ConanFile): license = "Public Domain" """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [LICENSE PUBLIC DOMAIN (KB-H056)] " \ "Public Domain is not a SPDX license. Use 'Unlicense' instead.", output) @@ -994,8 +998,8 @@ def test(self): os.rename("foo.txt", "bar.txt") """) - tools.save('conanfile.py', content=conanfile) - tools.save('test_package/conanfile.py', content=conanfile_tp) + save('conanfile.py', content=conanfile) + save('test_package/conanfile.py', content=conanfile_tp) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("WARN: [TOOLS RENAME (KB-H057)] The 'os.rename' in conanfile.py may cause" @@ -1003,8 +1007,8 @@ def test(self): self.assertIn("WARN: [TOOLS RENAME (KB-H057)] The 'os.rename' in test_package/conanfile.py" " may cause permission error on Windows. Use 'conan.tools.files.rename(self, src, dst)' instead.", output) - tools.save('conanfile.py', content=conanfile.replace("os.", "tools.")) - tools.save('test_package/conanfile.py', content=conanfile_tp.replace("os.", "tools.")) + save('conanfile.py', content=conanfile.replace("os.", "tools.")) + save('test_package/conanfile.py', content=conanfile_tp.replace("os.", "tools.")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("WARN: [TOOLS RENAME (KB-H057)] The 'tools.rename' in conanfile.py is outdated" " and may cause permission error on Windows. Use 'conan.tools.files.rename(self, src, dst)'" @@ -1014,8 +1018,8 @@ def test(self): " instead.", output) self.assertIn("[TOOLS RENAME (KB-H057)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("os.rename(", "tools.rename(self, ")) - tools.save('test_package/conanfile.py', content=conanfile_tp.replace("os.rename(", "tools.rename(self, ")) + save('conanfile.py', content=conanfile.replace("os.rename(", "tools.rename(self, ")) + save('test_package/conanfile.py', content=conanfile_tp.replace("os.rename(", "tools.rename(self, ")) output = self.conan(['export', '.', 'name/version@user/test']) self.assertNotIn("WARN: [TOOLS RENAME (KB-H057)]", output) self.assertIn("[TOOLS RENAME (KB-H057)] OK", output) @@ -1028,19 +1032,19 @@ class AConan(ConanFile): exports = "foo." """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("[ILLEGAL CHARACTERS (KB-H058)] OK", output) for filename in ["conanfile?.py", "conan file.py", "conanfile%.py"]: - tools.save(filename, content=conanfile) + save(filename, content=conanfile) output = self.conan(['export', filename, 'name/version@user/test']) self.assertIn("ERROR: [ILLEGAL CHARACTERS (KB-H058)] The file '{}' uses illegal" " charecters (<>:\"/\\|?*%,; ) for its name. Please, rename that file." .format(filename), output) - tools.save("conanfile.py", content=conanfile) - tools.save("foo.", content="") + save("conanfile.py", content=conanfile) + save("foo.", content="") output = self.conan(['export', "conanfile.py", 'name/version@user/test']) self.assertIn("ERROR: [ILLEGAL CHARACTERS (KB-H058)] The file 'foo.' ends with a dot." " Please, remove the dot from the end.", output) @@ -1051,7 +1055,7 @@ def test_class_name_disallowed(self): class LibnameConan(ConanFile): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("WARN: [CLASS NAME (KB-H059)] Class name 'LibnameConan' is not allowed. For example, use 'NameConan' instead.", output) @@ -1061,14 +1065,14 @@ def test_class_name_disallowed_dashed(self): class LibnameConan(ConanFile): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name-sdk/version@user/test']) self.assertIn("WARN: [CLASS NAME (KB-H059)] Class name 'LibnameConan' is not allowed. For example, use 'NameSdkConan' instead.", output) def test_no_crlf(self): conanfile = u"from conans import ConanFile\nclass AConan(ConanFile):\n pass\n" - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("[NO CRLF (KB-H060)] OK", output) @@ -1077,7 +1081,7 @@ def test_no_crlf(self): output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("ERROR: [NO CRLF (KB-H060)] The file 'conanfile.py' uses CRLF. Please, replace by LF.", output) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) tools.mkdir(os.path.join('test_package', 'build')) with io.open(os.path.join('test_package', 'build', 'conanfile.py'), 'w', newline='\r\n') as f_handle: f_handle.write(conanfile) @@ -1096,11 +1100,11 @@ def source(self): tools.cross_building(self) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("[TOOLS CROSS BUILDING (KB-H062)] OK", output) - tools.save('conanfile.py', content=conanfile.replace("tools.cross_building(self)", + save('conanfile.py', content=conanfile.replace("tools.cross_building(self)", "tools.cross_building(self.settings)")) output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("WARN: [TOOLS CROSS BUILDING (KB-H062)] The 'tools.cross_building(self.settings)' syntax in conanfile.py",output) @@ -1114,7 +1118,7 @@ class TestConan(ConanFile): def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/all@user/test']) self.assertIn("WARN: [NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1127,7 +1131,7 @@ def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("WARN: [NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1141,7 +1145,7 @@ class TestConan(ConanFile): def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("WARN: [NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1155,7 +1159,7 @@ class TestConan(ConanFile): def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertNotIn("[NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1169,7 +1173,7 @@ class TestConan(ConanFile): def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertNotIn("[NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1183,7 +1187,7 @@ class TestConan(ConanFile): def source(self): tools.get({}, strip_root=True) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/test']) self.assertNotIn("[NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output) @@ -1197,6 +1201,6 @@ def package_info(self): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', 'conanfile.py', 'name/version@user/test']) self.assertNotIn("Lib folder doesn't exist, can't collect libraries", output) diff --git a/tests/test_hooks/conan-center/test_conandata.py b/tests/test_hooks/conan-center/test_conandata.py index 9dcbff8a..b36c5992 100644 --- a/tests/test_hooks/conan-center/test_conandata.py +++ b/tests/test_hooks/conan-center/test_conandata.py @@ -6,6 +6,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save from conans import __version__ as conan_version @@ -28,14 +29,14 @@ def _get_environ(self, **kwargs): return kwargs def test_missing_conandata(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("[IMMUTABLE SOURCES (KB-H010)] Create a file 'conandata.yml' file with the " "sources to be downloaded.", output) def test_no_missing_conandata_but_not_used(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('conandata.yml', content="") + save('conanfile.py', content=self.conanfile) + save('conandata.yml', content="") output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("[IMMUTABLE SOURCES (KB-H010)] Use 'tools.get(**self.conan_data[\"sources\"]", output) @@ -55,8 +56,8 @@ def source(self): url: fakeurl md5: 12323423423 """) - tools.save('conanfile.py', content=conanfile) - tools.save('conandata.yml', content=conandata) + save('conanfile.py', content=conanfile) + save('conandata.yml', content=conandata) output = self.conan(['create', '.', 'name/version@user/channel'], expected_return_code=1) self.assertIn("[IMMUTABLE SOURCES (KB-H010)] OK", output) @@ -69,13 +70,13 @@ class AConan(ConanFile): def source(self): tools.download(self.conan_data["sources"]["all"]["url"]) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/channel'], expected_return_code=1) self.assertIn("[IMMUTABLE SOURCES (KB-H010)] OK", output) def _check_conandata(self, conandata): - tools.save('conanfile.py', content=self.conanfile) - tools.save('conandata.yml', content=conandata) + save('conanfile.py', content=self.conanfile) + save('conandata.yml', content=conandata) export_output = self.conan(['export', '.', 'name/1.69.0@jgsogo/test']) self.assertNotIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", export_output) self.assertIn("[CONANDATA.YML FORMAT (KB-H030)] OK", export_output) @@ -250,7 +251,7 @@ def test_different_sources_per_config_level2_mirror(self): self._check_conandata(conandata) def test_sha1_md5(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" sources: "1.69.0": @@ -259,13 +260,13 @@ def test_sha1_md5(self): sha1: "md5_1.69.0" md5: "sha1_1.69.0" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) export_output = self.conan(['export', '.', 'name/1.69.0@jgsogo/test']) self.assertNotIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", export_output) self.assertIn("[CONANDATA.YML FORMAT (KB-H030)] OK", export_output) def test_reduce_conandata(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" sources: "1.69.0": @@ -332,7 +333,7 @@ def test_reduce_conandata(self): ] } } - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) for version in ["1.69.0", "1.70.0", "1.71.0"]: export_output = self.conan(['export', '.', 'name/%s@jgsogo/test' % version]) self.assertNotIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", export_output) @@ -348,30 +349,30 @@ def test_reduce_conandata(self): self.assertEqual(expected_conandata_1710, conandata) def test_versions_as_string(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" sources: 1.73: url: "url1.69.0" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)] Versions in conandata.yml should be strings", output) def test_unknown_field(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" random_field: "random" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", output) self.assertIn("First level entries ['random_field'] not allowed. Use only first " "level entries ['sources', 'patches'] in conandata.yml", output) def test_unknown_subentry_sources(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" sources: "1.70.0": @@ -379,7 +380,7 @@ def test_unknown_subentry_sources(self): sha256: "sha1.69.0" other: "more_data" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", output) self.assertNotIn("First level entries", output) @@ -387,13 +388,13 @@ def test_unknown_subentry_sources(self): "conandata.yml", output) def test_unknown_subentry_patches(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" patches: "1.70.0": patches: "1.70.0.patch" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", output) self.assertNotIn("First level entries", output) @@ -401,7 +402,7 @@ def test_unknown_subentry_patches(self): "of conandata.yml", output) def test_unknown_subentry_in_list(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" patches: "1.70.0": @@ -412,7 +413,7 @@ def test_unknown_subentry_in_list(self): checksum: "sha_custom" base_path: "source_subfolder" """) - tools.save('conandata.yml', content=conandata) + save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", output) diff --git a/tests/test_hooks/conan-center/test_final_newline.py b/tests/test_hooks/conan-center/test_final_newline.py index fc170413..efac3e16 100644 --- a/tests/test_hooks/conan-center/test_final_newline.py +++ b/tests/test_hooks/conan-center/test_final_newline.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestGlobalFinalNewLine(ConanClientTestCase): @@ -52,51 +53,51 @@ def _get_environ(self, **kwargs): return kwargs def test_no_newline_pysoure(self): - tools.save('conanfile.py', content=self.conanfile.strip()) + save('conanfile.py', content=self.conanfile.strip()) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertIn("does not end with an endline", output) def test_no_newline_cmakelists(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save(os.path.join('CMakeLists.txt'), content=self.cmakelists.strip()) + save('conanfile.py', content=self.conanfile) + save(os.path.join('CMakeLists.txt'), content=self.cmakelists.strip()) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertIn("does not end with an endline", output) def test_no_newline_csource(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save(os.path.join('test_package', 'test_package.c'), content=self.csource.strip()) + save('conanfile.py', content=self.conanfile) + save(os.path.join('test_package', 'test_package.c'), content=self.csource.strip()) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertIn("does not end with an endline", output) def test_no_newline_yml(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save(os.path.join('conandata.yml'), content=self.conandata_yml.strip()) + save('conanfile.py', content=self.conanfile) + save(os.path.join('conandata.yml'), content=self.conandata_yml.strip()) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertIn("does not end with an endline", output) def test_no_newline_config_yml(self): - tools.save(os.path.join('all', 'conanfile.py'), content=self.conanfile) - tools.save(os.path.join('config.yml'), content=self.config_yml.strip()) + save(os.path.join('all', 'conanfile.py'), content=self.conanfile) + save(os.path.join('config.yml'), content=self.config_yml.strip()) output = self.conan(['export', 'all', 'name/version@user/channel']) self.assertIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertIn("does not end with an endline", output) def test_no_newline_in_build_file(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save(os.path.join('test_package', 'build', 'some_file.txt'), 'some data') + save('conanfile.py', content=self.conanfile) + save(os.path.join('test_package', 'build', 'some_file.txt'), 'some data') output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) self.assertNotIn("does not end with an endline", output) def test_ok_usage(self): - tools.save(os.path.join('config.yml'), content=self.config_yml) - tools.save(os.path.join('all', 'conanfile.py'), content=self.conanfile) - tools.save(os.path.join('all', 'CMakeLists.txt'), content=self.cmakelists) - tools.save(os.path.join('all', 'test_package', 'test_package.c'), content=self.csource) - tools.save(os.path.join('all', 'conandata.yml'), content=self.conandata_yml) + save(os.path.join('config.yml'), content=self.config_yml) + save(os.path.join('all', 'conanfile.py'), content=self.conanfile) + save(os.path.join('all', 'CMakeLists.txt'), content=self.cmakelists) + save(os.path.join('all', 'test_package', 'test_package.c'), content=self.csource) + save(os.path.join('all', 'conandata.yml'), content=self.conandata_yml) output = self.conan(['export', 'all', 'name/version@user/channel']) self.assertNotIn("ERROR: [NO FINAL ENDLINE (KB-H041)]", output) diff --git a/tests/test_hooks/conan-center/test_global_cppstd.py b/tests/test_hooks/conan-center/test_global_cppstd.py index 8c9cbe4a..982dac2e 100644 --- a/tests/test_hooks/conan-center/test_global_cppstd.py +++ b/tests/test_hooks/conan-center/test_global_cppstd.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestGlobalCPPSTD(ConanClientTestCase): @@ -21,19 +22,19 @@ def _get_environ(self, **kwargs): return kwargs def test_forbidden_usage(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [DEPRECATED GLOBAL CPPSTD (KB-H001)] The 'cppstd' setting is deprecated. " "Use the 'compiler.cppstd' subsetting instead", output) def test_forbidden_usage_multi_settings(self): - tools.save('conanfile.py', content=self.conanfile.replace('"cppstd"', '"cppstd", "os"')) + save('conanfile.py', content=self.conanfile.replace('"cppstd"', '"cppstd", "os"')) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [DEPRECATED GLOBAL CPPSTD (KB-H001)] The 'cppstd' setting is deprecated. " "Use the 'compiler.cppstd' subsetting instead", output) def test_ok_usage(self): - tools.save('conanfile.py', content=self.conanfile.replace("cppstd", "os")) + save('conanfile.py', content=self.conanfile.replace("cppstd", "os")) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [GLOBAL CPPSTD DEPRECATED] ", output) diff --git a/tests/test_hooks/conan-center/test_invalid_topics.py b/tests/test_hooks/conan-center/test_invalid_topics.py index 0649fa64..7fce6859 100644 --- a/tests/test_hooks/conan-center/test_invalid_topics.py +++ b/tests/test_hooks/conan-center/test_invalid_topics.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestInvalidTopics(ConanClientTestCase): @@ -21,23 +22,23 @@ def _get_environ(self, **kwargs): return kwargs def test_valid_topics(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[INVALID TOPICS (KB-H064)] OK", output) def test_no_topics(self): - tools.save('conanfile.py', content=self.conanfile.replace('topics = ("foobar",)', "")) + save('conanfile.py', content=self.conanfile.replace('topics = ("foobar",)', "")) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[INVALID TOPICS (KB-H064)] OK", output) def test_invalid_topics(self): - tools.save('conanfile.py', content=self.conanfile.replace('"foobar",', '"foobar", "conan"')) + save('conanfile.py', content=self.conanfile.replace('"foobar",', '"foobar", "conan"')) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("WARN: [INVALID TOPICS (KB-H064)] The topic 'conan' is invalid and should be" " removed from topics attribute.", output) def test_uppercase_topics(self): - tools.save('conanfile.py', content=self.conanfile.replace('"foobar",', '"foobar", "Baz", "QUX"')) + save('conanfile.py', content=self.conanfile.replace('"foobar",', '"foobar", "Baz", "QUX"')) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("WARN: [INVALID TOPICS (KB-H064)] The topic 'Baz' is invalid; even names " "and acronyms should be formatted entirely in lowercase.", output) diff --git a/tests/test_hooks/conan-center/test_library_install.py b/tests/test_hooks/conan-center/test_library_install.py index f75b00ea..95827a4e 100644 --- a/tests/test_hooks/conan-center/test_library_install.py +++ b/tests/test_hooks/conan-center/test_library_install.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestInstalledLibraries(ConanClientTestCase): @@ -29,33 +30,33 @@ def _get_environ(self, **kwargs): return kwargs def test_library_doesnot_exist(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) def test_empty_library_list(self): - tools.save('conanfile.py', content=self.conanfile.replace("open", "# open")) + save('conanfile.py', content=self.conanfile.replace("open", "# open")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) def test_not_installed_global_library(self): - tools.save('conanfile.py', content=self.conanfile.replace("[]", "['bar']")) + save('conanfile.py', content=self.conanfile.replace("[]", "['bar']")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component name::name library 'bar'", output) def test_empty_component_libs(self): - tools.save('conanfile.py', content=self.conanfile.replace("libs", "components['fake'].libs")) + save('conanfile.py', content=self.conanfile.replace("libs", "components['fake'].libs")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) def test_empty_component_without_libs(self): - tools.save('conanfile.py', content=self.conanfile.replace("libs", "components['fake'].libs") + save('conanfile.py', content=self.conanfile.replace("libs", "components['fake'].libs") .replace("open", "# open")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) def test_not_install_component_libs(self): - tools.save('conanfile.py', content=self.conanfile.replace("libs = []", + save('conanfile.py', content=self.conanfile.replace("libs = []", "components['fake'].libs = ['bar']")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component name::fake library 'bar'", output) @@ -68,11 +69,11 @@ class AConan(ConanFile): def package_id(self): self.info.header_only() """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) def test_full_library(self): - tools.save('conanfile.py', content=self.conanfile.replace("[]", "['libfoo.a']")) + save('conanfile.py', content=self.conanfile.replace("[]", "['libfoo.a']")) output = self.conan(['create', '.', 'name/version@user/test']) self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output) diff --git a/tests/test_hooks/conan-center/test_matching_configuration.py b/tests/test_hooks/conan-center/test_matching_configuration.py index e4889ddc..61c53398 100644 --- a/tests/test_hooks/conan-center/test_matching_configuration.py +++ b/tests/test_hooks/conan-center/test_matching_configuration.py @@ -6,6 +6,7 @@ from parameterized import parameterized from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class MatchingConfigurationTests(ConanClientTestCase): @@ -34,8 +35,8 @@ def test_matching_configuration(self, system_name, extension): cf = self.conanfile_match_conf.format(extension=extension, settings="settings = 'os', 'compiler', 'arch', " "'build_type'") - tools.save('conanfile.py', content=cf) - tools.save('file%s' % extension, content="") + save('conanfile.py', content=cf) + save('file%s' % extension, content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) if platform.system() == system_name: self.assertIn("[MATCHING CONFIGURATION (KB-H014)] OK", output) @@ -67,8 +68,8 @@ def test_mismatching_configuration(self): cf = self.conanfile_match_conf.format(extension=wrong_extension, settings="settings = 'os', 'compiler', 'arch', " "'build_type'") - tools.save('conanfile.py', content=cf) - tools.save('file%s' % wrong_extension, content="") + save('conanfile.py', content=cf) + save('file%s' % wrong_extension, content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertNotIn("[MATCHING CONFIGURATION (KB-H014)] OK", output) @@ -84,9 +85,9 @@ def test_matching_configuration_header_only_package_id(self): def package_id(self): self.info.header_only() """ - tools.save('conanfile_other.py', content=cf) - tools.save('file.h', content="") - tools.save('LICENSE', content="") + save('conanfile_other.py', content=cf) + save('file.h', content="") + save('LICENSE', content="") output = self.conan(['create', 'conanfile_other.py', 'name/version@danimtb/test']) self.assertIn("[MATCHING CONFIGURATION (KB-H014)] OK", output) self.assertNotIn("ERROR: [MATCHING CONFIGURATION (KB-H014)]", output) @@ -94,9 +95,9 @@ def package_id(self): def test_matching_configuration_header_only(self): cf = self.conanfile_match_conf.format(extension=".h", settings="") - tools.save('conanfile.py', content=cf) - tools.save('file.h', content="") - tools.save('LICENSE', content="") + save('conanfile.py', content=cf) + save('file.h', content="") + save('LICENSE', content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[MATCHING CONFIGURATION (KB-H014)] OK", output) self.assertNotIn("ERROR: [MATCHING CONFIGURATION (KB-H014)]", output) @@ -105,7 +106,7 @@ def test_matching_configuration_empty(self): cf = self.conanfile_match_conf.format(extension="", settings="settings = 'os', 'compiler', 'arch', " "'build_type'") - tools.save('conanfile.py', content=cf) + save('conanfile.py', content=cf) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertNotIn("[MATCHING CONFIGURATION (KB-H014)] OK", output) self.assertIn("ERROR: [MATCHING CONFIGURATION (KB-H014)] Empty package", output) @@ -114,8 +115,8 @@ def test_matching_configuration_empty(self): def test_matching_configuration_tool(self, system_name, extension): cf = self.conanfile_match_conf.format(extension=extension, settings="settings = 'os'") - tools.save('conanfile.py', content=cf) - tools.save('file%s' % extension, content="") + save('conanfile.py', content=cf) + save('file%s' % extension, content="") output = self.conan(['create', '.', 'name/version@jgsogo/test']) system = platform.system() if system in ["Darwin", "Linux"]: diff --git a/tests/test_hooks/conan-center/test_no_libtool.py b/tests/test_hooks/conan-center/test_no_libtool.py index b24b1bb1..17bd5674 100644 --- a/tests/test_hooks/conan-center/test_no_libtool.py +++ b/tests/test_hooks/conan-center/test_no_libtool.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class NoLibToolTests(ConanClientTestCase): @@ -28,7 +29,7 @@ def _get_environ(self, **kwargs): return kwargs def test_libtool_not_allowed(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("ERROR: [LIBTOOL FILES PRESENCE (KB-H018)]", output) self.assertIn("bad.la", output) diff --git a/tests/test_hooks/conan-center/test_no_pdbs.py b/tests/test_hooks/conan-center/test_no_pdbs.py index 0be71453..80138588 100644 --- a/tests/test_hooks/conan-center/test_no_pdbs.py +++ b/tests/test_hooks/conan-center/test_no_pdbs.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class NoPDBsTests(ConanClientTestCase): @@ -27,12 +28,12 @@ def _get_environ(self, **kwargs): return kwargs def test_pdb_not_allowed(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("ERROR: [PDB FILES NOT ALLOWED (KB-H017)]", output) def test_no_pdb_is_ok(self): - tools.save('conanfile.py', content=self.conanfile.replace("bad.pdb", "bad.txt")) + save('conanfile.py', content=self.conanfile.replace("bad.pdb", "bad.txt")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [PDB FILES NOT ALLOWED (KB-H017)]", output) self.assertIn("[PDB FILES NOT ALLOWED (KB-H017)] OK", output) diff --git a/tests/test_hooks/conan-center/test_no_target_name.py b/tests/test_hooks/conan-center/test_no_target_name.py index bd778fe3..1920bbb7 100644 --- a/tests/test_hooks/conan-center/test_no_target_name.py +++ b/tests/test_hooks/conan-center/test_no_target_name.py @@ -5,6 +5,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestNoTargetName(ConanClientTestCase): @@ -23,44 +24,44 @@ def _get_environ(self, **kwargs): return kwargs def test_with_name(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.name = "Foo"')) + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.name = "Foo"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [NO TARGET NAME (KB-H040)] CCI uses the name of the package for cmake generator and " "filename by default. Replace 'cpp_info.name' by 'cpp_info.names[]'.", output) def test_with_filename(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.filename = "Foobar"')) + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.filename = "Foobar"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [NO TARGET NAME (KB-H040)] CCI uses the name of the package for cmake generator and " "filename by default. Replace 'cpp_info.filename' by 'cpp_info.filenames[]'.", output) def test_with_cmake_generator(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake"] = "Foo"')) + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake"] = "Foo"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [NO TARGET NAME (KB-H040)] CCI uses the name of the package for cmake generator. " "Conanfile should not contain 'self.cpp_info.names['cmake']'. " "Use 'cmake_find_package' and 'cmake_find_package_multi' instead.", output) def test_with_cmake_multi_generator(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake_multi"] = "Foo"')) + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake_multi"] = "Foo"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("ERROR: [NO TARGET NAME (KB-H040)] CCI uses the name of the package for cmake_multi generator. " "Conanfile should not contain 'self.cpp_info.names['cmake_multi']'. " "Use 'cmake_find_package' and 'cmake_find_package_multi' instead.", output) def test_with_pkg_config(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["pkg_config"] = "foolib"')) + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["pkg_config"] = "foolib"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[NO TARGET NAME (KB-H040)] OK", output) def test_with_cmake_find_package(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake_find_package"] = ' + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names["cmake_find_package"] = ' '"foolib"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[NO TARGET NAME (KB-H040)] OK", output) def test_with_cmake_find_package_multi(self): - tools.save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names' + save('conanfile.py', content=self.conanfile.replace("{}", 'self.cpp_info.names' '["cmake_find_package_multi"] = "foolib"')) output = self.conan(['export', '.', 'name/version@user/test']) self.assertIn("[NO TARGET NAME (KB-H040)] OK", output) diff --git a/tests/test_hooks/conan-center/test_recipe_folder_size.py b/tests/test_hooks/conan-center/test_recipe_folder_size.py index 48a3e1cb..ed9ee2d2 100644 --- a/tests/test_hooks/conan-center/test_recipe_folder_size.py +++ b/tests/test_hooks/conan-center/test_recipe_folder_size.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class RecipeFolderSizeTests(ConanClientTestCase): @@ -24,23 +25,23 @@ def _get_environ(self, **kwargs): def test_regular_folder_size(self): content = "".join(["k" for it in range(1024 * 255)]) - tools.save('conanfile.py', content=self.conanfile) - tools.save('big_file', content=content) + save('conanfile.py', content=self.conanfile) + save('big_file', content=content) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[RECIPE FOLDER SIZE (KB-H009)] OK", output) self.assertNotIn("ERROR: [RECIPE FOLDER SIZE (KB-H009)]", output) def test_larger_folder_size(self): content = "".join(["k" for _ in range(1024 * 257)]) - tools.save('conanfile.py', content=self.conanfile) - tools.save('big_file', content=content) + save('conanfile.py', content=self.conanfile) + save('big_file', content=content) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [RECIPE FOLDER SIZE (KB-H009)] The size of your recipe folder", output) def test_custom_folder_size(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) content = " ".join(["test_recipe_folder_larger_size" for _ in range(500)]) - tools.save('big_file', content=content) + save('big_file', content=content) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[RECIPE FOLDER SIZE (KB-H009)] OK", output) with tools.environment_append({"CONAN_MAX_RECIPE_FOLDER_SIZE_KB": "0"}): @@ -48,8 +49,8 @@ def test_custom_folder_size(self): self.assertIn("ERROR: [RECIPE FOLDER SIZE (KB-H009)] The size of your recipe folder", output) def test_builds_in_test_package_discarded(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) content = " ".join(["1" for _ in range(1024 * 257)]) - tools.save('test_package/build/232323/big_file', content=content) + save('test_package/build/232323/big_file', content=content) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[RECIPE FOLDER SIZE (KB-H009)] OK", output) diff --git a/tests/test_hooks/conan-center/test_short_paths.py b/tests/test_hooks/conan-center/test_short_paths.py index 1f22f406..d6b795f6 100644 --- a/tests/test_hooks/conan-center/test_short_paths.py +++ b/tests/test_hooks/conan-center/test_short_paths.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class ShortPathsTests(ConanClientTestCase): @@ -43,26 +44,26 @@ def _get_environ(self, **kwargs): return kwargs def test_not_needed_short_path(self): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [SHORT_PATHS USAGE (KB-H066)]", output) self.assertIn("[SHORT_PATHS USAGE (KB-H066)] OK", output) def test_include_folder(self): - tools.save('conanfile.py', content=self.conanfile_long) + save('conanfile.py', content=self.conanfile_long) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn("WARN: [SHORT_PATHS USAGE (KB-H066)] The file './include/another-include-folder/another-subfolder/a-very-very-very-long-header-file-which-may-trigger-hook-66.h'" " has a very long path and may exceed Windows max path length. Add 'short_paths = True' in your " "recipe.", output) def test_include_folder_short_paths(self): - tools.save('conanfile.py', content=self.conanfile_long.replace("# s", "s")) + save('conanfile.py', content=self.conanfile_long.replace("# s", "s")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [SHORT_PATHS USAGE (KB-H066)]", output) self.assertIn("[SHORT_PATHS USAGE (KB-H066)] OK", output) def test_source_folder_long_path(self): - tools.save('conanfile.py', content=self.conanfile_source) + save('conanfile.py', content=self.conanfile_source) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn( "WARN: [SHORT_PATHS USAGE (KB-H066)] The file './include/another-include-folder/another-subfolder/very-very-very-long-folder-subfolder/" @@ -71,7 +72,7 @@ def test_source_folder_long_path(self): "recipe.", output) def test_source_folder_short_path(self): - tools.save('conanfile.py', content=self.conanfile_source.replace("# s", "s")) + save('conanfile.py', content=self.conanfile_source.replace("# s", "s")) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("WARN: [SHORT_PATHS USAGE (KB-H066)]", output) self.assertIn("[SHORT_PATHS USAGE (KB-H066)] OK", output) diff --git a/tests/test_hooks/conan-center/test_test_type.py b/tests/test_hooks/conan-center/test_test_type.py index f2162687..1c286941 100644 --- a/tests/test_hooks/conan-center/test_test_type.py +++ b/tests/test_hooks/conan-center/test_test_type.py @@ -4,6 +4,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class TestTestType(ConanClientTestCase): @@ -28,25 +29,25 @@ def _get_environ(self, **kwargs): return kwargs def test_type_explicit(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "explicit")) + save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "explicit")) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[TEST_TYPE MANAGEMENT (KB-H068)] OK", output) def test_type_requires(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "requires")) + save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "requires")) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [TEST_TYPE MANAGEMENT (KB-H068)] The attribute 'test_type' only should be used with 'explicit' value.", output) def test_type_build_requires(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "build_requires")) + save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=self.test_conanfile.replace("{}", "build_requires")) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("ERROR: [TEST_TYPE MANAGEMENT (KB-H068)] The attribute 'test_type' only should be used with 'explicit' value.", output) def test_no_test_type(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('test_package/conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) + save('test_package/conanfile.py', content=self.conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("[TEST_TYPE MANAGEMENT (KB-H068)] OK", output) diff --git a/tests/test_hooks/test_attribute_checker.py b/tests/test_hooks/test_attribute_checker.py index 5d970b9a..7dea9843 100644 --- a/tests/test_hooks/test_attribute_checker.py +++ b/tests/test_hooks/test_attribute_checker.py @@ -7,10 +7,16 @@ from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save +from tests.utils.compat import v2 + class AttributeCheckerTests(ConanClientTestCase): conanfile_base = textwrap.dedent("""\ - from conans import ConanFile + try: + from conans import ConanFile + except ImportError: + from conan import ConanFile class AConan(ConanFile): {placeholder} @@ -24,15 +30,15 @@ def _get_environ(self, **kwargs): return kwargs def test_conanfile_basic(self): - tools.save('conanfile.py', content=self.conanfile_basic) - output = self.conan(['export', '.', 'name/version@jgsogo/test']) + save('conanfile.py', content=self.conanfile_basic) + output = self.conan_export('.', 'name', 'version', 'jgsogo', 'test') self.assertIn("pre_export(): WARN: Conanfile doesn't have 'url'", output) self.assertIn("pre_export(): WARN: Conanfile doesn't have 'license'", output) self.assertIn("pre_export(): WARN: Conanfile doesn't have 'description'", output) def test_conanfile_alias(self): - tools.save('conanfile.py', content=self.conanfile_alias) - output = self.conan(['export', '.', 'name/version@jgsogo/test']) + save('conanfile.py', content=self.conanfile_alias) + output = self.conan_export('.', 'name', 'version', 'jgsogo', 'test') self.assertNotIn("pre_export(): WARN: Conanfile doesn't have 'url'", output) self.assertNotIn("pre_export(): WARN: Conanfile doesn't have 'license'", output) self.assertNotIn("pre_export(): WARN: Conanfile doesn't have 'description'", output) diff --git a/tests/test_hooks/test_export_metadata.py b/tests/test_hooks/test_export_metadata.py index 80b5794a..a1bdf102 100644 --- a/tests/test_hooks/test_export_metadata.py +++ b/tests/test_hooks/test_export_metadata.py @@ -15,6 +15,7 @@ from conans.paths import CONAN_MANIFEST from tests.utils import capabilities from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save here = os.path.dirname(__file__) @@ -48,13 +49,13 @@ def _get_environ(self, **kwargs): return kwargs def test_no_repo(self): - tools.save('conanfile.py', content=self.conanfile_plain) + save('conanfile.py', content=self.conanfile_plain) output = self.conan(['export', '.', 'name/version@jgsogo/test']) self.assertIn("pre_export(): WARN: Cannot identify a repository system in directory", output) def test_conflicting_file(self): - tools.save('conanfile.py', content=self.conanfile_plain) - tools.save(METADATA_FILENAME, content='whatever') + save('conanfile.py', content=self.conanfile_plain) + save(METADATA_FILENAME, content='whatever') output = self.conan(['export', '.', 'name/version@jgsogo/test']) self.assertIn("ERROR: Target file to write metadata already exists", output) self.assertIn("Use environment variable '{}' to set a different " @@ -74,7 +75,7 @@ def test_git_repository(self, exports): git.run("init .") git.run('config user.email "you@example.com"') git.run('config user.name "Your Name"') - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) git.run('add --all') git.run('commit -am "initial"') git.run('remote add origin {}'.format(url)) @@ -110,7 +111,7 @@ def test_svn_repository(self, pristine_repo): # Create the working repo svn = tools.SVN() svn.checkout(url=repo_url) - tools.save('conanfile.py', content=self.conanfile_plain) + save('conanfile.py', content=self.conanfile_plain) svn.run("add conanfile.py") svn.run('commit -m "initial"') if pristine_repo: diff --git a/tests/test_hooks/test_github_updater.py b/tests/test_hooks/test_github_updater.py index e2e3dee6..6b980370 100644 --- a/tests/test_hooks/test_github_updater.py +++ b/tests/test_hooks/test_github_updater.py @@ -7,6 +7,7 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save _GITHUB_REPO_DATA = { @@ -56,7 +57,7 @@ def _get_environ(self, **kwargs): return kwargs def test_unset_github_token(self): - tools.save('conanfile.py', content=self.conanfile_base) + save('conanfile.py', content=self.conanfile_base) output = self.conan(['export', '.', 'name/0.1.0@foobar/testing']) self.assertIn("pre_export(): ERROR: No GITHUB_TOKEN environment variable is set, skipping GitHub updater", output) @@ -93,7 +94,7 @@ def test_complete_attributes(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', json=_GITHUB_TOPICS_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') responses.add(responses.PUT, 'https://api.github.com/repos/foobar/conan-dummy/topics') - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn('pre_export(): The attributes have been updated with success.', output) @@ -106,7 +107,7 @@ def test_updated_project(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', json=_GITHUB_TOPICS_DATA_UPDATED) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') responses.add(responses.PUT, 'https://api.github.com/repos/foobar/conan-dummy/topics') - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): The attributes are up-to-date.', output) self.assertIn('pre_export(): The topics are up-to-date.', output) @@ -114,26 +115,26 @@ def test_updated_project(self): @responses.activate def test_unauthorized(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json={"message": "401 Unauthorized"}, status=401) - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): ERROR: GitHub GET request failed (401): {"message": "401 Unauthorized"}', output) @responses.activate def test_no_url_attribute(self): - tools.save('conanfile.py', content=self.conanfile_basic) + save('conanfile.py', content=self.conanfile_basic) output = self.conan(['export', '.', 'name/0.1.0@foobar/testing']) self.assertIn("ERROR: No url attribute was specified withing recipe, skipping GitHub updater.", output) @responses.activate def test_no_homepage_attribute(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA) - tools.save('conanfile.py', content=self.conanfile_url) + save('conanfile.py', content=self.conanfile_url) output = self.conan(['export', '.', 'name/0.1.0@foobar/testing']) self.assertIn('ERROR: The attributes description and homepage are not configured in the recipe.', output) @responses.activate def test_invalid_url(self): - tools.save('conanfile.py', content=self.conanfile_invalid_url) + save('conanfile.py', content=self.conanfile_invalid_url) output = self.conan(['export', '.', 'name/0.1.0@foobar/testing']) self.assertIn('ERROR: Not a GitHub repository: "https://gitlab.com/foobar/conan-dummy", skipping GitHub updater.', output) @@ -141,7 +142,7 @@ def test_invalid_url(self): def test_failed_attribute_update(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy', status=500, json={"message": "Internal Server Error"}) - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn('pre_export(): ERROR: GitHub PATCH request failed with (500): {"message": "Internal Server Error"}.', output) @@ -150,7 +151,7 @@ def test_failed_attribute_update(self): def test_no_topics(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') - tools.save('conanfile.py', content=self.conanfile_no_topics) + save('conanfile.py', content=self.conanfile_no_topics) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn('pre_export(): The attributes have been updated with success.', output) @@ -161,7 +162,7 @@ def test_failed_topics_get(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', status=500, json={"message": "Internal Server Error"}) - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn('pre_export(): The attributes have been updated with success.', output) @@ -173,7 +174,7 @@ def test_failed_topics_put(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', json=_GITHUB_TOPICS_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') responses.add(responses.PUT, 'https://api.github.com/repos/foobar/conan-dummy/topics', status=500, json={"message": "Internal Server Error"}) - tools.save('conanfile.py', content=self.conanfile_complete) + save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn('pre_export(): The attributes have been updated with success.', output) diff --git a/tests/test_hooks/test_members_typo_checker.py b/tests/test_hooks/test_members_typo_checker.py index 18e39c87..c826f242 100644 --- a/tests/test_hooks/test_members_typo_checker.py +++ b/tests/test_hooks/test_members_typo_checker.py @@ -6,11 +6,15 @@ from conans import tools from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class MembersTypoCheckerTests(ConanClientTestCase): conanfile_basic = textwrap.dedent("""\ - from conans import ConanFile + try: + from conans import ConanFile + except ImportError: + from conan import ConanFile class AConan(ConanFile): name = "name" @@ -19,7 +23,10 @@ def package_info(self): self.cpp_info.defines = ["ACONAN"] """) conanfile_with_typos = textwrap.dedent("""\ - from conans import ConanFile + try: + from conans import ConanFile + except ImportError: + from conan import ConanFile class AConan(ConanFile): name = "name" @@ -43,13 +50,13 @@ def _get_environ(self, **kwargs): return kwargs def test_conanfile_basic(self): - tools.save('conanfile.py', content=self.conanfile_basic) - output = self.conan(['export', '.', 'name/version@jgsogo/test']) + save('conanfile.py', content=self.conanfile_basic) + output = self.conan_export('.', 'name', 'version', 'jgsogo', 'test') self.assertNotIn("member looks like a typo", output) def test_conanfile_with_typos(self): - tools.save('conanfile.py', content=self.conanfile_with_typos) - output = self.conan(['export', '.', 'name/version@jgsogo/test']) + save('conanfile.py', content=self.conanfile_with_typos) + output = self.conan_export('.', 'name', 'version', 'jgsogo', 'test') self.assertIn( "pre_export(): WARN: The 'exports_sourcess' member looks like a typo. Similar to:", output) self.assertIn( diff --git a/tests/test_hooks/test_non_ascii.py b/tests/test_hooks/test_non_ascii.py index 3e9edd41..a223768f 100644 --- a/tests/test_hooks/test_non_ascii.py +++ b/tests/test_hooks/test_non_ascii.py @@ -1,14 +1,16 @@ import os import textwrap -from conans import tools - from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class NonASCIITests(ConanClientTestCase): conanfile = textwrap.dedent("""\ - from conans import ConanFile + try: + from conans import ConanFile + except ImportError: + from conan import ConanFile class AConan(ConanFile): author = "Юрий Алексеевич Гагарин" @@ -22,14 +24,14 @@ def _get_environ(self, **kwargs): return kwargs def test_with_non_ascii(self): - tools.save('conanfile.py', content=self.conanfile) - output = self.conan(['export', '.', 'name/version@user/channel']) + save('conanfile.py', content=self.conanfile) + output = self.conan_export('.', 'name', 'version', 'user', 'channel') self.assertIn("ERROR: The file \'conanfile.py\' contains a non-ascii character at line (5)." " Only ASCII characters are allowed, please remove it.", output) def test_with_no_non_ascii(self): - tools.save('conanfile.py', content=self.conanfile + save('conanfile.py', content=self.conanfile .replace("Юрий Алексеевич Гагарин", "Yuri Alekseyevich Gagarin") .replace("A Terra é Azul", "The Earth is Blue")) - output = self.conan(['export', '.', 'name/version@user/channel']) + output = self.conan_export('.', 'name', 'version', 'user', 'channel') self.assertNotIn("ERROR:", output) diff --git a/tests/test_hooks/test_recipe_linter.py b/tests/test_hooks/test_recipe_linter.py index 270fb228..3d41095c 100644 --- a/tests/test_hooks/test_recipe_linter.py +++ b/tests/test_hooks/test_recipe_linter.py @@ -10,9 +10,18 @@ from conans import __version__ as conan_version from conans import tools -from conans.client.command import ERROR_GENERAL, SUCCESS -from conans.tools import environment_append +try: + from conans.client.command import ERROR_GENERAL, SUCCESS +except ImportError: + from conans.cli.exit_codes import ERROR_GENERAL, SUCCESS + +try: + from conans.tools import environment_append +except ImportError: + from conans.util.env import environment_update as environment_append + from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save class RecipeLinterTests(ConanClientTestCase): @@ -38,11 +47,11 @@ def _get_environ(self, **kwargs): @parameterized.expand([(False, ), (True, )]) def test_basic(self, pylint_werr): - tools.save('conanfile.py', content=self.conanfile) + save('conanfile.py', content=self.conanfile) pylint_werr_value = "1" if pylint_werr else None with environment_append({"CONAN_PYLINT_WERR": pylint_werr_value}): return_code = ERROR_GENERAL if pylint_werr else SUCCESS - output = self.conan(['export', '.', 'name/version@'], expected_return_code=return_code) + output = self.conan_export('.', 'name', 'version', expected_return_code=return_code) if pylint_werr: self.assertIn("pre_export(): Package recipe has linter errors." @@ -71,15 +80,15 @@ class Recipe(ConanFile): def build(self): pass """) - tools.save(os.path.join("path spaces", "conanfile.py"), content=conanfile) + save(os.path.join("path spaces", "conanfile.py"), content=conanfile) output = self.conan(['export', 'path spaces/conanfile.py', 'name/version@']) recipe_path = os.path.join(os.getcwd(), "path spaces", "conanfile.py") self.assertIn("pre_export(): Lint recipe '{}'".format(recipe_path), output) self.assertIn("pre_export(): Linter detected '0' errors", output) def test_custom_rcfile(self): - tools.save('conanfile.py', content=self.conanfile) - tools.save('pylintrc', content="[FORMAT]\nindent-string=' '") + save('conanfile.py', content=self.conanfile) + save('pylintrc', content="[FORMAT]\nindent-string=' '") with environment_append({"CONAN_PYLINTRC": os.path.join(os.getcwd(), "pylintrc")}): output = self.conan(['export', '.', 'name/version@']) @@ -94,7 +103,7 @@ class Recipe(ConanFile): def build(self): self.output.info(self.conan_data) """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): # With the default 'python_plugin' it doesn't raise with environment_append({"CONAN_PYLINT_RECIPE_PLUGINS": None}): @@ -103,7 +112,7 @@ def build(self): self.assertIn("pre_export(): Linter detected '0' errors", output) # With a custom one, it should fail - tools.save("plugin_empty.py", content="def register(_):\n\tpass") + save("plugin_empty.py", content="def register(_):\n\tpass") with environment_append({"CONAN_PYLINT_RECIPE_PLUGINS": "plugin_empty"}): output = self.conan(['export', '.', 'consumer/other@'], expected_return_code=ERROR_GENERAL) self.assertIn("pre_export(): Package recipe has linter errors." @@ -141,7 +150,7 @@ def requirements(self): def deploy(self): self.copy_deps("*.dll") """) - tools.save('consumer.py', content=conanfile) + save('consumer.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): output = self.conan(['export', 'consumer.py', 'consumer/version@']) self.assertIn("pre_export(): Lint recipe", output) # Hook run without errors @@ -164,7 +173,7 @@ def source(self): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): output = self.conan(['export', '.', 'consumer/version@']) self.assertIn("pre_export(): Lint recipe", output) # Hook run without errors @@ -180,7 +189,7 @@ class ExampleConan(ConanFile): def build(self): _ = self.conan_data["sources"][float(self.version)] """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): output = self.conan(['export', '.', 'consumer/version@']) self.assertIn("pre_export(): Lint recipe", output) # Hook run without errors @@ -199,10 +208,10 @@ class TestConan(ConanFile): name = "consumer" version = "version" """) - tools.save('require.py', self.conanfile) + save('require.py', self.conanfile) self.conan(['export', 'require.py', 'name/version@']) - tools.save('consumer.py', content=conanfile) + save('consumer.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): output = self.conan(['export', 'consumer.py', 'consumer/version@']) self.assertIn("pre_export(): Lint recipe", output) # Hook run without errors diff --git a/tests/test_hooks/test_spdx_checker.py b/tests/test_hooks/test_spdx_checker.py index 764dca17..a2c61539 100644 --- a/tests/test_hooks/test_spdx_checker.py +++ b/tests/test_hooks/test_spdx_checker.py @@ -5,6 +5,8 @@ from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save + class SPDXCheckerTest(ConanClientTestCase): def _get_environ(self, **kwargs): @@ -19,7 +21,7 @@ def test_valid_license_name(self): class AConan(ConanFile): license = "BSL-1.0" """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("recipe doesn't have a license attribute", output) @@ -31,7 +33,7 @@ def test_valid_license_list_names(self): class AConan(ConanFile): license = "Zlib", "MIT", "BSD-3-Clause" """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("recipe doesn't have a license attribute", output) @@ -45,7 +47,7 @@ def test_no_license_attribute(self): class AConan(ConanFile): pass """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertIn("recipe doesn't have a license attribute", output) @@ -55,7 +57,7 @@ def test_invalid_license_name(self): class AConan(ConanFile): license = "Apache-2.0", "Invalid-License" """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("recipe doesn't have a license attribute", output) @@ -68,7 +70,7 @@ def test_case_sensitive(self): class AConan(ConanFile): license = "zlib" """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("recipe doesn't have a license attribute", output) @@ -80,7 +82,7 @@ def test_wrong_attribute_type(self): class AConan(ConanFile): license = {"name": "Zlib"} """) - tools.save('conanfile.py', content=conanfile) + save('conanfile.py', content=conanfile) output = self.conan(['export', '.', 'name/version@user/channel']) self.assertNotIn("recipe doesn't have a license attribute", output) diff --git a/tests/test_hooks/test_yaml_linter.py b/tests/test_hooks/test_yaml_linter.py index 33892dad..38a983e0 100644 --- a/tests/test_hooks/test_yaml_linter.py +++ b/tests/test_hooks/test_yaml_linter.py @@ -7,10 +7,20 @@ from parameterized import parameterized from conans import tools -from conans.client.command import ERROR_GENERAL, SUCCESS -from conans.tools import environment_append +try: + from conans.client.command import ERROR_GENERAL, SUCCESS +except ImportError: + from conans.cli.exit_codes import ERROR_GENERAL, SUCCESS + +try: + from conans.tools import environment_append +except ImportError: + from conans.util.env import environment_update as environment_append + from tests.utils.test_cases.conan_client import ConanClientTestCase +from tests.utils.compat import save + class YAMLLinterTests(ConanClientTestCase): conanfile = textwrap.dedent(r""" @@ -40,8 +50,8 @@ def test_basic(self, yamllint_werr): base_path: "source" patches: """) - tools.save('conanfile.py', content=self.conanfile) - tools.save('conandata.yml', content=conandatafile) + save('conanfile.py', content=self.conanfile) + save('conandata.yml', content=conandatafile) yamllint_werr_value = "1" if yamllint_werr else None with environment_append({"CONAN_YAMLLINT_WERR": yamllint_werr_value}): return_code = ERROR_GENERAL if yamllint_werr else SUCCESS @@ -66,8 +76,8 @@ def test_path_with_spaces(self): - patch_file: "patches/abcdef.diff" base_path: "source" """) - tools.save(os.path.join("path spaces", "conanfile.py"), content=self.conanfile) - tools.save(os.path.join("path spaces", "conandata.py"), content=conandatafile) + save(os.path.join("path spaces", "conanfile.py"), content=self.conanfile) + save(os.path.join("path spaces", "conandata.py"), content=conandatafile) output = self.conan(['export', 'path spaces/conanfile.py', 'name/version@']) recipe_path = os.path.join(os.getcwd(), "path spaces", "conanfile.py") self.assertIn("pre_export(): Lint yaml '{}'".format(recipe_path), output) diff --git a/tests/utils/compat.py b/tests/utils/compat.py new file mode 100644 index 00000000..d2e1b785 --- /dev/null +++ b/tests/utils/compat.py @@ -0,0 +1,15 @@ +from conans import tools +try: + from conans import Settings + v2 = False +except ImportError: + from conans.model.settings import Settings + v2 = True + + +def save(filename, content): + if hasattr(tools, "save"): + tools.save(filename, content) + else: + with open(filename, "w") as f: + f.write(content) diff --git a/tests/utils/conan_command.py b/tests/utils/conan_command.py index 96d097a8..26a31f24 100644 --- a/tests/utils/conan_command.py +++ b/tests/utils/conan_command.py @@ -4,12 +4,24 @@ import sys from conans import __version__ as conan_version -from conans.client.command import Conan, CommandOutputer, Command +try: + from conans.client.command import Conan, CommandOutputer, Command +except ImportError: + from conans.cli.api.conan_api import ConanAPIV2 + from conans.cli.cli import Cli + v2 = True + from conans.model.version import Version @contextmanager def conan_command(output_stream): + if v2: + conan_api = ConanAPIV2() + cli = Cli(conan_api) + yield cli + return + # This snippet reproduces code from conans.client.command.main, we cannot directly # use it because in case of error it is exiting the python interpreter :/ old_stdout, old_stderr = sys.stdout, sys.stderr diff --git a/tests/utils/test_cases/conan_client.py b/tests/utils/test_cases/conan_client.py index d7d7086d..34037ad9 100644 --- a/tests/utils/test_cases/conan_client.py +++ b/tests/utils/test_cases/conan_client.py @@ -11,9 +11,13 @@ except ImportError: from io import StringIO -from conans.client.command import SUCCESS +try: + from conans.client.command import SUCCESS +except ImportError: + from conans.cli.exit_codes import SUCCESS from tests.utils.conan_command import conan_command from tests.utils.environ_vars import context_env +from tests.utils.compat import v2 class ConanClientTestCase(unittest.TestCase): @@ -28,6 +32,22 @@ def _get_environ(self, **kwargs): kwargs.update({'CONAN_USER_HOME': home, 'CONAN_USER_HOME_SHORT': home_short}) return kwargs + def conan_export(self, cwd, name, version, user=None, channel=None, expected_return_code=SUCCESS): + if v2: + args = ['export', '--name', name, '--version', version] + if user: + args.extend(['--user', user]) + if channel: + args.extend(['--channel', channel]) + args.append(cwd) + else: + if user and channel: + ref = "%s/%s@%s/%s" % (name, version, user, channel) + else: + ref = "%s/%s@" % (name, version) + args = ['export', cwd, ref] + return self.conan(args, expected_return_code=expected_return_code) + def conan(self, command, expected_return_code=SUCCESS): with context_env(**self._get_environ()): stream = StringIO() diff --git a/tox.ini b/tox.ini index b4387820..d3b3cc96 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,12 @@ [tox] skipsdist=True envlist = - py{36,37,38}-conan{dev,current,prev,prevprev} + py{36,37,38}-conan{dev,dev2,current,prev,prevprev} [testenv] deps = conandev: https://github.com/conan-io/conan/archive/develop.tar.gz + conandev2: https://github.com/conan-io/conan/archive/develop2.tar.gz conancurrent: conan conanprev: conan-unknown conanprevprev: conan-unknown