Tools: Fix flake8 version 5 warnings

pull/9565/head
Roland Dobai 2022-08-10 09:01:57 +02:00 zatwierdzone przez BOT
rodzic 656936d32a
commit bab3830797
15 zmienionych plików z 39 dodań i 39 usunięć

Wyświetl plik

@ -63,7 +63,7 @@ variables:
BOT_DOCKER_IMAGE_TAG: ":latest"
ESP_IDF_DOC_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3"
ESP_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-env-v5.0:2"
ESP_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-env-v5.0:3"
AFL_FUZZER_TEST_IMAGE: "$CI_DOCKER_REGISTRY/afl-fuzzer-test-v5.0:2-1"
CLANG_STATIC_ANALYSIS_IMAGE: "${CI_DOCKER_REGISTRY}/clang-static-analysis-v5.0:2-1"
TARGET_TEST_ENV_IMAGE: "$CI_DOCKER_REGISTRY/target-test-env-v5.0:2"

Wyświetl plik

@ -30,7 +30,7 @@ repos:
args: ['-f=lf']
- id: double-quote-string-fixer
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
rev: 5.0.4
hooks:
- id: flake8
args: ['--config=.flake8', '--tee', '--benchmark']

Wyświetl plik

@ -51,8 +51,8 @@ def main(): # type: () -> None
# pass the extra_gdbinit_file if the build is reproducible
kwargs['extra_gdbinit_file'] = get_prefix_map_gdbinit_path(kwargs['prog'])
del(kwargs['debug'])
del(kwargs['operation'])
del kwargs['debug']
del kwargs['operation']
espcoredump = CoreDump(**kwargs)
temp_core_files = None

Wyświetl plik

@ -107,7 +107,7 @@ class CertificateBundle:
if start is True:
crt += strg
if(count == 0):
if count == 0:
raise InputError('No certificate found')
status('Successfully added %d certificates' % count)

Wyświetl plik

@ -167,7 +167,7 @@ class SpiffsObjLuPage(SpiffsPage):
img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] +
SpiffsPage._len_dict[self.build_config.obj_id_len], obj_id)
assert(len(img) <= self.build_config.page_size)
assert len(img) <= self.build_config.page_size
img += b'\xFF' * (self.build_config.page_size - len(img))
@ -249,7 +249,7 @@ class SpiffsObjIndexPage(SpiffsObjPageWithIdx):
img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] +
SpiffsPage._len_dict[self.build_config.page_ix_len], page)
assert(len(img) <= self.build_config.page_size)
assert len(img) <= self.build_config.page_size
img += b'\xFF' * (self.build_config.page_size - len(img))
@ -275,7 +275,7 @@ class SpiffsObjDataPage(SpiffsObjPageWithIdx):
img += self.contents
assert(len(img) <= self.build_config.page_size)
assert len(img) <= self.build_config.page_size
img += b'\xFF' * (self.build_config.page_size - len(img))
@ -374,7 +374,7 @@ class SpiffsBlock(object):
for page in self.pages:
img += page.to_binary()
assert(len(img) <= self.build_config.block_size)
assert len(img) <= self.build_config.block_size
img += b'\xFF' * (self.build_config.block_size - len(img))
return img

Wyświetl plik

@ -48,22 +48,22 @@ def test_esp_timer(dut: Dut) -> None:
logging.info('Start time: {} us'.format(start_time))
match = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2)
assert(match.group(1).decode('utf8') == 'periodic' and int(match.group(2)) == INITIAL_TIMER_PERIOD)
assert match.group(1).decode('utf8') == 'periodic' and int(match.group(2)) == INITIAL_TIMER_PERIOD
match = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2)
assert(match.group(1).decode('utf8') == 'one-shot' and int(match.group(2)) == 0)
assert match.group(1).decode('utf8') == 'one-shot' and int(match.group(2)) == 0
for i in range(0, 5):
match = dut.expect(PERIODIC_TIMER_REGEX, timeout=2)
cur_time = int(match.group(1))
diff = start_time + (i + 1) * INITIAL_TIMER_PERIOD - cur_time
logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
assert(abs(diff) < 100)
assert abs(diff) < 100
match = dut.expect(ONE_SHOT_REGEX, timeout=3)
one_shot_timer_time = int(match.group(1))
diff = start_time + ONE_SHOT_TIMER_PERIOD - one_shot_timer_time
logging.info('One-shot timer, time: {} us, diff: {}'.format(one_shot_timer_time, diff))
assert(abs(diff) < 350)
assert abs(diff) < 350
match = dut.expect(RESTART_REGEX, timeout=3)
start_time = int(match.group(1))
@ -74,7 +74,7 @@ def test_esp_timer(dut: Dut) -> None:
cur_time = int(match.group(1))
diff = start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time
logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
assert(abs(diff) < 100)
assert abs(diff) < 100
match = dut.expect(LIGHT_SLEEP_ENTER_REGEX, timeout=2)
sleep_enter_time = int(match.group(1))
@ -85,13 +85,13 @@ def test_esp_timer(dut: Dut) -> None:
logging.info('Enter sleep: {}, exit sleep: {}, slept: {}'.format(
sleep_enter_time, sleep_exit_time, sleep_time))
assert(abs(sleep_time - LIGHT_SLEEP_TIME) < 1000)
assert abs(sleep_time - LIGHT_SLEEP_TIME) < 1000
for i in range(5, 7):
match = dut.expect(PERIODIC_TIMER_REGEX, timeout=2)
cur_time = int(match.group(1))
diff = abs(start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time)
logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
assert(diff < 100)
assert diff < 100
dut.expect(STOP_REGEX, timeout=2)

Wyświetl plik

@ -39,7 +39,7 @@ def test_light_sleep(dut: Dut) -> None:
match = dut.expect(EXIT_SLEEP_REGEX)
logging.info('Got second sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3)))
# sleep time error should be less than 1ms
assert(match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1)
assert match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1
# this time we'll test gpio wakeup
dut.expect_exact(ENTERING_SLEEP_STR)
@ -48,7 +48,7 @@ def test_light_sleep(dut: Dut) -> None:
time.sleep(1)
match = dut.expect(EXIT_SLEEP_PIN_REGEX)
logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3)))
assert(int(match.group(3)) < WAKEUP_INTERVAL_MS)
assert int(match.group(3)) < WAKEUP_INTERVAL_MS
dut.expect(WAITING_FOR_GPIO_STR)
logging.info('Is waiting for GPIO...')
@ -62,9 +62,9 @@ def test_light_sleep(dut: Dut) -> None:
time.sleep(1)
match = dut.expect(EXIT_SLEEP_UART_REGEX)
logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3)))
assert(int(match.group(3)) < WAKEUP_INTERVAL_MS)
assert int(match.group(3)) < WAKEUP_INTERVAL_MS
logging.info('Went to sleep again')
match = dut.expect(EXIT_SLEEP_REGEX)
assert(match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1)
assert match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1
logging.info('Woke up from timer again')

Wyświetl plik

@ -216,7 +216,7 @@ class IDFDUT(DUT.SerialDUT):
if expected_rom_class and type(inst) != expected_rom_class:
raise RuntimeError('Target not expected')
return inst.read_mac() is not None, get_target_by_rom_class(type(inst))
except(FatalError, RuntimeError):
except (FatalError, RuntimeError):
return False, None
finally:
if inst is not None:

Wyświetl plik

@ -83,9 +83,9 @@ class ErrItem(object):
base = '_BASE'
if self.file == other.file:
if self.name.endswith(base) and not(other.name.endswith(base)):
if self.name.endswith(base) and not other.name.endswith(base):
return 1
elif not(self.name.endswith(base)) and other.name.endswith(base):
elif not self.name.endswith(base) and other.name.endswith(base):
return -1
self_key = self.file + self.name

Wyświetl plik

@ -599,14 +599,14 @@ class IDFTool(object):
self.versions = OrderedDict() # type: Dict[str, IDFToolVersion]
def add_version(self, version): # type: (IDFToolVersion) -> None
assert(type(version) is IDFToolVersion)
assert type(version) is IDFToolVersion
self.versions[version.version] = version
def get_path(self): # type: () -> str
return os.path.join(global_idf_tools_path or '', 'tools', self.name)
def get_path_for_version(self, version): # type: (str) -> str
assert(version in self.versions)
assert version in self.versions
return os.path.join(self.get_path(), version)
def get_export_paths(self, version): # type: (str) -> List[str]
@ -732,7 +732,7 @@ class IDFTool(object):
self.versions_installed.append(version)
def download(self, version): # type: (str) -> None
assert(version in self.versions)
assert version in self.versions
download_obj = self.versions[version].get_download_for_platform(self._platform)
if not download_obj:
fatal('No packages for tool {} platform {}!'.format(self.name, self._platform))
@ -768,12 +768,12 @@ class IDFTool(object):
def install(self, version): # type: (str) -> None
# Currently this is called after calling 'download' method, so here are a few asserts
# for the conditions which should be true once that method is done.
assert (version in self.versions)
assert version in self.versions
download_obj = self.versions[version].get_download_for_platform(self._platform)
assert (download_obj is not None)
assert download_obj is not None
archive_name = os.path.basename(download_obj.url)
archive_path = os.path.join(global_idf_tools_path or '', 'dist', archive_name)
assert (os.path.isfile(archive_path))
assert os.path.isfile(archive_path)
dest_dir = self.get_path_for_version(version)
if os.path.exists(dest_dir):
warn('destination path already exists, removing')

Wyświetl plik

@ -170,7 +170,7 @@ def get_link_anchor(node):
try:
return 'CONFIG_%s' % node.item.name
except AttributeError:
assert(node_is_menu(node)) # only menus should have no item.name
assert node_is_menu(node) # only menus should have no item.name
# for menus, build a link anchor out of the parents
result = []

Wyświetl plik

@ -134,9 +134,9 @@ class EntityNode:
def add_child(self, entity):
child_specificity = self.entity.specificity.value + 1
assert (child_specificity <= Entity.Specificity.SYMBOL.value)
assert child_specificity <= Entity.Specificity.SYMBOL.value
name = entity[Entity.Specificity(child_specificity)]
assert (name and name != Entity.ALL)
assert name and name != Entity.ALL
child = [c for c in self.children if c.name == name]
assert (len(child) <= 1)
@ -174,7 +174,7 @@ class EntityNode:
for sections in self.get_output_sections():
placement = self.placements[sections]
if placement.is_significant():
assert (placement.node == self)
assert placement.node == self
keep = False
sort = None

Wyświetl plik

@ -65,7 +65,7 @@ class InputSectionDesc:
"""
def __init__(self, entity, sections, exclusions=None, keep=False, sort=None):
assert (entity.specificity != Entity.Specificity.SYMBOL)
assert entity.specificity != Entity.Specificity.SYMBOL
self.entity = entity
self.sections = set(sections)
@ -73,8 +73,8 @@ class InputSectionDesc:
self.exclusions = set()
if exclusions:
assert (not [e for e in exclusions if e.specificity == Entity.Specificity.SYMBOL or
e.specificity == Entity.Specificity.NONE])
assert not [e for e in exclusions if e.specificity == Entity.Specificity.SYMBOL or
e.specificity == Entity.Specificity.NONE]
self.exclusions = set(exclusions)
else:
self.exclusions = set()

Wyświetl plik

@ -66,7 +66,7 @@ class UF2Writer(object):
md5_part = self._to_uint32(addr)
md5_part += self._to_uint32(len_chunk)
md5_part += hashlib.md5(chunk).digest()
assert(len(md5_part) == self.UF2_MD5_PART_SIZE)
assert len(md5_part) == self.UF2_MD5_PART_SIZE
block += md5_part
block += b'\x00' * (self.UF2_DATA_SIZE - self.UF2_MD5_PART_SIZE - len_chunk)

Wyświetl plik

@ -31,7 +31,7 @@ def set_server_cert_cn(ip):
'-CAkey', _path('ca.key'), '-CAcreateserial', '-out', _path('srv.crt'), '-days', '360']]
for args in arg_list:
if subprocess.check_call(args) != 0:
raise('openssl command {} failed'.format(args))
raise RuntimeError('openssl command {} failed'.format(args))
# Publisher class creating a python client to send/receive published data from esp-mqtt client
@ -264,7 +264,7 @@ def connection_tests(dut, cases, dut_ip):
dut.expect('MQTT_EVENT_ERROR: Test={}'.format(test_nr), timeout=30)
dut.expect('ESP-TLS ERROR: ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED') # expect ... handshake error (PEER_DID_NOT_RETURN_A_CERTIFICATE)
if 'PEER_DID_NOT_RETURN_A_CERTIFICATE' not in s.get_last_ssl_error():
raise('Unexpected ssl error from the server {}'.format(s.get_last_ssl_error()))
raise RuntimeError('Unexpected ssl error from the server {}'.format(s.get_last_ssl_error()))
for case in ['CONFIG_EXAMPLE_CONNECT_CASE_MUTUAL_AUTH', 'CONFIG_EXAMPLE_CONNECT_CASE_MUTUAL_AUTH_KEY_PWD']:
# These cases connect to server with both server and client verification (client key might be password protected)