From dcbc93a117b0efaa0e42fa6359eed4a71a9ca341 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 10 Jun 2022 02:04:30 +0300 Subject: tests: Convert to formatted string literals Use formatted string literals to replace legacy printf-style string formatting. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- tests/kmstest.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tests/kmstest.py') diff --git a/tests/kmstest.py b/tests/kmstest.py index 708e699..14e28cd 100755 --- a/tests/kmstest.py +++ b/tests/kmstest.py @@ -113,7 +113,7 @@ class KernelLogReader(object): class Logger(object): def __init__(self, name): - self.logfile = open('%s.log' % name, 'w') + self.logfile = open(f'{name}.log', 'w') self._kmsg = KernelLogReader() def __del__(self): @@ -129,7 +129,7 @@ class Logger(object): def event(self): kmsgs = self._kmsg.read() for msg in kmsgs: - self.logfile.write('K [%6f] %s\n' % (msg.timestamp, msg.msg)) + self.logfile.write(f'K [{msg.timestamp:6f} {msg.msg}\n') self.logfile.flush() @property @@ -146,7 +146,7 @@ class Logger(object): self.event() now = time.clock_gettime(time.CLOCK_MONOTONIC) - self.logfile.write('U [%6f] %s\n' % (now, msg)) + self.logfile.write(f'U [{now:6f}] {msg}\n') self.logfile.flush() @@ -171,7 +171,7 @@ class CRCReader(object): # Hardcode the device minor to 0 as the KMSTest constructor opens the # default card object. - self.dir = os.open('/sys/kernel/debug/dri/0/crtc-%u/crc' % self.pipe, 0) + self.dir = os.open('f/sys/kernel/debug/dri/0/crtc-{self.pipe}/crc', 0) self.ctrl = os.open('control', os.O_WRONLY, dir_fd = self.dir) self.data = -1 @@ -211,7 +211,7 @@ class Dist(object): self.y = y def __repr__(self): - return '(%d,%d)' % (self.x, self.y) + return f'({self.x},{self.y})' class Point(object): @@ -220,7 +220,7 @@ class Point(object): self.y = y def __repr__(self): - return '(%d,%d)' % (self.x, self.y) + return f'({self.x},{self.y})' def move(self, distance): self.x += distance.x @@ -233,7 +233,7 @@ class Size(object): self.height = height def __repr__(self): - return '%ux%u' % (self.width, self.height) + return f'{self.width}x{self.height}' class Rect(object): @@ -244,7 +244,7 @@ class Rect(object): self.height = height def __repr__(self): - return '(%d,%d)/%ux%u' % (self.left, self.top, self.width, self.height) + return f'({self.left},{self.top})/{self.width}x{self.height}' def isEmpty(self): """Check if the rectangle has a zero width or height""" @@ -462,24 +462,24 @@ class KMSTest(object): def start(self, name): """Start a test.""" self.test_name = name - self.logger.log('Testing %s' % name) - sys.stdout.write('Testing %s: ' % name) + self.logger.log(f'Testing {name}') + sys.stdout.write(f'Testing {name}: ') sys.stdout.flush() def progress(self, current, maximum): - sys.stdout.write('\rTesting %s: %u/%u' % (self.test_name, current, maximum)) + sys.stdout.write(f'\rTesting {self.test_name}: {current}/{maximum}') sys.stdout.flush() def fail(self, reason): """Complete a test with failure.""" - self.logger.log('Test failed. Reason: %s' % reason) + self.logger.log(f'Test failed. Reason: {reason}') self.logger.flush() - sys.stdout.write('\rTesting %s: FAIL\n' % self.test_name) + sys.stdout.write(f'\rTesting {self.test_name}: FAIL\n') sys.stdout.flush() def skip(self, reason): """Complete a test with skip.""" - self.logger.log('Test skipped. Reason: %s' % reason) + self.logger.log(f'Test skipped. Reason: {reason}') self.logger.flush() sys.stdout.write('SKIP\n') sys.stdout.flush() @@ -488,6 +488,6 @@ class KMSTest(object): """Complete a test with success.""" self.logger.log('Test completed successfully') self.logger.flush() - sys.stdout.write('\rTesting %s: SUCCESS\n' % self.test_name) + sys.stdout.write(f'\rTesting {self.test_name}: SUCCESS\n') sys.stdout.flush() -- cgit v1.2.3