Skip to content

Commit

Permalink
manual ruff fixes
Browse files Browse the repository at this point in the history
ruff can detect but not fix these.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Dec 5, 2024
1 parent 1f495cb commit 8c8f496
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
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
20 changes: 10 additions & 10 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 Down
2 changes: 1 addition & 1 deletion tests/lens_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def make_test_cases(lenses):
**lens["meta"],
"id": lens["id"],
"desc": lens["desc"],
"target": " *OR* ".join([l["desc"] for l in lens_group if lens_is_match(lens["meta"], l["meta"])]),
"target": " *OR* ".join([lg["desc"] for lg in lens_group if lens_is_match(lens["meta"], lg["meta"])]),
}
for lens in lens_group
]
Expand Down
2 changes: 1 addition & 1 deletion tests/system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def _encode(self, data_in, encode_action, get_err):
"""
result = None
for encoding in self.encodings:
if encoding == bytes:
if encoding is bytes:
return data_in
try:
result = encode_action(data_in, encoding)
Expand Down

0 comments on commit 8c8f496

Please sign in to comment.