Skip to content

Commit

Permalink
Merge pull request #8713 from cfpb/ans_ruff_update
Browse files Browse the repository at this point in the history
Ruff auto-format changes for v0.9.0
  • Loading branch information
anselmbradford authored Jan 9, 2025
2 parents 181307b + f4dd7d1 commit e83f7a8
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 76 deletions.
2 changes: 1 addition & 1 deletion cfgov/cdntools/management/commands/purge_by_cache_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def add_arguments(self, parser):
"--cache_tag",
required=True,
nargs="+",
help=("The cache tag to invalidate " "(can specify multiple)"),
help=("The cache tag to invalidate (can specify multiple)"),
)
parser.add_argument(
"--action",
Expand Down
2 changes: 1 addition & 1 deletion cfgov/cfgov/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def handle_error(code, request, exception=None):
# the results of a security scan, or a malformed static file reference.

return HttpResponse(
"This request could not be processed, " f"HTTP Error {str(code)}.",
f"This request could not be processed, HTTP Error {str(code)}.",
status=code,
)

Expand Down
2 changes: 1 addition & 1 deletion cfgov/core/management/commands/inactive_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def handle(self, *args, **options):
# Notify specified emails (e.g. system admins)
if len(emails) > 0:
self.stdout.write(
"Sending inactive user list to " "{}\n".format(
"Sending inactive user list to {}\n".format(
",".join(emails)
)
)
Expand Down
36 changes: 14 additions & 22 deletions cfgov/data_research/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ def test_dump_as_csv(self):

self.assertEqual(content.strip(), ",".join(self.data_row))

@mock.patch(
"data_research.scripts.process_mortgage_data." "read_in_s3_csv"
)
@mock.patch("data_research.scripts.process_mortgage_data." "dump_as_csv")
@mock.patch("data_research.scripts.process_mortgage_data." "load_counties")
@mock.patch("data_research.scripts.process_mortgage_data." "load_states")
@mock.patch("data_research.scripts.process_mortgage_data.read_in_s3_csv")
@mock.patch("data_research.scripts.process_mortgage_data.dump_as_csv")
@mock.patch("data_research.scripts.process_mortgage_data.load_counties")
@mock.patch("data_research.scripts.process_mortgage_data.load_states")
def test_process_source(
self, mock_states, mock_counties, mock_dump, mock_read
):
Expand Down Expand Up @@ -177,9 +175,7 @@ def test_process_source(
self.assertEqual(mock_counties.call_count, 1)
self.assertEqual(mock_states.call_count, 1)

@mock.patch(
"data_research.scripts.process_mortgage_data." "process_source"
)
@mock.patch("data_research.scripts.process_mortgage_data.process_source")
@mock.patch(
"data_research.scripts.process_mortgage_data."
"update_through_date_constant"
Expand All @@ -193,7 +189,7 @@ def test_process_source(
"update_county_msa_meta.run"
)
@mock.patch(
"data_research.scripts.process_mortgage_data." "export_public_csvs.run"
"data_research.scripts.process_mortgage_data.export_public_csvs.run"
)
def test_run_command(
self,
Expand Down Expand Up @@ -237,9 +233,7 @@ def setUp(self):
)

# real values from a base CSV row
self.data_header = (
"date,fips,open,current,thirty,sixty,ninety," "other\n"
)
self.data_header = "date,fips,open,current,thirty,sixty,ninety,other\n"
self.data_row = "09/01/16,12081,1952,1905,21,5,10,11\n"
self.data_row_dict = {
"date": "09/01/16",
Expand Down Expand Up @@ -639,7 +633,7 @@ def test_load_national_values(self):
self.assertEqual(NationalMortgageData.objects.count(), 1)

@mock.patch(
"data_research.scripts." "load_mortgage_performance_csv.read_in_s3_csv"
"data_research.scripts.load_mortgage_performance_csv.read_in_s3_csv"
)
def test_load_values(self, mock_read_in):
mock_read_in.return_value = [
Expand All @@ -660,7 +654,7 @@ def test_load_values(self, mock_read_in):
self.assertEqual(CountyMortgageData.objects.count(), 1)

@mock.patch(
"data_research.scripts." "load_mortgage_performance_csv.read_in_s3_csv"
"data_research.scripts.load_mortgage_performance_csv.read_in_s3_csv"
)
def test_load_values_return_fips(self, mock_read_in):
mock_read_in.return_value = [
Expand All @@ -681,11 +675,10 @@ def test_load_values_return_fips(self, mock_read_in):
self.assertEqual(fips_list, ["12081"])

@mock.patch(
"data_research.scripts."
"load_mortgage_aggregates.update_sampling_dates"
"data_research.scripts.load_mortgage_aggregates.update_sampling_dates"
)
@mock.patch(
"data_research.scripts." "load_mortgage_aggregates.validate_counties"
"data_research.scripts.load_mortgage_aggregates.validate_counties"
)
def test_run_aggregates(self, mock_validate_counties, mock_update_dates):
dates = MortgageMetaData.objects.get(name="sampling_dates")
Expand Down Expand Up @@ -844,7 +837,7 @@ def load_fips(self, mock_obj):
mock_obj.county_fips = self.counties
return mock_obj

@mock.patch("data_research.scripts." "update_county_msa_meta.FIPS")
@mock.patch("data_research.scripts.update_county_msa_meta.FIPS")
def test_update_msa_meta(self, mock_FIPS):
mock_FIPS = self.load_fips(mock_FIPS)
self.assertFalse(
Expand All @@ -859,7 +852,7 @@ def test_update_msa_meta(self, mock_FIPS):
).json_value
self.assertEqual(len(test_json), 2)

@mock.patch("data_research.scripts." "update_county_msa_meta.FIPS")
@mock.patch("data_research.scripts.update_county_msa_meta.FIPS")
def test_update_county_meta(self, mock_FIPS):
mock_FIPS = self.load_fips(mock_FIPS)
self.assertFalse(
Expand All @@ -876,8 +869,7 @@ class UpdateStateMsaDropdownTests(django.test.TestCase):
fixtures = ["mortgage_constants.json", "mortgage_metadata.json"]

@mock.patch(
"data_research.scripts."
"update_county_msa_meta.update_state_to_geo_meta"
"data_research.scripts.update_county_msa_meta.update_state_to_geo_meta"
)
def test_run_rebuild(self, mock_update):
run_update()
Expand Down
6 changes: 3 additions & 3 deletions cfgov/paying_for_college/disclosures/scripts/load_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def load(source, s3=False):
data = serializer.validated_data
if not validate_pid(data["program_code"]):
print(
"ERROR: invalid program code: " "{}".format(
"ERROR: invalid program code: {}".format(
data["program_code"]
)
)
Expand All @@ -234,10 +234,10 @@ def load(source, s3=False):
program.completion_rate = data["completion_rate"]
program.default_rate = data["default_rate"]
program.mean_student_loan_completers = data[
"mean_student_" "loan_completers"
"mean_student_loan_completers"
]
program.median_student_loan_completers = data[
"median_student_" "loan_completers"
"median_student_loan_completers"
]
program.program_code = data["program_code"]
program.program_name = strip_control_chars(data["program_name"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# test values
OID = "9e0280139f3238cbc9702c7b0d62e5c238a835d0"
ERRORS = "INVALID: test notification via Python"
REPORT = "URL is {}\nOK is {}\nReason is {}\n" "Status is {}\nTime sent is {}"
REPORT = "URL is {}\nOK is {}\nReason is {}\nStatus is {}\nTime sent is {}"


def send_test_notifications(url=None, oid=OID, errors=ERRORS):
Expand Down
14 changes: 6 additions & 8 deletions cfgov/paying_for_college/models/disclosures.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def notify_school(self):
}
now = datetime.datetime.now()
no_contact_msg = (
"School notification failed: " f"No endpoint or email info {now}"
f"School notification failed: No endpoint or email info {now}"
)
# we prefer to use endpount notification, so use it first if existing
if school.contact:
Expand All @@ -608,26 +608,24 @@ def notify_school(self):
try:
resp = requests.post(endpoint, data=payload, timeout=10)
except requests.exceptions.ConnectionError as e:
exmsg = "Error: connection error at school " f"{now} {e}\n"
exmsg = f"Error: connection error at school {now} {e}\n"
self.log = self.log + exmsg
self.save()
return exmsg
except requests.exceptions.Timeout:
exmsg = (
"Error: connection with school " f"timed out {now}\n"
)
exmsg = f"Error: connection with school timed out {now}\n"
self.log = self.log + exmsg
self.save()
return exmsg
except requests.exceptions.RequestException as e:
exmsg = "Error: request error at school: " f"{now} {e}\n"
exmsg = f"Error: request error at school: {now} {e}\n"
self.log = self.log + exmsg
self.save()
return exmsg
else:
if resp.ok:
self.sent = True
self.log = "School notified " f"via endpoint {now}"
self.log = f"School notified via endpoint {now}"
self.save()
return self.log
else:
Expand Down Expand Up @@ -659,7 +657,7 @@ def notify_school(self):
)
self.sent = True
self.emails = school.contact.contacts
self.log = "School notified via email " f"at {self.emails}"
self.log = f"School notified via email at {self.emails}"
self.save()
return self.log
except smtplib.SMTPException as e:
Expand Down
6 changes: 2 additions & 4 deletions cfgov/paying_for_college/tests/test_load_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ def test_read_in_s3(self, mock_requests):
"load_programs.clean_string_as_string"
)
@patch(
"paying_for_college.disclosures.scripts."
"load_programs.standardize_rate"
"paying_for_college.disclosures.scripts.load_programs.standardize_rate"
)
def test_clean(self, mock_standardize, mock_string, mock_number):
mock_number.return_value = "NUMBER"
Expand Down Expand Up @@ -225,8 +224,7 @@ def test_load(self, mock_get_or_create_program, mock_clean, mock_read_in):
"and Schools (ACICS) - Test"
)
jpr_note = (
"The rate reflects employment status "
"as of November 1, 2014 - Test"
"The rate reflects employment status as of November 1, 2014 - Test"
)
program_name = "Occupational Therapy Assistant - 981 - Test"
mock_read_in.return_value = [
Expand Down
2 changes: 1 addition & 1 deletion cfgov/paying_for_college/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def test_clean_csv_headings(self, mock_write, mock_read):
self.assertEqual(mock_write.call_count, 3)

def test_unzip_file(self):
test_zip = f"{COLLEGE_ROOT}/data_sources/ipeds/" "test.txt.zip"
test_zip = f"{COLLEGE_ROOT}/data_sources/ipeds/test.txt.zip"
self.assertTrue(update_ipeds.unzip_file(test_zip))

@patch("paying_for_college.disclosures.scripts.update_ipeds.requests.get")
Expand Down
10 changes: 4 additions & 6 deletions cfgov/paying_for_college/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,23 @@ def test_offer(self):
)
no_oid = "?iped=408039&pid=981&oid="
bad_school = (
"?iped=xxxxxx&pid=981&" "oid=f38283b5b7c939a058889f997949efa566c61"
"?iped=xxxxxx&pid=981&oid=f38283b5b7c939a058889f997949efa566c61"
)
bad_program = (
"?iped=408039&pid=xxx&"
"oid=f38283b5b7c939a058889f997949efa566c616c5"
"?iped=408039&pid=xxx&oid=f38283b5b7c939a058889f997949efa566c616c5"
)
# puerto_rico = '?iped=243197&pid=981&oid='
missing_oid_field = "?iped=408039&pid=981"
missing_school_id = "?iped="
bad_oid = (
"?iped=408039&pid=981&oid=f382"
"<script></script>f997949efa566c616c5"
"?iped=408039&pid=981&oid=f382<script></script>f997949efa566c616c5"
)
illegal_program = (
"?iped=408039&pid=<981>&oid=f38283b"
"5b7c939a058889f997949efa566c616c5"
)
no_program = (
"?iped=408039&pid=&oid=f38283b" "5b7c939a058889f997949efa566c616c5"
"?iped=408039&pid=&oid=f38283b5b7c939a058889f997949efa566c616c5"
)
resp = self.client.get(url + qstring)
self.assertEqual(resp.status_code, 200)
Expand Down
5 changes: 2 additions & 3 deletions cfgov/privacy/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ class PrivacyActForm(forms.Form):
)
system_of_record = forms.CharField(
label=(
"Name of the system of records you believe contain the "
"record(s)"
"Name of the system of records you believe contain the record(s)"
),
required=False,
widget=forms.TextInput(attrs=text_input_attrs),
)
date_of_records = forms.CharField(
label="Date of the record(s)",
help_text=(
"Or the period in which you believe that the record was " "created"
"Or the period in which you believe that the record was created"
),
required=False,
widget=forms.TextInput(attrs=text_input_attrs),
Expand Down
2 changes: 1 addition & 1 deletion cfgov/regulations3k/parser/regtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def table(self):
def assemble_header_rows(self):
if not self.header_rows:
return ""
header_shell = "<thead>\n" "{h_rows}\n" "</thead>\n"
header_shell = "<thead>\n{h_rows}\n</thead>\n"
return header_shell.format(h_rows="\n".join(self.header_rows))

def parse_xml_table(self, table_soup):
Expand Down
4 changes: 2 additions & 2 deletions cfgov/scripts/http_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ def check_urls(base, url_list=None):
logger.error(f"These URLs failed: {failures}")
if len(timeouts) > ALLOWED_TIMEOUTS:
logger.error(
f"These URLs timed out after {TIMEOUT} seconds: " f"{timeouts}"
f"These URLs timed out after {TIMEOUT} seconds: {timeouts}"
)
elif timeouts:
logger.info(
"{} allowed timeouts occurred:\n" "{}".format(
"{} allowed timeouts occurred:\n{}".format(
len(timeouts), "\n".join(timeouts)
)
)
Expand Down
4 changes: 2 additions & 2 deletions cfgov/scripts/static_asset_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def check_static(url):
f"of {count} failed for {url}: {failures}\x1b[0m\n"
)
else:
return f"\x1b[32m{count} static links passed " f"for {url}\x1b[0m\n"
return f"\x1b[32m{count} static links passed for {url}\x1b[0m\n"


if __name__ == "__main__": # pragma: nocover
Expand Down Expand Up @@ -133,7 +133,7 @@ def check_static(url):
)
if fail:
logger.warning(
"\x1b[91mFAIL. Too many static links " "didn't return 200.\x1b[0m"
"\x1b[91mFAIL. Too many static links didn't return 200.\x1b[0m"
)
else:
logger.info("\x1b[32mSUCCESS! Static links return 200.\x1b[0m")
2 changes: 1 addition & 1 deletion cfgov/tccp/management/commands/validate_tccp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def handle(self, **options):
self.stdout.write(f"{invalid_cards.count()} cards with invalid APRs")

for i, invalid_card in enumerate(invalid_cards):
self.stdout.write(f"{i+1}: {invalid_card.slug}")
self.stdout.write(f"{i + 1}: {invalid_card.slug}")

self.stdout.write()

Expand Down
6 changes: 2 additions & 4 deletions cfgov/v1/atomic_elements/molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ class ContactPhone(blocks.StructBlock):
blocks.CharBlock(
max_length=15,
help_text=(
"Do not include spaces or dashes. "
"Ex. 8554112372"
"Do not include spaces or dashes. Ex. 8554112372"
),
validators=[phone_number_format_validator()],
),
Expand All @@ -317,8 +316,7 @@ class ContactPhone(blocks.StructBlock):
required=False,
label="TTY",
help_text=(
"Do not include spaces or dashes. "
"Ex. 8554112372"
"Do not include spaces or dashes. Ex. 8554112372"
),
validators=[phone_number_format_validator()],
),
Expand Down
Loading

0 comments on commit e83f7a8

Please sign in to comment.