Skip to content

Commit 8c8f496

Browse files
committed
manual ruff fixes
ruff can detect but not fix these. Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent 1f495cb commit 8c8f496

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

doc/templates/gen.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#! /usr/bin/env python
2+
import sys
3+
import os
4+
import re
5+
import time
6+
27
# ----------------------------------------------------------------------
38
# Settings
49
vardir = "."
@@ -28,11 +33,6 @@ def last_modified(text):
2833

2934
# ----------------------------------------------------------------------
3035
# main
31-
import sys
32-
import os
33-
import re
34-
import time
35-
3636
# Check command line arguments
3737
if len(sys.argv) == 1:
3838
usage()
@@ -44,7 +44,8 @@ def last_modified(text):
4444
# Get a list of all variables (files in the form __*__) from vardir
4545
vars = os.listdir(vardir)
4646
for i in range(len(vars)-1, -1, -1):
47-
if re.match("^__.*__$", vars[i]): continue
47+
if re.match("^__.*__$", vars[i]):
48+
continue
4849
del vars[i]
4950
vars.sort()
5051

tests/bash_tests/testcases.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import re
33
import unittest
44

5+
from importlib.util import find_spec
56
from system_tests import BT
67

7-
88
class TestCases(unittest.TestCase):
99

1010

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

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

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

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

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

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

@@ -1013,9 +1013,7 @@ def preview_test(self):
10131013
def stdin_test(self):
10141014
return # temporarily disable
10151015
# Test driver for stdin
1016-
try:
1017-
import lxml
1018-
except ModuleNotFoundError:
1016+
if find_spec('lxml') is None:
10191017
print('Skipped. Because it misses module lxml. Please install: `pip install lxml`')
10201018
return
10211019

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

13361334
xmp = 'xmpsdk.xmp'
1337-
BT.save(BT.Executer('xmpparse {xmp}' , vars()).stdout, 't1')
1338-
BT.save(BT.Executer('xmpparse {xmp}-new', vars()).stdout, 't2')
1335+
BT.save(BT.Executer('xmpparse {}'.format(xmp), vars()).stdout, 't1')
1336+
BT.save(BT.Executer('xmpparse {}-new'.format(xmp), vars()).stdout, 't2')
13391337
out += BT.diff('t1', 't2')
13401338

13411339
out += BT.Executer('xmpsample')

tests/bash_tests/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ def start(self):
364364
with request.urlopen('http://127.0.0.1:{}'.format(self.port), timeout=3) as f:
365365
if f.status != 200:
366366
raise RuntimeError()
367-
except:
368-
raise RuntimeError('Failed to run the HTTP server')
367+
except Exception as e:
368+
raise RuntimeError('Failed to run the HTTP server: {}'.format(e))
369369
log.info('The HTTP server started')
370370

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

@@ -556,7 +556,7 @@ def __str__(self):
556556
def __add__(self, other):
557557
if isinstance(other, Executer):
558558
other = other.stdout
559-
if other != None:
559+
if other is not None:
560560
self.lines.append(str(other))
561561
return self
562562

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

611611

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

620620

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

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

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

749749
return out
750750

tests/lens_tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def make_test_cases(lenses):
152152
**lens["meta"],
153153
"id": lens["id"],
154154
"desc": lens["desc"],
155-
"target": " *OR* ".join([l["desc"] for l in lens_group if lens_is_match(lens["meta"], l["meta"])]),
155+
"target": " *OR* ".join([lg["desc"] for lg in lens_group if lens_is_match(lens["meta"], lg["meta"])]),
156156
}
157157
for lens in lens_group
158158
]

tests/system_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def _encode(self, data_in, encode_action, get_err):
724724
"""
725725
result = None
726726
for encoding in self.encodings:
727-
if encoding == bytes:
727+
if encoding is bytes:
728728
return data_in
729729
try:
730730
result = encode_action(data_in, encoding)

0 commit comments

Comments
 (0)