Skip to content

Commit b3df26e

Browse files
author
Gauvain Pocentek
committed
tests: default to python 3
Fix the bytes/str issues
1 parent 34c8a03 commit b3df26e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

tools/build_test_env.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fatal() { error "$@"; exit 1; }
2626
try() { "$@" || fatal "'$@' failed"; }
2727

2828
NOVENV=
29-
PY_VER=2
29+
PY_VER=3
3030
API_VER=4
3131
while getopts :np:a: opt "$@"; do
3232
case $opt in
@@ -41,7 +41,7 @@ done
4141

4242
case $PY_VER in
4343
2) VENV_CMD=virtualenv;;
44-
3) VENV_CMD=pyvenv;;
44+
3) VENV_CMD="python3 -m venv";;
4545
*) fatal "Wrong python version (2 or 3)";;
4646
esac
4747

@@ -53,7 +53,6 @@ esac
5353
for req in \
5454
curl \
5555
docker \
56-
"${VENV_CMD}" \
5756
;
5857
do
5958
command -v "${req}" >/dev/null 2>&1 || fatal "${req} is required"
@@ -96,7 +95,7 @@ testcase() {
9695

9796
if [ -z "$NOVENV" ]; then
9897
log "Creating Python virtualenv..."
99-
try "$VENV_CMD" "$VENV"
98+
try $VENV_CMD "$VENV"
10099
. "$VENV"/bin/activate || fatal "failed to activate Python virtual environment"
101100

102101
log "Installing dependencies into virtualenv..."

tools/python_test_v4.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@
364364
'content': 'Initial content',
365365
'commit_message': 'Initial commit'})
366366
readme = admin_project.files.get(file_path='README', ref='master')
367-
readme.content = base64.b64encode(b"Improved README")
367+
readme.content = base64.b64encode(b"Improved README").decode()
368368
time.sleep(2)
369369
readme.save(branch="master", commit_message="new commit")
370370
readme.delete(commit_message="Removing README", branch="master")
@@ -374,7 +374,9 @@
374374
'content': 'Initial content',
375375
'commit_message': 'New commit'})
376376
readme = admin_project.files.get(file_path='README.rst', ref='master')
377-
assert(readme.decode() == 'Initial content')
377+
# The first decode() is the ProjectFile method, the second one is the bytes
378+
# object method
379+
assert(readme.decode().decode() == 'Initial content')
378380

379381
data = {
380382
'branch': 'master',
@@ -425,7 +427,7 @@
425427
assert(tree[0]['name'] == 'README.rst')
426428
blob_id = tree[0]['id']
427429
blob = admin_project.repository_raw_blob(blob_id)
428-
assert(blob == 'Initial content')
430+
assert(blob.decode() == 'Initial content')
429431
archive1 = admin_project.repository_archive()
430432
archive2 = admin_project.repository_archive('master')
431433
assert(archive1 == archive2)
@@ -579,7 +581,7 @@
579581
snippet.file_name = 'bar.py'
580582
snippet.save()
581583
snippet = admin_project.snippets.get(snippet.id)
582-
assert(snippet.content() == 'initial content')
584+
assert(snippet.content().decode() == 'initial content')
583585
assert(snippet.file_name == 'bar.py')
584586
size = len(admin_project.snippets.list())
585587
snippet.delete()
@@ -741,7 +743,7 @@
741743
snippet = gl.snippets.get(snippet.id)
742744
assert(snippet.title == 'updated_title')
743745
content = snippet.content()
744-
assert(content == 'import gitlab')
746+
assert(content.decode() == 'import gitlab')
745747

746748
assert(snippet.user_agent_detail()['user_agent'])
747749

@@ -775,7 +777,7 @@
775777
except gitlab.GitlabCreateError as e:
776778
error_message = e.error_message
777779
break
778-
assert 'Retry later' in error_message
780+
assert 'Retry later' in error_message.decode()
779781
[current_project.delete() for current_project in projects]
780782
settings.throttle_authenticated_api_enabled = False
781783
settings.save()

0 commit comments

Comments
 (0)