Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff python fixes #3082

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from conans import ConanFile
from conans.tools import os_info
from conans.model.version import Version

class Exiv2Conan(ConanFile):
settings = 'os', 'compiler', 'build_type', 'arch'
Expand Down
13 changes: 7 additions & 6 deletions doc/templates/gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#! /usr/bin/env python
import sys
import os
import re
import time

# ----------------------------------------------------------------------
# Settings
vardir = "."
Expand Down Expand Up @@ -28,11 +33,6 @@ def last_modified(text):

# ----------------------------------------------------------------------
# main
import sys
import os
import re
import time

# Check command line arguments
if len(sys.argv) == 1:
usage()
Expand All @@ -44,7 +44,8 @@ def last_modified(text):
# Get a list of all variables (files in the form __*__) from vardir
vars = os.listdir(vardir)
for i in range(len(vars)-1, -1, -1):
if re.match("^__.*__$", vars[i]): continue
if re.match("^__.*__$", vars[i]):
continue
del vars[i]
vars.sort()

Expand Down
26 changes: 12 additions & 14 deletions tests/bash_tests/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import re
import unittest

from importlib.util import find_spec
from system_tests import BT


class TestCases(unittest.TestCase):


Expand Down Expand Up @@ -368,25 +368,25 @@ def exiv2_test(self):
out += BT.Executer('exiv2 -u -h')

out += '\n\nAdjust -------------------------------------------------------------------'
out += BT.Executer('exiv2 -u -v -a-12:01:01 adjust {images_1_str}', vars(), assert_returncode=[253])
out += BT.Executer('exiv2 -u -v -a-12:01:01 adjust {}'.format(images_1_str), vars(), assert_returncode=[253])

out += '\nRename -------------------------------------------------------------------'
out += BT.Executer('exiv2 -u -vf rename {images_1_str}', vars(), assert_returncode=[253])
out += BT.Executer('exiv2 -u -vf rename {}'.format(images_1_str), vars(), assert_returncode=[253])

out += '\nPrint --------------------------------------------------------------------'
out += BT.Executer('exiv2 -u -v print {images_2_str}', vars(), assert_returncode=[253])
out += BT.Executer('exiv2 -u -v print {}'.format(images_2_str), vars(), assert_returncode=[253])
out += ''
out += BT.Executer('exiv2 -u -v -b -pt print {images_2_str}', vars())
e = BT.Executer('exiv2 -u -v -b -pt print {images_2_str}', vars(), redirect_stderr_to_stdout=False, decode_output=False)
out += BT.Executer('exiv2 -u -v -b -pt print {}'.format(images_2_str), vars())
e = BT.Executer('exiv2 -u -v -b -pt print {}'.format(images_2_str), vars(), redirect_stderr_to_stdout=False, decode_output=False)
BT.save(e.stdout, 'iii')
out += e.stderr.decode()

out += '\nExtract Exif data --------------------------------------------------------'
out += BT.Executer('exiv2 -u -vf extract {images_2_str}', vars())
out += BT.Executer('exiv2 -u -vf extract {}'.format(images_2_str), vars())

out += '\nExtract Thumbnail --------------------------------------------------------'
out += BT.Executer('exiv2 -u -vf -et extract {images_2_str}', vars(), assert_returncode=[253])
e = BT.Executer('exiv2 -u -v -b -pt print {images_3_str}', vars(), redirect_stderr_to_stdout=False, decode_output=False)
out += BT.Executer('exiv2 -u -vf -et extract {}'.format(images_2_str), vars(), assert_returncode=[253])
e = BT.Executer('exiv2 -u -v -b -pt print {}'.format(images_3_str), vars(), redirect_stderr_to_stdout=False, decode_output=False)
BT.save(e.stdout, 'jjj')
out += e.stderr.decode()

Expand Down Expand Up @@ -1013,9 +1013,7 @@ def preview_test(self):
def stdin_test(self):
return # temporarily disable
# Test driver for stdin
try:
import lxml
except ModuleNotFoundError:
if find_spec('lxml') is None:
print('Skipped. Because it misses module lxml. Please install: `pip install lxml`')
return

Expand Down Expand Up @@ -1334,8 +1332,8 @@ def xmpparser_test(self):
out += BT.diff(img, img + '-new')

xmp = 'xmpsdk.xmp'
BT.save(BT.Executer('xmpparse {xmp}' , vars()).stdout, 't1')
BT.save(BT.Executer('xmpparse {xmp}-new', vars()).stdout, 't2')
BT.save(BT.Executer('xmpparse {}'.format(xmp), vars()).stdout, 't1')
BT.save(BT.Executer('xmpparse {}-new'.format(xmp), vars()).stdout, 't2')
out += BT.diff('t1', 't2')

out += BT.Executer('xmpsample')
Expand Down
22 changes: 11 additions & 11 deletions tests/bash_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ def start(self):
with request.urlopen('http://127.0.0.1:{}'.format(self.port), timeout=3) as f:
if f.status != 200:
raise RuntimeError()
except:
raise RuntimeError('Failed to run the HTTP server')
except Exception as e:
raise RuntimeError('Failed to run the HTTP server: {}'.format(e))
log.info('The HTTP server started')

def stop(self):
Expand Down Expand Up @@ -504,8 +504,8 @@ def run(self):
except subprocess.TimeoutExpired:
self.subprocess.kill()
output = self.subprocess.communicate()
except:
raise RuntimeError('Failed to execute: {}'.format(self.args))
except Exception as e:
raise RuntimeError('Failed to execute {}: {}'.format(self.args, e))
output = [i or b'' for i in output]
output = [i.rstrip(b'\r\n').rstrip(b'\n') for i in output] # Remove the last line break of the output

Expand Down Expand Up @@ -556,7 +556,7 @@ def __str__(self):
def __add__(self, other):
if isinstance(other, Executer):
other = other.stdout
if other != None:
if other is not None:
self.lines.append(str(other))
return self

Expand Down Expand Up @@ -605,7 +605,7 @@ def copyTest(num, src, good):
src_file = os.path.join(Config.data_dir, src)
good_file = os.path.join(Config.data_dir, '{}.c{}gd'.format(good, num))
copyTestFile(good, test_file)
Executer('metacopy -a {src_file} {test_file}', vars())
Executer('metacopy -a {} {}'.format(src_file, test_file), vars())
return diffCheck(good_file, test_file, in_bytes=True)


Expand All @@ -614,7 +614,7 @@ def iptcTest(num, src, good):
src_file = os.path.join(Config.data_dir, src)
good_file = os.path.join(Config.data_dir, '{}.i{}gd'.format(good, num))
copyTestFile(good, test_file)
Executer('metacopy -ip {src_file} {test_file}', vars())
Executer('metacopy -ip {} {}'.format(src_file, test_file), vars())
return diffCheck(good_file, test_file, in_bytes=True)


Expand All @@ -624,7 +624,7 @@ def printTest(filename):
good_file = os.path.join(Config.data_dir, filename + '.ipgd')
copyTestFile(filename, test_file)

e = Executer('iptcprint {src_file}', vars(), assert_returncode=None, decode_output=False)
e = Executer('iptcprint {}'.format(src_file), vars(), assert_returncode=None, decode_output=False)
stdout = e.stdout.replace(Config.data_dir.replace(os.path.sep, '/').encode(), b'../data') # Ignore the difference of data_dir on Windows
save(stdout + b'\n', test_file)

Expand Down Expand Up @@ -743,8 +743,8 @@ def runTest(cmd,raw=False):
print('{} returncode = {}'.format(cmd, p.returncode))
# Split the output by newline
out = stdout.decode('utf-8').replace('\r', '').rstrip('\n').split('\n')
except:
print('** {} died **'.format(cmd))
except Exception as e:
print('** {} died: {} **'.format(cmd, e))

return out

Expand All @@ -758,7 +758,7 @@ def verbose_version(verbose=False):
kv = line.rstrip().split('=')
if len(kv) == 2:
key, val = kv
if not key in vv:
if key not in vv:
vv[key] = val
elif isinstance(vv[key], list):
vv[key].append(val)
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1097.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path


class InfiniteRecursionInCiffDirectoryReadDirectory(metaclass=CaseMeta):
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1099.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path


class EmptyValueInCommandFile(metaclass=CaseMeta):
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1805.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import unittest
import system_tests
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors

# Check that `exiv2 -pr` works for different file types.
# ExifTool has a list of markers that appear in the headers:
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1812.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path


class OutOfMemoryInJp2ImageReadMetadata(metaclass=CaseMeta):
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1819.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path

class EmptyStringXmpTextValueRead(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1827.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors

class ExposureTimeCastDoubleToLong(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1830.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors

class ValueTypeFloatToLong(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_1941.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import system_tests
from system_tests import CaseMeta, CopyTmpFiles, path
from system_tests import CaseMeta

class TestNikonFl7GroupWithFlash(metaclass=CaseMeta):

Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2339.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2339_printDegrees_integer_overflow(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2339"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2352.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2352_floatToRationalCast_integer_overflow(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2352"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2366.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2366_QuickTimeVideo_userDataDecoder_buffer_overflow(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2366"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2376.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2376_QuickTimeVideo_userDataDecoder_null_deref(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2376"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2377.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2377_QuickTimeVideo_userDataDecoder_buffer_overflow(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2377"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2383.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2383_QuickTimeVideo_userDataDecoder_null_deref(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2383"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2393.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2393_QuickTimeVideo_multipleEntriesDecoder_long_running(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2393"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2403.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, CopyTmpFiles
@CopyTmpFiles("$data_path/issue_2403_poc.exv")

class checkIconvSegFault(metaclass=CaseMeta):
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_2423.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta

class issue_2423_QuickTimeVideo_sampleDesc_long_running(metaclass=CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/2423"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_646.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path
from system_tests import CaseMeta

class Fix646_NikonAF22(metaclass=CaseMeta):

Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_841.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path


class InvalidDataLocationInCiffComponentDoRead(metaclass=CaseMeta):
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_g44w_q3vm_gwjq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
import unittest

@unittest.skip("Skipping test using option -pR (only for Debug mode)")
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_583f_w9pm_99r2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path

class Jp2ImagePrintStructureICC(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_crmj_qh74_2r36.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path

class QuickTimeVideoNikonTagsDecoderOutOfBoundsRead(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_g9xm_7538_mq8w.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors

class QuickTimeVideoNikonTagsDecoderOutOfBoundsRead(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_h9x9_4f77_336w.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors

class Jp2ImageEncodeJp2HeaderOutOfBoundsRead2(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_m479_7frc_gqqg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, path

class ImagePrintIFDStructure(metaclass=CaseMeta):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
from system_tests import CaseMeta, CopyTmpFiles, path
@CopyTmpFiles("$data_path/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2")

class Jp2ImageEncodeJp2HeaderOutOfBoundsRead2(metaclass=CaseMeta):
Expand Down
Loading
Loading