Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
ruff ruff ruff!

Signed-off-by: Milas Bowman <[email protected]>
  • Loading branch information
milas committed Nov 20, 2023
1 parent c9e3efd commit 26e0725
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 104 deletions.
2 changes: 1 addition & 1 deletion tests/integration/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_run_with_networking_config_with_undeclared_network(self):
),
}

with pytest.raises(docker.errors.APIError) as e:
with pytest.raises(docker.errors.APIError):
container = client.containers.run(
'alpine', 'echo hello world', network=net_name,
networking_config=networking_config,
Expand Down
213 changes: 110 additions & 103 deletions tests/unit/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,96 +41,92 @@ def test_create_container_args(self):
)
}

create_kwargs = _create_container_args(dict(
image='alpine',
command='echo hello world',
blkio_weight_device=[{'Path': 'foo', 'Weight': 3}],
blkio_weight=2,
cap_add=['foo'],
cap_drop=['bar'],
cgroup_parent='foobar',
cgroupns='host',
cpu_period=1,
cpu_quota=2,
cpu_shares=5,
cpuset_cpus='0-3',
detach=False,
device_read_bps=[{'Path': 'foo', 'Rate': 3}],
device_read_iops=[{'Path': 'foo', 'Rate': 3}],
device_write_bps=[{'Path': 'foo', 'Rate': 3}],
device_write_iops=[{'Path': 'foo', 'Rate': 3}],
devices=['/dev/sda:/dev/xvda:rwm'],
dns=['8.8.8.8'],
domainname='example.com',
dns_opt=['foo'],
dns_search=['example.com'],
entrypoint='/bin/sh',
environment={'FOO': 'BAR'},
extra_hosts={'foo': '1.2.3.4'},
group_add=['blah'],
ipc_mode='foo',
kernel_memory=123,
labels={'key': 'value'},
links={'foo': 'bar'},
log_config={'Type': 'json-file', 'Config': {}},
lxc_conf={'foo': 'bar'},
healthcheck={'test': 'true'},
hostname='somehost',
mac_address='abc123',
mem_limit=123,
mem_reservation=123,
mem_swappiness=2,
memswap_limit=456,
name='somename',
network_disabled=False,
network='foo',
networking_config=networking_config,
oom_kill_disable=True,
oom_score_adj=5,
pid_mode='host',
pids_limit=500,
platform='linux',
ports={
1111: 4567,
2222: None
},
privileged=True,
publish_all_ports=True,
read_only=True,
restart_policy={'Name': 'always'},
security_opt=['blah'],
shm_size=123,
stdin_open=True,
stop_signal=9,
sysctls={'foo': 'bar'},
tmpfs={'/blah': ''},
tty=True,
ulimits=[{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
user='bob',
userns_mode='host',
uts_mode='host',
version=DEFAULT_DOCKER_API_VERSION,
volume_driver='some_driver',
volumes=[
create_kwargs = _create_container_args({
'image': 'alpine',
'command': 'echo hello world',
'blkio_weight_device': [{'Path': 'foo', 'Weight': 3}],
'blkio_weight': 2,
'cap_add': ['foo'],
'cap_drop': ['bar'],
'cgroup_parent': 'foobar',
'cgroupns': 'host',
'cpu_period': 1,
'cpu_quota': 2,
'cpu_shares': 5,
'cpuset_cpus': '0-3',
'detach': False,
'device_read_bps': [{'Path': 'foo', 'Rate': 3}],
'device_read_iops': [{'Path': 'foo', 'Rate': 3}],
'device_write_bps': [{'Path': 'foo', 'Rate': 3}],
'device_write_iops': [{'Path': 'foo', 'Rate': 3}],
'devices': ['/dev/sda:/dev/xvda:rwm'],
'dns': ['8.8.8.8'],
'domainname': 'example.com',
'dns_opt': ['foo'],
'dns_search': ['example.com'],
'entrypoint': '/bin/sh',
'environment': {'FOO': 'BAR'},
'extra_hosts': {'foo': '1.2.3.4'},
'group_add': ['blah'],
'ipc_mode': 'foo',
'kernel_memory': 123,
'labels': {'key': 'value'},
'links': {'foo': 'bar'},
'log_config': {'Type': 'json-file', 'Config': {}},
'lxc_conf': {'foo': 'bar'},
'healthcheck': {'test': 'true'},
'hostname': 'somehost',
'mac_address': 'abc123',
'mem_limit': 123,
'mem_reservation': 123,
'mem_swappiness': 2,
'memswap_limit': 456,
'name': 'somename',
'network_disabled': False,
'network': 'foo',
'networking_config': networking_config,
'oom_kill_disable': True,
'oom_score_adj': 5,
'pid_mode': 'host',
'pids_limit': 500,
'platform': 'linux',
'ports': {1111: 4567, 2222: None},
'privileged': True,
'publish_all_ports': True,
'read_only': True,
'restart_policy': {'Name': 'always'},
'security_opt': ['blah'],
'shm_size': 123,
'stdin_open': True,
'stop_signal': 9,
'sysctls': {'foo': 'bar'},
'tmpfs': {'/blah': ''},
'tty': True,
'ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
'user': 'bob',
'userns_mode': 'host',
'uts_mode': 'host',
'version': DEFAULT_DOCKER_API_VERSION,
'volume_driver': 'some_driver', 'volumes': [
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
'volumename:/mnt/vol3r',
'/volumewithnohostpath',
'/anothervolumewithnohostpath:ro',
'C:\\windows\\path:D:\\hello\\world:rw'
],
volumes_from=['container'],
working_dir='/code'
))
'volumes_from': ['container'],
'working_dir': '/code',
})

expected = dict(
image='alpine',
command='echo hello world',
domainname='example.com',
detach=False,
entrypoint='/bin/sh',
environment={'FOO': 'BAR'},
host_config={
expected = {
'image': 'alpine',
'command': 'echo hello world',
'domainname': 'example.com',
'detach': False,
'entrypoint': '/bin/sh',
'environment': {'FOO': 'BAR'},
'host_config': {
'Binds': [
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
Expand All @@ -153,9 +149,13 @@ def test_create_container_args(self):
'CpuQuota': 2,
'CpuShares': 5,
'CpusetCpus': '0-3',
'Devices': [{'PathOnHost': '/dev/sda',
'CgroupPermissions': 'rwm',
'PathInContainer': '/dev/xvda'}],
'Devices': [
{
'PathOnHost': '/dev/sda',
'CgroupPermissions': 'rwm',
'PathInContainer': '/dev/xvda',
},
],
'Dns': ['8.8.8.8'],
'DnsOptions': ['foo'],
'DnsSearch': ['example.com'],
Expand Down Expand Up @@ -187,37 +187,44 @@ def test_create_container_args(self):
'ShmSize': 123,
'Sysctls': {'foo': 'bar'},
'Tmpfs': {'/blah': ''},
'Ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
'Ulimits': [
{"Name": "nofile", "Soft": 1024, "Hard": 2048},
],
'UsernsMode': 'host',
'UTSMode': 'host',
'VolumeDriver': 'some_driver',
'VolumesFrom': ['container'],
},
healthcheck={'test': 'true'},
hostname='somehost',
labels={'key': 'value'},
mac_address='abc123',
name='somename',
network_disabled=False,
networking_config={'EndpointsConfig': {
'foo': {'Aliases': ['test'], 'DriverOpts': {'key1': 'a'}}}
'healthcheck': {'test': 'true'},
'hostname': 'somehost',
'labels': {'key': 'value'},
'mac_address': 'abc123',
'name': 'somename',
'network_disabled': False,
'networking_config': {
'EndpointsConfig': {
'foo': {
'Aliases': ['test'],
'DriverOpts': {'key1': 'a'},
},
}
},
platform='linux',
ports=[('1111', 'tcp'), ('2222', 'tcp')],
stdin_open=True,
stop_signal=9,
tty=True,
user='bob',
volumes=[
'platform': 'linux',
'ports': [('1111', 'tcp'), ('2222', 'tcp')],
'stdin_open': True,
'stop_signal': 9,
'tty': True,
'user': 'bob',
'volumes': [
'/mnt/vol2',
'/mnt/vol1',
'/mnt/vol3r',
'/volumewithnohostpath',
'/anothervolumewithnohostpath',
'D:\\hello\\world'
],
working_dir='/code'
)
'working_dir': '/code',
}

assert create_kwargs == expected

Expand Down

0 comments on commit 26e0725

Please sign in to comment.