Skip to content

Commit

Permalink
lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Feb 5, 2024
1 parent 76872ae commit 88a8a0c
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 39 deletions.
188 changes: 163 additions & 25 deletions faker/providers/automotive/uk_UA/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from typing import Optional

from typing import Optional, Tuple

from .. import Provider as AutomotiveProvider

Expand Down Expand Up @@ -35,42 +36,179 @@ class Provider(AutomotiveProvider):
"Chernihiv": (("SV", "IV", "OV", "RV"), "25"),
"Chernivtsi": (("SE", "IE", "OE", "RE"), "26"),
"Sevastopol": (("SN", "IN", "ON", "RN"), "27"),
"Nationwide": (("II", "ED", "DC", "DI", "PD"), "00")
"Nationwide": (("II", "ED", "DC", "DI", "PD"), "00"),
}

license_plate_suffix = (
"AA", "BA", "CA", "EA", "HA", "IA", "KA", "MA", "OA", "PA", "TA", "XA",
"AB", "BB", "CB", "EB", "HB", "IB", "KB", "MB", "OB", "PB", "TB", "XB",
"AC", "BC", "BR", "EC", "HC", "IC", "KC", "MC", "OC", "PC", "TC", "XC",
"AE", "BE", "CE", "EE", "HE", "IE", "KE", "ME", "OE", "PE", "TE", "XE",
"AN", "BN", "CN", "EN", "HN", "IN", "KN", "MK", "ON", "PN", "TN", "XN",
"AI", "BI", "CI", "EI", "HI", "II", "KI", "MI", "OI", "PI", "TI", "XI",
"AK", "BK", "CK", "EK", "HK", "IK", "KK", "MK", "OK", "PK", "TK", "XK",
"AM", "BM", "CM", "EM", "HM", "IM", "KM", "MM", "OM", "PM", "TM", "XM",
"AO", "BO", "CO", "EO", "HO", "IO", "KO", "MO", "OO", "PO", "TO", "XO",
"AP", "BP", "CP", "EP", "HP", "IP", "KP", "MP", "OP", "PP", "TP", "XP",
"AT", "BT", "CT", "ET", "HT", "IT", "KT", "MT", "OT", "PT", "TT", "XT",
"AX", "BX", "CX", "EX", "HX", "IX", "KX", "MX", "OX", "PX", "TX", "XX",
"AY", "AZ", "BH", "BL", "BN", "BQ", "BR", "TU", "TV", "TY", "TZ"
"AA",
"BA",
"CA",
"EA",
"HA",
"IA",
"KA",
"MA",
"OA",
"PA",
"TA",
"XA",
"AB",
"BB",
"CB",
"EB",
"HB",
"IB",
"KB",
"MB",
"OB",
"PB",
"TB",
"XB",
"AC",
"BC",
"BR",
"EC",
"HC",
"IC",
"KC",
"MC",
"OC",
"PC",
"TC",
"XC",
"AE",
"BE",
"CE",
"EE",
"HE",
"IE",
"KE",
"ME",
"OE",
"PE",
"TE",
"XE",
"AN",
"BN",
"CN",
"EN",
"HN",
"IN",
"KN",
"MK",
"ON",
"PN",
"TN",
"XN",
"AI",
"BI",
"CI",
"EI",
"HI",
"II",
"KI",
"MI",
"OI",
"PI",
"TI",
"XI",
"AK",
"BK",
"CK",
"EK",
"HK",
"IK",
"KK",
"MK",
"OK",
"PK",
"TK",
"XK",
"AM",
"BM",
"CM",
"EM",
"HM",
"IM",
"KM",
"MM",
"OM",
"PM",
"TM",
"XM",
"AO",
"BO",
"CO",
"EO",
"HO",
"IO",
"KO",
"MO",
"OO",
"PO",
"TO",
"XO",
"AP",
"BP",
"CP",
"EP",
"HP",
"IP",
"KP",
"MP",
"OP",
"PP",
"TP",
"XP",
"AT",
"BT",
"CT",
"ET",
"HT",
"IT",
"KT",
"MT",
"OT",
"PT",
"TT",
"XT",
"AX",
"BX",
"CX",
"EX",
"HX",
"IX",
"KX",
"MX",
"OX",
"PX",
"TX",
"XX",
"AY",
"AZ",
"BH",
"BL",
"BN",
"BQ",
"BR",
"TU",
"TV",
"TY",
"TZ",
)

vehicle_categories = (
"A1", "A", "B1", "B",
"C1", "C", "D1", "D",
"BE", "C1E", "CE", "D1E",
"DE", "T"
)
vehicle_categories = ("A1", "A", "B1", "B", "C1", "C", "D1", "D", "BE", "C1E", "CE", "D1E", "DE", "T")

def __get_random_region_code(self, region_name: Optional[str] = None) -> (str, str):
def __get_random_region_code(self, region_name: Optional[str] = None) -> Tuple[str, str]:
try:
if region_name is None:
region_name, data = random.choice(list(self.license_region_data.items()))
region_name, _ = random.choice(list(self.license_region_data.items()))

prefix, region_number = self.license_region_data[region_name]
return random.choice(prefix), region_number
except KeyError:
region_names = ", ".join(self.license_region_data.keys())
raise KeyError(f'Keys name must be only {region_names}')
raise KeyError(f"Keys name must be only {region_names}")

def license_plate(self, region_name: Optional[str] = None, temporary_plate: bool = False) -> str:
"""Generate a license plate.
Expand Down Expand Up @@ -140,7 +278,7 @@ def diplomatic_license_plate(self) -> str:
level = random.choice(("CDP", "DP", "S"))
country_code = self.random_number(3, fix_len=True)
car_number = self.random_number(3, fix_len=True)
if level == 'CDP':
if level == "CDP":
return f"{level} {country_code}"
return f"{level} {country_code} {car_number}"

Expand Down
2 changes: 1 addition & 1 deletion faker/providers/internet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def ipv4_public(self, network: bool = False, address_class: Optional[str] = None

def ipv6(self, network: bool = False) -> str:
"""Produce a random IPv6 address or network with a valid CIDR"""
address = str(IPv6Address(self.generator.random.randint(2**IPV4LENGTH, (2**IPV6LENGTH) - 1)))
address = str(IPv6Address(self.generator.random.randint(2 ** IPV4LENGTH, (2 ** IPV6LENGTH) - 1)))
if network:
address += "/" + str(self.generator.random.randint(0, IPV6LENGTH))
address = str(IPv6Network(address, strict=False))
Expand Down
12 changes: 6 additions & 6 deletions faker/providers/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def pyfloat(
# Make sure left_digits still respected
if left_digits is not None:
if max_value is None:
left_max_value = 10**left_digits # minus smallest representable, adjusted later
left_max_value = 10 ** left_digits # minus smallest representable, adjusted later
if min_value is None:
left_min_value = -(10**left_digits) # plus smallest representable, adjusted later
left_min_value = -(10 ** left_digits) # plus smallest representable, adjusted later

if max_value is not None and max_value < 0:
left_max_value += 1 # as the random_int will be generated up to max_value - 1
Expand Down Expand Up @@ -220,11 +220,11 @@ def pyfloat(
result += sys.float_info.epsilon

if right_digits:
result = min(result, 10**left_digits - float(f'0.{"0" * (right_digits - 1)}1'))
result = max(result, -(10**left_digits + float(f'0.{"0" * (right_digits - 1)}1')))
result = min(result, 10 ** left_digits - float(f'0.{"0" * (right_digits - 1)}1'))
result = max(result, -(10 ** left_digits + float(f'0.{"0" * (right_digits - 1)}1')))
else:
result = min(result, 10**left_digits - 1)
result = max(result, -(10**left_digits + 1))
result = min(result, 10 ** left_digits - 1)
result = max(result, -(10 ** left_digits + 1))

# It's possible for the result to end up > than max_value or < than min_value
# When this happens we introduce some variance so we're not always the exactly the min_value or max_value.
Expand Down
6 changes: 3 additions & 3 deletions tests/providers/test_automotive.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ def test_diplomatic_plate(self, faker, num_samples):

def test_prefix(self, faker):
for _ in range(10):
temporary = faker.plate_letter_prefix(region_name='Lviv')
temporary = faker.plate_letter_prefix(region_name="Lviv")
assert len(temporary) == 2
assert temporary in UkUaAutomotiveProvider.license_region_data.get('Lviv')[0]
assert temporary in UkUaAutomotiveProvider.license_region_data.get("Lviv")[0]

def test_region_code(self, faker):
assert "14" == faker.plate_region_code(region_name='Lviv')
assert "14" == faker.plate_region_code(region_name="Lviv")
2 changes: 1 addition & 1 deletion tests/providers/test_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


def is64bit():
return sys.maxsize > 2**32
return sys.maxsize > 2 ** 32


class UTC(tzinfo):
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ def test_min_value_minus_one_hundred_doesnt_return_positive(self):

def test_min_value_10_pow_1000_return_greater_number(self):
Faker.seed("2")
result = self.fake.pydecimal(min_value=10**1000)
self.assertGreater(result, 10**1000)
result = self.fake.pydecimal(min_value=10 ** 1000)
self.assertGreater(result, 10 ** 1000)


class TestPystr(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_binary(self):
provider = Provider(self.generator)

for _ in range(999):
length = random.randint(0, 2**10)
length = random.randint(0, 2 ** 10)
binary = provider.binary(length)

assert isinstance(binary, (bytes, bytearray))
Expand Down

0 comments on commit 88a8a0c

Please sign in to comment.