Skip to content

Commit f972abd

Browse files
authored
Test/improvements (#19291)
* test improvements * cstd coverage * coverage * wip * fix * fix test
1 parent d889806 commit f972abd

36 files changed

+933
-1090
lines changed

conan/api/conan_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,3 @@ def settings_yml(self):
150150
@property
151151
def requester(self):
152152
return self._requester
153-

conan/api/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def request_boolean(self, msg, default_option=None):
7878
"""Request user to input a boolean"""
7979
ret = None
8080
while ret is None:
81-
if default_option is True:
81+
if default_option:
8282
s = self.request_string("%s (YES/no)" % msg)
8383
elif default_option is False:
8484
s = self.request_string("%s (NO/yes)" % msg)

conan/api/subapi/audit.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def get_provider(self, provider_name):
6868
)
6969

7070
raise ConanException(
71-
f"Provider '{provider_name}' not found. Please specify a valid provider name or add it using: "
72-
f"'conan audit provider add {provider_name} {add_arguments} --token=<token>'\n"
73-
f"{register_message}"
71+
f"Provider '{provider_name}' not found. Please specify a valid provider name or add "
72+
f"it using: 'conan audit provider add {provider_name} {add_arguments} "
73+
f"--token=<token>'\n{register_message}"
7474
)
7575

7676
provider_data = providers[provider_name]
@@ -82,9 +82,11 @@ def get_provider(self, provider_name):
8282
provider_data["token"] = env_token
8383
elif "token" in provider_data:
8484
try:
85-
provider_data["token"] = decode(base64.standard_b64decode(provider_data["token"]).decode(), CYPHER_KEY)
86-
except binascii.Error as e:
87-
raise ConanException(f"Invalid token format for provider '{provider_name}'. The token might be corrupt.")
85+
enc_token = base64.standard_b64decode(provider_data["token"]).decode()
86+
provider_data["token"] = decode(enc_token, CYPHER_KEY)
87+
except binascii.Error:
88+
raise ConanException(f"Invalid token format for provider '{provider_name}'. "
89+
f"The token might be corrupt.")
8890

8991
provider_cls = self._provider_cls.get(provider_data["type"])
9092

@@ -142,7 +144,8 @@ def auth_provider(self, provider, token):
142144
providers = _load_providers(self._providers_path)
143145

144146
assert provider.name in providers
145-
providers[provider.name]["token"] = base64.standard_b64encode(encode(token, CYPHER_KEY).encode()).decode()
147+
encode_token = encode(token, CYPHER_KEY).encode()
148+
providers[provider.name]["token"] = base64.standard_b64encode(encode_token).decode()
146149
setattr(provider, "token", token)
147150
_save_providers(self._providers_path, providers)
148151

conan/api/subapi/cache.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from conan.api.output import ConanOutput
99
from conan.internal.api.uploader import compress_files
1010
from conan.internal.cache.cache import PkgCache
11-
from conan.internal.cache.conan_reference_layout import EXPORT_SRC_FOLDER, EXPORT_FOLDER, SRC_FOLDER, \
12-
METADATA, DOWNLOAD_EXPORT_FOLDER
11+
from conan.internal.cache.conan_reference_layout import (EXPORT_SRC_FOLDER, EXPORT_FOLDER,
12+
SRC_FOLDER, METADATA,
13+
DOWNLOAD_EXPORT_FOLDER)
1314
from conan.internal.cache.home_paths import HomePaths
1415
from conan.internal.cache.integrity_check import IntegrityChecker
1516
from conan.internal.rest.download_cache import DownloadCache
@@ -104,7 +105,8 @@ def clean(self, package_list, source=True, build=True, download=True, temp=True,
104105
if not os.path.exists(manifest) or not os.path.exists(info):
105106
rmdir(folder)
106107
if backup_sources:
107-
backup_files = self._conan_api.cache.get_backup_sources(package_list, exclude=False, only_upload=False)
108+
backup_files = self._conan_api.cache.get_backup_sources(package_list, exclude=False,
109+
only_upload=False)
108110
ConanOutput().verbose(f"Cleaning {len(backup_files)} backup sources")
109111
for f in backup_files:
110112
remove(f)
@@ -175,7 +177,8 @@ def save(self, package_list, tgz_path, no_source=False):
175177
pkglist_path = os.path.join(tempfile.gettempdir(), "pkglist.json")
176178
save(pkglist_path, serialized)
177179
tar_files["pkglist.json"] = pkglist_path
178-
compress_files(tar_files, os.path.basename(tgz_path), os.path.dirname(tgz_path), compresslevel, recursive=True)
180+
compress_files(tar_files, os.path.basename(tgz_path), os.path.dirname(tgz_path),
181+
compresslevel, recursive=True)
179182
remove(pkglist_path)
180183

181184
def restore(self, path):
@@ -260,7 +263,8 @@ def get_backup_sources(self, package_list=None, exclude=True, only_upload=True):
260263
download_cache_path = config.get("core.sources:download_cache")
261264
download_cache_path = download_cache_path or HomePaths(
262265
self._conan_api.cache_folder).default_sources_backup_folder
263-
excluded_urls = config.get("core.sources:exclude_urls", check_type=list, default=[]) if exclude else []
266+
excluded_urls = config.get("core.sources:exclude_urls",
267+
check_type=list, default=[]) if exclude else []
264268
download_cache = DownloadCache(download_cache_path)
265269
return download_cache.get_backup_sources_files(excluded_urls, package_list, only_upload)
266270

conan/api/subapi/graph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def load_root_test_conanfile(self, path, tested_reference, profile_host, profile
8888
return root_node
8989

9090
def _load_root_virtual_conanfile(self, profile_host, profile_build, requires, tool_requires,
91-
lockfile, remotes, update, check_updates=False, python_requires=None):
91+
lockfile, remotes, update, check_updates=False,
92+
python_requires=None):
9293
if not python_requires and not requires and not tool_requires:
9394
raise ConanException("Provide requires or tool_requires")
9495
app = ConanApp(self._conan_api)
@@ -164,8 +165,8 @@ def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remo
164165
""" Compute the dependency graph, starting from a root package, evaluation the graph with
165166
the provided configuration in profile_build, and profile_host. The resulting graph is a
166167
graph of recipes, but packages are not computed yet (package_ids) will be empty in the
167-
result. The result might have errors, like version or configuration conflicts, but it is still
168-
possible to inspect it. Only trying to install such graph will fail
168+
result. The result might have errors, like version or configuration conflicts, but it is
169+
still possible to inspect it. Only trying to install such graph will fail
169170
170171
:param root_node: the starting point, an already initialized Node structure, as
171172
returned by the "load_root_node" api

conan/api/subapi/install.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def install_sources(self, graph, remotes):
6060

6161
# TODO: Look for a better name
6262
def install_consumer(self, deps_graph, generators=None, source_folder=None, output_folder=None,
63-
deploy=False, deploy_package=None, deploy_folder=None, envs_generation=None):
63+
deploy=False, deploy_package=None, deploy_folder=None,
64+
envs_generation=None):
6465
""" Once a dependency graph has been installed, there are things to be done, like invoking
6566
generators for the root consumer.
6667
This is necessary for example for conanfile.txt/py, or for "conan install <ref> -g
@@ -101,5 +102,5 @@ def install_consumer(self, deps_graph, generators=None, source_folder=None, outp
101102
envs_generation=envs_generation)
102103

103104
def deploy(self, graph, deployer, deploy_package=None, deploy_folder=None):
104-
return do_deploys(self._conan_api.home_folder, graph, deployer, deploy_package=deploy_package,
105-
deploy_folder=deploy_folder)
105+
return do_deploys(self._conan_api.home_folder, graph, deployer,
106+
deploy_package=deploy_package, deploy_folder=deploy_folder)

conan/api/subapi/remotes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def disable(self, pattern):
5858
5959
:param pattern: single ``str`` or list of ``str``. If the pattern is an exact name without
6060
wildcards like "*" and no remote is found matching that exact name, it will raise an error.
61-
:return: the list of disabled :ref:`Remote <conan.api.model.Remote>` objects (even if they were already disabled)
61+
:return: the list of disabled :ref:`Remote <conan.api.model.Remote>` objects (even if they
62+
were already disabled)
6263
"""
6364
remotes = _load(self._remotes_file)
6465
disabled = _filter(remotes, pattern, only_enabled=False)
@@ -76,7 +77,8 @@ def enable(self, pattern):
7677
7778
:param pattern: single ``str`` or list of ``str``. If the pattern is an exact name without
7879
wildcards like "*" and no remote is found matching that exact name, it will raise an error.
79-
:return: the list of enabled :ref:`Remote <conan.api.model.Remote>` objects (even if they were already enabled)
80+
:return: the list of enabled :ref:`Remote <conan.api.model.Remote>` objects (even if they
81+
were already enabled)
8082
"""
8183
remotes = _load(self._remotes_file)
8284
enabled = _filter(remotes, pattern, only_enabled=False)
@@ -93,7 +95,8 @@ def get(self, remote_name):
9395
Obtain a :ref:`Remote <conan.api.model.Remote>` object
9496
9597
:param remote_name: the exact name of the remote to be returned
96-
:return: the :ref:`Remote <conan.api.model.Remote>` object, or raise an Exception if the remote does not exist.
98+
:return: the :ref:`Remote <conan.api.model.Remote>` object, or raise an Exception if the
99+
remote does not exist.
97100
"""
98101
remotes = _load(self._remotes_file)
99102
try:

conan/api/subapi/report.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def _source(path_to_conanfile, reference):
7878
"dst_prefix": dst_prefix,
7979
}
8080

81+
8182
def _configure_source(conan_api, hook_manager, conanfile_path, ref, remotes):
8283
app = ConanApp(conan_api)
8384
conanfile = app.loader.load_consumer(conanfile_path, name=ref.name, version=str(ref.version),
@@ -100,6 +101,7 @@ def _configure_source(conan_api, hook_manager, conanfile_path, ref, remotes):
100101
conanfile.folders.set_base_recipe_metadata(recipe_layout.metadata())
101102
config_source(export_source_folder, conanfile, hook_manager)
102103

104+
103105
def _get_ref_from_cache_or_remote(conan_api, reference, enabled_remotes):
104106
ref = RecipeReference.loads(reference)
105107
full_ref, matching_remote = None, False

conan/cli/commands/remote.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
import json
32
import os
43
from collections import OrderedDict
@@ -19,7 +18,7 @@ def _print_remotes_json(remotes):
1918
"verify_ssl": r.verify_ssl,
2019
"enabled": not r.disabled,
2120
"allowed_packages": r.allowed_packages,
22-
"recipes_only": r.recipes_only,}
21+
"recipes_only": r.recipes_only}
2322
for r in remotes]
2423
cli_out_write(json.dumps(info, indent=4))
2524

@@ -128,15 +127,17 @@ def remote_update(conan_api, parser, subparser, *args):
128127
subparser.add_argument("--index", action=OnceArgument, type=int,
129128
help="Insert the remote at a specific position in the remote list")
130129
subparser.add_argument("-ap", "--allowed-packages", action="append", default=None,
131-
help="Add recipe reference pattern to the list of allowed packages for this remote")
130+
help="Add recipe reference pattern to the list of allowed packages "
131+
"for this remote")
132132
subparser.add_argument("--recipes-only", default=None, const="True", nargs="?",
133133
choices=["True", "False"],
134-
help="Disallow binary downloads from this remote, only recipes will be downloaded")
134+
help="Disallow binary downloads from this remote, only recipes will "
135+
"be downloaded")
135136

136137
subparser.set_defaults(secure=None)
137138
args = parser.parse_args(*args)
138139
if (args.url is None and args.secure is None and args.index is None and
139-
args.allowed_packages is None and args.recipes_only is None):
140+
args.allowed_packages is None and args.recipes_only is None):
140141
subparser.error("Please add at least one argument to update")
141142
args.recipes_only = None if args.recipes_only is None else args.recipes_only == "True"
142143
conan_api.remotes.update(args.remote, args.url, args.secure, index=args.index,
@@ -277,7 +278,8 @@ def _print_auth_json(results):
277278
@conan_subcommand(formatters={"text": _print_auth, "json": _print_auth_json})
278279
def remote_auth(conan_api, parser, subparser, *args):
279280
"""
280-
Authenticate in the defined remotes. Use CONAN_LOGIN_USERNAME* and CONAN_PASSWORD* variables if available.
281+
Authenticate in the defined remotes. Use CONAN_LOGIN_USERNAME* and CONAN_PASSWORD* variables
282+
if available.
281283
Ask for username and password interactively in case (re-)authentication is required and there are
282284
no CONAN_LOGIN* and CONAN_PASSWORD* variables available which could be used.
283285
Usually you'd use this method over conan remote login for scripting which needs to run in CI

conan/internal/api/config/config_installer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def _process_file(directory, filename, config, cache_folder, folder):
143143
output.info("Copying file %s to %s" % (filename, target_folder))
144144
_filecopy(directory, filename, target_folder)
145145

146+
146147
def _process_folder(config, folder, cache_folder, ignore=None):
147148
if not os.path.isdir(folder):
148149
raise ConanException("No such directory: '%s'" % str(folder))

0 commit comments

Comments
 (0)