1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

use py3 instead py2 (#3153)

* use py3 instead py2

Signed-off-by: jnozsc <jnozsc@gmail.com>

* use python 3.6

Signed-off-by: jnozsc <jnozsc@gmail.com>
This commit is contained in:
jnozsc 2020-03-02 23:30:44 -08:00 committed by GitHub
parent 027b97cbfa
commit 4a711340ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 20 deletions

View File

@ -3,7 +3,7 @@ services:
- docker - docker
language: python language: python
python: python:
- "2.7" - "3.6"
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt

View File

@ -14,9 +14,9 @@ SETUPVARS = {
'PIHOLE_DNS_2': '4.2.2.2' 'PIHOLE_DNS_2': '4.2.2.2'
} }
tick_box = "[\x1b[1;32m\xe2\x9c\x93\x1b[0m]".decode("utf-8") tick_box = "[\x1b[1;32m\u2713\x1b[0m]"
cross_box = "[\x1b[1;31m\xe2\x9c\x97\x1b[0m]".decode("utf-8") cross_box = "[\x1b[1;31m\u2717\x1b[0m]"
info_box = "[i]".decode("utf-8") info_box = "[i]"
@pytest.fixture @pytest.fixture
@ -38,9 +38,7 @@ def Pihole(Docker):
return out return out
funcType = type(Docker.run) funcType = type(Docker.run)
Docker.run = funcType(run_bash, Docker.run = funcType(run_bash, Docker)
Docker,
testinfra.backend.docker.DockerBackend)
return Docker return Docker
@ -106,7 +104,7 @@ def mock_command(script, args, container):
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1" in'''.format(script=script)) case "\$1" in'''.format(script=script))
for k, v in args.iteritems(): for k, v in args.items():
case = dedent(''' case = dedent('''
{arg}) {arg})
echo {res} echo {res}
@ -133,7 +131,7 @@ def mock_command_2(script, args, container):
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1 \$2" in'''.format(script=script)) case "\$1 \$2" in'''.format(script=script))
for k, v in args.iteritems(): for k, v in args.items():
case = dedent(''' case = dedent('''
\"{arg}\") \"{arg}\")
echo \"{res}\" echo \"{res}\"

View File

@ -18,6 +18,6 @@ run_local = testinfra.get_backend(
def test_build_pihole_image(image, tag): def test_build_pihole_image(image, tag):
build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag)) build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag))
if build_cmd.rc != 0: if build_cmd.rc != 0:
print build_cmd.stdout print(build_cmd.stdout)
print build_cmd.stderr print(build_cmd.stderr)
assert build_cmd.rc == 0 assert build_cmd.rc == 0

View File

@ -1,6 +1,6 @@
from textwrap import dedent from textwrap import dedent
import re import re
from conftest import ( from .conftest import (
SETUPVARS, SETUPVARS,
tick_box, tick_box,
info_box, info_box,
@ -34,7 +34,7 @@ def test_setupVars_are_sourced_to_global_scope(Pihole):
This confirms the sourced variables are in scope between functions This confirms the sourced variables are in scope between functions
''' '''
setup_var_file = 'cat <<EOF> /etc/pihole/setupVars.conf\n' setup_var_file = 'cat <<EOF> /etc/pihole/setupVars.conf\n'
for k, v in SETUPVARS.iteritems(): for k, v in SETUPVARS.items():
setup_var_file += "{}={}\n".format(k, v) setup_var_file += "{}={}\n".format(k, v)
setup_var_file += "EOF\n" setup_var_file += "EOF\n"
Pihole.run(setup_var_file) Pihole.run(setup_var_file)
@ -59,7 +59,7 @@ def test_setupVars_are_sourced_to_global_scope(Pihole):
output = run_script(Pihole, script).stdout output = run_script(Pihole, script).stdout
for k, v in SETUPVARS.iteritems(): for k, v in SETUPVARS.items():
assert "{}={}".format(k, v) in output assert "{}={}".format(k, v) in output
@ -69,7 +69,7 @@ def test_setupVars_saved_to_file(Pihole):
''' '''
# dedent works better with this and padding matching script below # dedent works better with this and padding matching script below
set_setup_vars = '\n' set_setup_vars = '\n'
for k, v in SETUPVARS.iteritems(): for k, v in SETUPVARS.items():
set_setup_vars += " {}={}\n".format(k, v) set_setup_vars += " {}={}\n".format(k, v)
Pihole.run(set_setup_vars).stdout Pihole.run(set_setup_vars).stdout
@ -88,7 +88,7 @@ def test_setupVars_saved_to_file(Pihole):
output = run_script(Pihole, script).stdout output = run_script(Pihole, script).stdout
for k, v in SETUPVARS.iteritems(): for k, v in SETUPVARS.items():
assert "{}={}".format(k, v) in output assert "{}={}".format(k, v) in output

View File

@ -1,10 +1,9 @@
import pytest import pytest
from conftest import ( from .conftest import (
tick_box, tick_box,
info_box, info_box,
cross_box, cross_box,
mock_command, mock_command,
mock_command_2,
) )

View File

@ -14,5 +14,5 @@ def test_scripts_pass_shellcheck():
"shellcheck -x \"$file\" -e SC1090,SC1091; " "shellcheck -x \"$file\" -e SC1090,SC1091; "
"done;") "done;")
results = run_local(shellcheck) results = run_local(shellcheck)
print results.stdout print(results.stdout)
assert '' == results.stdout assert '' == results.stdout

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py27 envlist = py36
[testenv] [testenv]
whitelist_externals = docker whitelist_externals = docker