refactor(treewide): formatting and ruff fixes, + manually enabled F401

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang
2024-03-27 11:37:26 +05:30
parent c28d19cf7f
commit 4d34b1ead7
618 changed files with 4188 additions and 6384 deletions

View File

@@ -9,36 +9,35 @@ test_records = frappe.get_test_records("Company")
class TestInit(unittest.TestCase):
def test_encode_company_abbr(self):
abbr = "NFECT"
names = [
"Warehouse Name",
"ERPNext Foundation India",
"Gold - Member - {a}".format(a=abbr),
" - {a}".format(a=abbr),
f"Gold - Member - {abbr}",
f" - {abbr}",
"ERPNext - Foundation - India",
"ERPNext Foundation India - {a}".format(a=abbr),
"No-Space-{a}".format(a=abbr),
f"ERPNext Foundation India - {abbr}",
f"No-Space-{abbr}",
"- Warehouse",
]
expected_names = [
"Warehouse Name - {a}".format(a=abbr),
"ERPNext Foundation India - {a}".format(a=abbr),
"Gold - Member - {a}".format(a=abbr),
" - {a}".format(a=abbr),
"ERPNext - Foundation - India - {a}".format(a=abbr),
"ERPNext Foundation India - {a}".format(a=abbr),
"No-Space-{a} - {a}".format(a=abbr),
"- Warehouse - {a}".format(a=abbr),
f"Warehouse Name - {abbr}",
f"ERPNext Foundation India - {abbr}",
f"Gold - Member - {abbr}",
f" - {abbr}",
f"ERPNext - Foundation - India - {abbr}",
f"ERPNext Foundation India - {abbr}",
f"No-Space-{abbr} - {abbr}",
f"- Warehouse - {abbr}",
]
for i in range(len(names)):
enc_name = encode_company_abbr(names[i], abbr=abbr)
self.assertTrue(
enc_name == expected_names[i],
"{enc} is not same as {exp}".format(enc=enc_name, exp=expected_names[i]),
f"{enc_name} is not same as {expected_names[i]}",
)
def test_translation_files(self):

View File

@@ -9,12 +9,8 @@ class TestWebsite(unittest.TestCase):
def test_permission_for_custom_doctype(self):
create_user("Supplier 1", "supplier1@gmail.com")
create_user("Supplier 2", "supplier2@gmail.com")
create_supplier_with_contact(
"Supplier1", "All Supplier Groups", "Supplier 1", "supplier1@gmail.com"
)
create_supplier_with_contact(
"Supplier2", "All Supplier Groups", "Supplier 2", "supplier2@gmail.com"
)
create_supplier_with_contact("Supplier1", "All Supplier Groups", "Supplier 1", "supplier1@gmail.com")
create_supplier_with_contact("Supplier2", "All Supplier Groups", "Supplier 2", "supplier2@gmail.com")
po1 = create_purchase_order(supplier="Supplier1")
po2 = create_purchase_order(supplier="Supplier2")
@@ -62,9 +58,9 @@ def create_user(name, email):
def create_supplier_with_contact(name, group, contact_name, contact_email):
supplier = frappe.get_doc(
{"doctype": "Supplier", "supplier_name": name, "supplier_group": group}
).insert(ignore_if_duplicate=True)
supplier = frappe.get_doc({"doctype": "Supplier", "supplier_name": name, "supplier_group": group}).insert(
ignore_if_duplicate=True
)
if not frappe.db.exists("Contact", contact_name + "-1-" + name):
new_contact = frappe.new_doc("Contact")

View File

@@ -1,12 +1,12 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from typing import Any, Dict, NewType, Optional
from typing import Any, NewType
import frappe
from frappe.core.doctype.report.report import get_report_module_dotted_path
ReportFilters = Dict[str, Any]
ReportFilters = dict[str, Any]
ReportName = NewType("ReportName", str)
@@ -57,8 +57,8 @@ def execute_script_report(
report_name: ReportName,
module: str,
filters: ReportFilters,
default_filters: Optional[ReportFilters] = None,
optional_filters: Optional[ReportFilters] = None,
default_filters: ReportFilters | None = None,
optional_filters: ReportFilters | None = None,
):
"""Util for testing execution of a report with specified filters.
@@ -77,9 +77,7 @@ def execute_script_report(
default_filters = {}
test_filters = []
report_execute_fn = frappe.get_attr(
get_report_module_dotted_path(module, report_name) + ".execute"
)
report_execute_fn = frappe.get_attr(get_report_module_dotted_path(module, report_name) + ".execute")
report_filters = frappe._dict(default_filters).copy().update(filters)
test_filters.append(report_filters)