-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Check versions used to create the venv and auto-wipe #3432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d4d355c
Check versions used to create the venv and auto-wipe
humitos 1541bf0
Save environment.json file
humitos 85d7603
Open file properly
humitos 05c2aed
Make it compatible with current master
humitos e99673a
Minor refactor
humitos d38b5c3
Fix linting errors
humitos b7a4cc1
Test cases for PythonEnvironment.is_obsolete
humitos 49ed943
Comment fix
humitos da1fde3
Rename environment file
humitos 3b2f538
Make json.dump compatible with py2 and py3
humitos a151cde
Use `config.python_full_version` instead of `config.python_version`
humitos f31144a
Test for changing container_image at project level
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,22 @@ | |
from builtins import str | ||
|
||
import mock | ||
import pytest | ||
from django.test import TestCase | ||
from docker.errors import APIError as DockerAPIError | ||
from docker.errors import DockerException | ||
from mock import Mock, PropertyMock, patch | ||
from mock import Mock, PropertyMock, mock_open, patch | ||
|
||
from readthedocs.builds.constants import BUILD_STATE_CLONING | ||
from readthedocs.builds.models import Version | ||
from readthedocs.doc_builder.config import ConfigWrapper | ||
from readthedocs.doc_builder.environments import ( | ||
BuildCommand, DockerBuildCommand, DockerEnvironment, LocalEnvironment) | ||
from readthedocs.doc_builder.exceptions import BuildEnvironmentError | ||
from readthedocs.doc_builder.python_environments import Virtualenv | ||
from readthedocs.projects.models import Project | ||
from readthedocs.rtd_tests.mocks.environment import EnvironmentMockGroup | ||
from readthedocs.rtd_tests.tests.test_config_wrapper import create_load | ||
|
||
DUMMY_BUILD_ID = 123 | ||
SAMPLE_UNICODE = u'HérÉ îß sömê ünïçó∂é' | ||
|
@@ -831,3 +835,134 @@ def test_command_oom_kill(self): | |
self.assertEqual( | ||
str(cmd.output), | ||
u'Command killed due to excessive memory consumption\n') | ||
|
||
|
||
|
||
|
||
class TestAutoWipeEnvironment(TestCase): | ||
fixtures = ['test_data'] | ||
|
||
def setUp(self): | ||
self.pip = Project.objects.get(slug='pip') | ||
self.version = self.pip.versions.get(slug='0.8') | ||
|
||
def test_is_obsolete_without_env_json_file(self): | ||
yaml_config = create_load()()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
with patch('os.path.exists') as exists: | ||
exists.return_value = False | ||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
|
||
self.assertFalse(python_env.is_obsolete) | ||
|
||
def test_is_obsolete_with_invalid_env_json_file(self): | ||
yaml_config = create_load()()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
with patch('os.path.exists') as exists: | ||
exists.return_value = True | ||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
|
||
self.assertFalse(python_env.is_obsolete) | ||
|
||
def test_is_obsolete_with_json_different_python_version(self): | ||
config_data = { | ||
'build': { | ||
'image': '2.0', | ||
}, | ||
'python': { | ||
'version': 2.7, | ||
}, | ||
} | ||
yaml_config = create_load(config_data)()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 3.5}}' | ||
with patch('os.path.exists') as exists, patch('readthedocs.doc_builder.python_environments.open', mock_open(read_data=env_json_data)) as _open: # noqa | ||
exists.return_value = True | ||
self.assertTrue(python_env.is_obsolete) | ||
|
||
@pytest.mark.xfail(reason='build.image is not being considered yet') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to make this test pass, we need the PR that get the image from yaml merged... then we can remove this line and it should pass :) |
||
def test_is_obsolete_with_json_different_build_image(self): | ||
config_data = { | ||
'build': { | ||
'image': 'latest', | ||
}, | ||
'python': { | ||
'version': 2.7, | ||
}, | ||
} | ||
yaml_config = create_load(config_data)()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 2.7}}' | ||
with patch('os.path.exists') as exists, patch('readthedocs.doc_builder.python_environments.open', mock_open(read_data=env_json_data)) as _open: # noqa | ||
exists.return_value = True | ||
self.assertTrue(python_env.is_obsolete) | ||
|
||
def test_is_obsolete_with_project_different_build_image(self): | ||
config_data = { | ||
'build': { | ||
'image': '2.0', | ||
}, | ||
'python': { | ||
'version': 2.7, | ||
}, | ||
} | ||
yaml_config = create_load(config_data)()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
# Set container_image manually | ||
self.pip.container_image = 'readthedocs/build:latest' | ||
self.pip.save() | ||
|
||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 2.7}}' | ||
with patch('os.path.exists') as exists, patch('readthedocs.doc_builder.python_environments.open', mock_open(read_data=env_json_data)) as _open: # noqa | ||
exists.return_value = True | ||
self.assertTrue(python_env.is_obsolete) | ||
|
||
def test_is_obsolete_with_json_same_data_as_version(self): | ||
config_data = { | ||
'build': { | ||
'image': '2.0', | ||
}, | ||
'python': { | ||
'version': 3.5, | ||
}, | ||
} | ||
yaml_config = create_load(config_data)()[0] | ||
config = ConfigWrapper(version=self.version, yaml_config=yaml_config) | ||
|
||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=None, | ||
config=config, | ||
) | ||
env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 3.5}}' | ||
with patch('os.path.exists') as exists, patch('readthedocs.doc_builder.python_environments.open', mock_open(read_data=env_json_data)) as _open: # noqa | ||
exists.return_value = True | ||
self.assertFalse(python_env.is_obsolete) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
with patch()
lines are terrible, but I didn't find a better way to write them :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to escape with backslash here according to pep8 https://www.python.org/dev/peps/pep-0008/#maximum-line-length