Skip to content

Commit

Permalink
Merge pull request #19204 from nsoranzo/fix_UP031_errors_pt2
Browse files Browse the repository at this point in the history
Fix UP031 errors - Part 2
  • Loading branch information
mvdbeek authored Nov 26, 2024
2 parents de5ee59 + 0e6d628 commit d6b92f2
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 172 deletions.
6 changes: 3 additions & 3 deletions lib/tool_shed/grids/admin_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def get_value(self, trans, grid, repository_metadata):
# We used to display the following, but grid was too cluttered.
# for tool_metadata_dict in metadata[ 'tools' ]:
# tools_str += '%s <b>%s</b><br/>' % ( tool_metadata_dict[ 'id' ], tool_metadata_dict[ 'version' ] )
return "%d" % len(metadata["tools"])
return "{}".format(len(metadata["tools"]))
return tools_str

class DatatypesColumn(grids.TextColumn):
Expand All @@ -414,7 +414,7 @@ def get_value(self, trans, grid, repository_metadata):
# We used to display the following, but grid was too cluttered.
# for datatype_metadata_dict in metadata[ 'datatypes' ]:
# datatypes_str += '%s<br/>' % datatype_metadata_dict[ 'extension' ]
return "%d" % len(metadata["datatypes"])
return "{}".format(len(metadata["datatypes"]))
return datatypes_str

class WorkflowsColumn(grids.TextColumn):
Expand All @@ -432,7 +432,7 @@ def get_value(self, trans, grid, repository_metadata):
# workflow_metadata_dicts = [ workflow_tup[1] for workflow_tup in workflow_tups ]
# for workflow_metadata_dict in workflow_metadata_dicts:
# workflows_str += '%s<br/>' % workflow_metadata_dict[ 'name' ]
return "%d" % len(metadata["workflows"])
return "{}".format(len(metadata["workflows"]))
return workflows_str

class DeletedColumn(grids.BooleanColumn):
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/grids/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def build_changeset_revision_select_field(
# Display the latest revision first.
options.insert(0, (changeset_tup[1], changeset_tup[2]))
if add_id_to_name:
name = "changeset_revision_%d" % repository.id
name = f"changeset_revision_{repository.id}"
else:
name = "changeset_revision"
select_field = SelectField(name=name, refresh_on_change=True)
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/managers/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def index_tool_ids(app: ToolShedApp, tool_ids: List[str]) -> Dict[str, Any]:
continue
for tool_metadata in tools:
if tool_metadata["guid"] in tool_ids:
repository_found.append("%d:%s" % (int(changeset), changehash))
repository_found.append(f"{int(changeset)}:{changehash}")
metadata = get_current_repository_metadata_for_changeset_revision(app, repository, changehash)
if metadata is None:
continue
Expand Down
4 changes: 2 additions & 2 deletions lib/tool_shed/metadata/repository_metadata_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,12 @@ def reset_metadata_on_selected_repositories(self, **kwd):
except Exception:
log.exception("Error attempting to reset metadata on repository %s", str(repository.name))
unsuccessful_count += 1
message = "Successfully reset metadata on %d %s. " % (
message = "Successfully reset metadata on {} {}. ".format(
successful_count,
inflector.cond_plural(successful_count, "repository"),
)
if unsuccessful_count:
message += "Error setting metadata on %d %s - see the paster log for details. " % (
message += "Error setting metadata on {} {} - see the paster log for details. ".format(
unsuccessful_count,
inflector.cond_plural(unsuccessful_count, "repository"),
)
Expand Down
25 changes: 5 additions & 20 deletions lib/tool_shed/test/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,6 @@ def check_for_strings(self, strings_displayed=None, strings_not_displayed=None):
for check_str in strings_not_displayed:
self.check_string_not_in_page(check_str)

def check_page(self, strings_displayed, strings_displayed_count, strings_not_displayed):
"""Checks a page for strings displayed, not displayed and number of occurrences of a string"""
for check_str in strings_displayed:
self.check_page_for_string(check_str)
for check_str, count in strings_displayed_count:
self.check_string_count_in_page(check_str, count)
for check_str in strings_not_displayed:
self.check_string_not_in_page(check_str)

def check_page_for_string(self, patt):
"""Looks for 'patt' in the current browser page"""
self._browser.check_page_for_string(patt)
Expand Down Expand Up @@ -905,7 +896,7 @@ def browse_tools(self, strings_displayed=None, strings_not_displayed=None):
self.visit_url(url)
self.check_for_strings(strings_displayed, strings_not_displayed)

def check_count_of_metadata_revisions_associated_with_repository(self, repository: Repository, metadata_count):
def check_count_of_metadata_revisions_associated_with_repository(self, repository: Repository, metadata_count: int):
self.check_repository_changelog(repository)
self.check_string_count_in_page("Repository metadata is associated with this change set.", metadata_count)

Expand Down Expand Up @@ -1011,7 +1002,7 @@ def check_repository_invalid_tools_for_changeset_revision(
strings_not_displayed=strings_not_displayed,
)

def check_string_count_in_page(self, pattern, min_count, max_count=None):
def check_string_count_in_page(self, pattern, min_count: int, max_count: Optional[int] = None):
"""Checks the number of 'pattern' occurrences in the current browser page"""
page = self.last_page()
pattern_count = page.count(pattern)
Expand All @@ -1022,14 +1013,9 @@ def check_string_count_in_page(self, pattern, min_count, max_count=None):
# than max_count.
if pattern_count < min_count or pattern_count > max_count:
fname = self.write_temp_file(page)
errmsg = "%i occurrences of '%s' found (min. %i, max. %i).\npage content written to '%s' " % (
pattern_count,
pattern,
min_count,
max_count,
fname,
raise AssertionError(
f"{pattern_count} occurrences of '{pattern}' found (min. {min_count}, max. {max_count}).\npage content written to '{fname}' "
)
raise AssertionError(errmsg)

def check_galaxy_repository_tool_panel_section(
self, repository: galaxy_model.ToolShedRepository, expected_tool_panel_section: str
Expand Down Expand Up @@ -2098,8 +2084,7 @@ def _wait_for_installation(repository: galaxy_model.ToolShedRepository, refresh)
# This timeout currently defaults to 10 minutes.
if timeout_counter > repository_installation_timeout:
raise AssertionError(
"Repository installation timed out, %d seconds elapsed, repository state is %s."
% (timeout_counter, repository.status)
f"Repository installation timed out, {timeout_counter} seconds elapsed, repository state is {repository.status}."
)
time.sleep(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_0130_verify_handling_of_invalid_characters(self):
# unicode decoding error message.
content = self._escape_page_content_if_needed("These characters should not")
strings_displayed = [
"%d:%s" % (revision_number, revision_hash),
f"{revision_number}:{revision_hash}",
"filtering_0000",
"user1",
"repos",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ def test_0020_verify_dependency_metadata(self):
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, tip)
# Make sure that the new tip is now downloadable, and that there are no other downloadable revisions.
assert metadata_record.downloadable, "Tip is not downloadable."
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 1
), "Repository %s has %d downloadable revisions, expected 1." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 1
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1."

def test_0025_delete_repository_dependency(self):
"""Delete the repository_dependencies.xml from convert_chars_0440.
Expand All @@ -174,12 +172,10 @@ def test_0025_delete_repository_dependency(self):
metadata_record.downloadable
), f"The revision of {repository.name} that does not contain repository_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 2
), "Repository %s has %d downloadable revisions, expected 2." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 2
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 2."

def test_0030_create_bwa_package_repository(self):
"""Create and populate the bwa_package_0440 repository.
Expand Down Expand Up @@ -257,12 +253,10 @@ def test_0045_verify_dependency_metadata(self):
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, tip)
# Make sure that the new tip is now downloadable, and that there are no other downloadable revisions.
assert metadata_record.downloadable, "Tip is not downloadable."
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 1
), "Repository %s has %d downloadable revisions, expected 1." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 1
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1."

def test_0050_delete_complex_repository_dependency(self):
"""Delete the tool_dependencies.xml from bwa_base_0440.
Expand All @@ -287,12 +281,10 @@ def test_0050_delete_complex_repository_dependency(self):
metadata_record.downloadable
), f"The revision of {repository.name} that does not contain tool_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 2
), "Repository %s has %d downloadable revisions, expected 2." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 2
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 2."

def test_0055_create_bwa_tool_dependency_repository(self):
"""Create and populate the bwa_tool_dependency_0440 repository.
Expand Down Expand Up @@ -340,12 +332,10 @@ def test_0060_delete_bwa_tool_dependency_definition(self):
metadata_record is None
), f"The tip revision of {repository.name} should not have metadata, but metadata was found."
# Verify that the new changeset revision is not downloadable.
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 1
), "Repository %s has %d downloadable revisions, expected 1." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 1
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1."

def test_0065_reupload_bwa_tool_dependency_definition(self):
"""Reupload the tool_dependencies.xml file to bwa_tool_dependency_0440.
Expand All @@ -372,12 +362,10 @@ def test_0065_reupload_bwa_tool_dependency_definition(self):
metadata_record.downloadable
), f"The revision of {repository.name} that contains tool_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions)
assert (
len(self._db_repository(repository).downloadable_revisions) == 1
), "Repository %s has %d downloadable revisions, expected 1." % (
repository.name,
len(self._db_repository(repository).downloadable_revisions),
)
n_downloadable_revisions == 1
), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1."

def _get_repository_metadata_by_changeset_revision(self, repository: Repository, changeset: str):
return self.get_repository_metadata_by_changeset_revision(self._db_repository(repository).id, changeset)
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ def test_0020_upload_updated_tool_dependency_to_package_x11(self):
# Upload the tool dependency definition to the package_x11_client_1_5_proto_7_0_0470 repository.
self.user_populator().setup_test_data_repo("libx11_proto", package_x11_repository, start=1, end=2)
count = self._get_metadata_revision_count(package_x11_repository)
assert count == 1, (
"package_x11_client_1_5_proto_7_0_0470 has incorrect number of metadata revisions, expected 1 but found %d"
% count
)
assert (
count == 1
), f"package_x11_client_1_5_proto_7_0_0470 has incorrect number of metadata revisions, expected 1 but found {count}"

def test_0025_upload_updated_tool_dependency_to_package_emboss(self):
"""Upload a new tool_dependencies.xml to package_emboss_5_0_0_0470.
Expand All @@ -164,9 +163,9 @@ def test_0025_upload_updated_tool_dependency_to_package_emboss(self):
"package_emboss_5_0_0_0470", package_emboss_repository, start=1, end=2
)
count = self._get_metadata_revision_count(package_emboss_repository)
assert count == 2, (
"package_emboss_5_0_0_0470 has incorrect number of metadata revisions, expected 2 but found %d" % count
)
assert (
count == 2
), f"package_emboss_5_0_0_0470 has incorrect number of metadata revisions, expected 2 but found {count}"

def test_0030_upload_updated_tool_dependency_to_emboss_5_repository(self):
"""Upload a new tool_dependencies.xml to emboss_5_0470.
Expand Down Expand Up @@ -216,11 +215,9 @@ def test_0045_reset_repository_metadata(self):
self.reset_repository_metadata(package_emboss_repository)
self.reset_repository_metadata(package_x11_repository)
count = self._get_metadata_revision_count(package_emboss_repository)
assert count == 1, "Repository package_emboss_5_0_0 has %d installable revisions, expected 1." % count
assert count == 1, f"Repository package_emboss_5_0_0 has {count} installable revisions, expected 1."
count = self._get_metadata_revision_count(package_x11_repository)
assert count == 1, (
"Repository package_x11_client_1_5_proto_7_0 has %d installable revisions, expected 1." % count
)
assert count == 1, f"Repository package_x11_client_1_5_proto_7_0 has {count} installable revisions, expected 1."

def test_0050_reset_emboss_5_metadata(self):
"""Reset metadata on emboss_5.
Expand All @@ -230,4 +227,4 @@ def test_0050_reset_emboss_5_metadata(self):
emboss_repository = self._get_repository_by_name_and_owner(emboss_repository_name, common.test_user_1_name)
self.reset_repository_metadata(emboss_repository)
count = self._get_metadata_revision_count(emboss_repository)
assert count == 1, "Repository emboss_5 has %d installable revisions, expected 1." % count
assert count == 1, f"Repository emboss_5 has {count} installable revisions, expected 1."
Loading

0 comments on commit d6b92f2

Please sign in to comment.