Permalink
Browse files

linting: do not use len() to determine if a sequence is empty

Instead of comparing the length to 0, rely on the fact that empty sequences
are False.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
  • Loading branch information...
BastianStender committed May 25, 2018
1 parent 6170ba0 commit fec552f3ef37a392bbd12db6f8fdab7480c943ca
@@ -1,11 +1,11 @@
def test_barebox(command):
stdout, stderr, returncode = command.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'barebox' in '\n'.join(stdout)
stdout, stderr, returncode = command.run('false')
assert returncode == 1
assert len(stdout) == 0
assert len(stderr) == 0
assert not stdout
assert not stderr
@@ -1,10 +1,11 @@
import pytest
def test_bootchooser(command):
stdout, stderr, returncode = command.run('bootchooser -i')
if returncode == 127:
pytest.skip("bootchooser command not available")
assert returncode == 0
assert len(stderr) == 0
assert not stderr
assert stdout[0].startswith('Good targets')
assert stdout[1] != 'none'
@@ -9,15 +9,15 @@ def test_sleep(command):
stdout, stderr, returncode = command.run('true')
elapsed_true = monotonic() - timestamp
assert returncode == 0
assert len(stdout) == 0
assert len(stderr) == 0
assert not stdout
assert not stderr
timestamp = monotonic()
stdout, stderr, returncode = command.run('sleep 1')
elapsed_sleep = monotonic() - timestamp
assert returncode == 0
assert len(stdout) == 0
assert len(stderr) == 0
assert not stdout
assert not stderr
assert elapsed_true < elapsed_sleep
@@ -6,6 +6,6 @@ def test_state(command):
if returncode == 127:
pytest.skip("state command not available")
assert returncode == 0
assert len(stderr) == 0
assert not stderr
assert stdout[0] == 'registered state instances:'
assert len(stdout) > 1
@@ -6,8 +6,8 @@ def test_watchdog(command):
if returncode == 127:
pytest.skip("wd command not available")
assert returncode == 0
assert len(stderr) == 0
assert len(stdout) == 0
assert not stderr
assert not stdout
command._await_prompt()
@@ -4,11 +4,11 @@ def test_target(target):
stdout, stderr, returncode = barebox.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'barebox' in '\n'.join(stdout)
stdout, stderr, returncode = barebox.run('false')
assert returncode == 1
assert len(stdout) == 0
assert len(stderr) == 0
assert not stdout
assert not stderr
@@ -1,11 +1,11 @@
def test_shell(command):
stdout, stderr, returncode = command.run('cat /proc/version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'Linux' in stdout[0]
stdout, stderr, returncode = command.run('false')
assert returncode != 0
assert len(stdout) == 0
assert len(stderr) == 0
assert not stdout
assert not stderr
@@ -28,8 +28,8 @@ def test_barebox(target, in_bootloader):
stdout, stderr, returncode = command.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'barebox' in '\n'.join(stdout)
@@ -38,8 +38,8 @@ def test_shell(target, in_shell):
command = target['ShellDriver']
stdout, stderr, returncode = command.run('cat /proc/version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'Linux' in stdout[0]
@@ -27,8 +27,8 @@ def test_uboot(target, in_bootloader):
stdout, stderr, returncode = command.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'U-Boot' in '\n'.join(stdout)
@@ -37,8 +37,8 @@ def test_shell(target, in_shell):
command = target.get_driver('ShellDriver')
stdout, stderr, returncode = command.run('cat /proc/version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'Linux' in stdout[0]
@@ -47,6 +47,6 @@ def test_uboot_2(target, in_bootloader):
stdout, stderr, returncode = command.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'U-Boot' in '\n'.join(stdout)
@@ -28,16 +28,16 @@ def shell(target, strategy, capsys):
def test_barebox(bootloader):
stdout, stderr, returncode = bootloader.run('version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'barebox' in '\n'.join(stdout)
def test_shell(shell):
stdout, stderr, returncode = shell.run('cat /proc/version')
assert returncode == 0
assert len(stdout) > 0
assert len(stderr) == 0
assert stdout
assert not stderr
assert 'Linux' in stdout[0]
View
@@ -119,7 +119,7 @@ def get_resource(self, cls, *, name=None, await=True):
other_names.append(res.name)
continue
found.append(res)
if len(found) == 0:
if not found:
if other_names:
raise NoResourceFoundError(
"all resources matching {} found in target {} have other names: {}".format(
@@ -154,7 +154,7 @@ def _get_driver(self, cls, *, name=None, activate=True, active=False):
if active and drv.state != BindingState.active:
continue
found.append(drv)
if len(found) == 0:
if not found:
if other_names:
raise NoDriverFoundError(
"all {}drivers matching {} found in target {} have other names: {}".format(
View
@@ -30,7 +30,7 @@ class A:
with pytest.warns(None) as record:
d_filtered = filter_dict(d_orig, A)
assert len(record) == 0
assert not record
assert d_filtered is not d_orig
assert d_filtered == {'foo': 1}

0 comments on commit fec552f

Please sign in to comment.