Skip to content

Commit

Permalink
Make tests pass (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio authored Feb 8, 2024
1 parent 5bc420e commit 822b289
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 76 deletions.
9 changes: 1 addition & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import os
from setuptools import setup, find_packages


about = {}
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'shub', '__init__.py'), encoding='utf-8') as f:
exec(f.read(), about)


setup(
name='shub',
version='2.15.3',
packages=find_packages(exclude=('tests', 'tests.*')),
url=about['DOCS_LINK'],
url="https://shub.readthedocs.io/en/stable/",
description='Scrapinghub Command Line Client',
long_description=open('README.rst').read(),
author='Scrapinghub',
Expand Down
11 changes: 6 additions & 5 deletions tests/image/test_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from unittest import mock

import pytest
Expand Down Expand Up @@ -91,12 +92,12 @@ def test_cli_with_progress(docker_client_mock, project_dir, test_mock):
result = runner.invoke(cli, ["dev"])
assert result.exit_code == 0
expected = format_expected_progress(
'Building registry.io/user/project:1.0.'
'Steps: 0%| | 0/1'
'Steps: 100%|██████████| 3/3'
'The image registry.io/user/project:1.0 build is completed.'
r'Building registry\.io/user/project:1\.0\.'
r'Steps: 0%\| +\| 0/1'
r'Steps: 100%\|█+\| 3/3'
r'The image registry\.io/user/project:1\.0 build is completed\.'
)
assert expected in clean_progress_output(result.output)
assert re.search(clean_progress_output(result.output), expected)


def test_cli_custom_version(docker_client_mock, project_dir, test_mock):
Expand Down
39 changes: 20 additions & 19 deletions tests/image/test_deploy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re
import time
from unittest import mock

Expand Down Expand Up @@ -165,19 +166,19 @@ def test_progress_bar_logic():
result = CliRunner().invoke(progress_cmd)
assert result.exit_code == 0
expected = format_expected_progress(
'Progress: 0%| | 0/100'
'Progress: 25%|██▌ | 25/100'
'Progress: 30%|███ | 30/100'
'Progress: 35%|███▌ | 35/100'
'Progress: 50%|█████ | 50/100'
'Progress: 55%|█████▌ | 55/100'
'Progress: 65%|██████▌ | 65/100'
'Progress: 75%|███████▌ | 75/100'
'Progress: 100%|██████████| 100/100'
'Progress: 100%|██████████| 100/100'
'Deploy results:'
r'Progress: 0%\|[^|]+\| 0/100'
r'Progress: 25%\|[^|]+\| 25/100'
r'Progress: 30%\|[^|]+\| 30/100'
r'Progress: 35%\|[^|]+\| 35/100'
r'Progress: 50%\|[^|]+\| 50/100'
r'Progress: 55%\|[^|]+\| 55/100'
r'Progress: 65%\|[^|]+\| 65/100'
r'Progress: 75%\|[^|]+\| 75/100'
r'Progress: 100%\|[^|]+\| 100/100'
r'Progress: 100%\|[^|]+\| 100/100'
r'Deploy results:'
)
assert expected in clean_progress_output(result.output)
assert re.search(expected, clean_progress_output(result.output))
lines = result.output.split('\n')
# test that output ends with a newline symbol
assert lines[-1] == ''
Expand All @@ -192,14 +193,14 @@ def test_progress_bar_logic_incomplete():
result = CliRunner().invoke(progress_cmd)
assert result.exit_code == 0
expected = format_expected_progress(
'Progress: 0%| | 0/100'
'Progress: 25%|██▌ | 25/100'
'Progress: 30%|███ | 30/100'
'Progress: 100%|██████████| 100/100'
'Progress: 100%|██████████| 100/100'
'Deploy results:'
r'Progress: 0%|[^|]+| 0/100'
r'Progress: 25%|[^|]+| 25/100'
r'Progress: 30%|[^|]+| 30/100'
r'Progress: 100%|[^|]+| 100/100'
r'Progress: 100%|[^|]+| 100/100'
r'Deploy results:'
)
assert expected in clean_progress_output(result.output)
assert re.search(expected, clean_progress_output(result.output))
# test that the command succeeded
lines = result.output.split('\n')
# test that output ends with a newline symbol
Expand Down
79 changes: 40 additions & 39 deletions tests/image/test_push.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from unittest import mock

import pytest
Expand Down Expand Up @@ -53,25 +54,25 @@ def test_cli_with_progress(docker_client_mock):
result = runner.invoke(cli, ["dev", "--version", "test"])
assert result.exit_code == 0
expected = format_expected_progress(
'Login to registry.io succeeded.'
'Pushing registry.io/user/project:test to the registry.'
'Layers: 0%| | 0/1'
'Layers: 0%| | 0/1'
'Layers: 0%| | 0/2'
'Layers: 0%| | 0/3'
'Layers: 0%| | 0/3'
'Layers: 0%| | 0/3'
'abc: 2%|▏ | 512/24.8k [1.00MB/s]'
'Layers: 0%| | 0/3'
'egh: 100%|██████████| 57.3k/57.3k [1.00MB/s]'
'Layers: 33%|███▎ | 1/3'
'Layers: 67%|██████▋ | 2/3'
'Layers: 100%|██████████| 3/3'
'abc: 100%|██████████| 24.8k/24.8k [1.00MB/s]'
'egh: 100%|██████████| 57.3k/57.3k [1.00MB/s]'
'The image registry.io/user/project:test pushed successfully.'
r'Login to registry\.io succeeded\.'
r'Pushing registry\.io/user/project:test to the registry\.'
r'Layers: 0%\|[^|]+\| 0/1'
r'Layers: 0%\|[^|]+\| 0/1'
r'Layers: 0%\|[^|]+\| 0/2'
r'Layers: 0%\|[^|]+\| 0/3'
r'Layers: 0%\|[^|]+\| 0/3'
r'Layers: 0%\|[^|]+\| 0/3'
r'abc: 2%\|[^|]+\| 512/24\.8k \[1\.00MB/s\]'
r'Layers: 0%\|[^|]+\| 0/3'
r'egh: 100%\|[^|]+\| 57\.3k/57\.3k \[1\.00MB/s\]'
r'Layers: 33%\|[^|]+\| 1/3'
r'Layers: 67%\|[^|]+\| 2/3'
r'Layers: 100%\|[^|]+\| 3/3'
r'abc: 100%\|[^|]+\| 24\.8k/24\.8k \[1\.00MB/s\]'
r'egh: 100%\|[^|]+\| 57\.3k/57\.3k \[1\.00MB/s\]'
r'The image registry\.io/user/project:test pushed successfully\.'
)
assert expected in clean_progress_output(result.output)
assert re.search(expected, clean_progress_output(result.output))


@pytest.mark.usefixtures('project_dir', 'test_mock', 'monkeypatch_bar_rate')
Expand Down Expand Up @@ -100,28 +101,28 @@ def test_progress_no_total(docker_client_mock):
result = runner.invoke(cli, ["dev", "--version", "test"])
assert result.exit_code == 0
expected = format_expected_progress(
'Login to registry.io succeeded.'
'Pushing registry.io/user/project:test to the registry.'
'Layers: 0%| | 0/1'
'Layers: 0%| | 0/1'
'Layers: 0%| | 0/2'
'Layers: 0%| | 0/3'
'Layers: 0%| | 0/4'
'Layers: 0%| | 0/4'
'Layers: 0%| | 0/4'
'Layers: 0%| | 0/4'
'abc: 100%|██████████| 512/512 [1.00MB/s]'
'Layers: 0%| | 0/4'
'egh: 100%|██████████| 57.3k/57.3k [1.00MB/s]'
'Layers: 25%|██▌ | 1/4'
'Layers: 50%|█████ | 2/4'
'Layers: 75%|███████▌ | 3/4'
'Layers: 100%|██████████| 4/4'
'abc: 100%|██████████| 24.8k/24.8k [1.00MB/s]'
'egh: 100%|██████████| 57.3k/57.3k [1.00MB/s]'
'The image registry.io/user/project:test pushed successfully.'
r'Login to registry\.io succeeded\.'
r'Pushing registry\.io/user/project:test to the registry\.'
r'Layers: 0%\|[^|]+\| 0/1'
r'Layers: 0%\|[^|]+\| 0/1'
r'Layers: 0%\|[^|]+\| 0/2'
r'Layers: 0%\|[^|]+\| 0/3'
r'Layers: 0%\|[^|]+\| 0/4'
r'Layers: 0%\|[^|]+\| 0/4'
r'Layers: 0%\|[^|]+\| 0/4'
r'Layers: 0%\|[^|]+\| 0/4'
r'abc: 100%\|[^|]+\| 512/512 \[1\.00MB/s\]'
r'Layers: 0%\|[^|]+\| 0/4'
r'egh: 100%\|[^|]+\| 57\.3k/57\.3k \[1\.00MB/s\]'
r'Layers: 25%\|[^|]+\| 1/4'
r'Layers: 50%\|[^|]+\| 2/4'
r'Layers: 75%\|[^|]+\| 3/4'
r'Layers: 100%\|[^|]+\| 4/4'
r'abc: 100%\|[^|]+\| 24\.8k/24\.8k \[1\.00MB/s\]'
r'egh: 100%\|[^|]+\| 57\.3k/57\.3k \[1\.00MB/s\]'
r'The image registry\.io/user/project:test pushed successfully\.'
)
assert expected in clean_progress_output(result.output)
assert re.search(expected, clean_progress_output(result.output))


@pytest.mark.usefixtures('project_dir')
Expand Down
10 changes: 7 additions & 3 deletions tests/image/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ def test_get_image_registry(self):
class StatusUrlsTest(TestCase):

def setUp(self):
tmpdir = tempfile.gettempdir()
os.chdir(tmpdir)
self.status_file = os.path.join(tmpdir, STATUS_FILE_LOCATION)
self.curdir = os.getcwd()
self.tmp_dir = tempfile.gettempdir()
os.chdir(self.tmp_dir)
self.status_file = os.path.join(self.tmp_dir, STATUS_FILE_LOCATION)
if os.path.exists(self.status_file):
os.remove(self.status_file)

def tearDown(self):
os.chdir(self.curdir)

def test_load_status_url(self):
self.assertRaises(NotFoundException, load_status_url, 0)
# try with void file
Expand Down
5 changes: 3 additions & 2 deletions tests/test_deploy_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self):
self.curdir = os.getcwd()
self.fake_requester = FakeRequester()
deploy_egg.utils.make_deploy_request = self.fake_requester.fake_request
self.tmp_dir = tempfile.mktemp(prefix="shub-test-deploy-eggs")
self.tmp_dir = tempfile.mkdtemp(prefix="shub-test-deploy-eggs")

def tearDown(self):
os.chdir(self.curdir)
Expand All @@ -35,7 +35,8 @@ def tearDown(self):
def test_parses_project_information_correctly(self):
# this test's assertions are based on the values
# defined on this folder's setup.py file
shutil.copytree('tests/samples/deploy_egg_sample_project/', self.tmp_dir)
shutil.rmtree(self.tmp_dir)
shutil.copytree('tests/samples/deploy_egg_sample_project', self.tmp_dir)
os.chdir(self.tmp_dir)

data = self.call_main_and_check_request_data()
Expand Down

0 comments on commit 822b289

Please sign in to comment.