9
9
absolute_import , division , print_function , unicode_literals )
10
10
11
11
import os .path
12
- import json
13
12
import re
14
- import tempfile
15
13
import uuid
16
14
from builtins import str
17
15
@@ -839,54 +837,14 @@ def test_command_oom_kill(self):
839
837
u'Command killed due to excessive memory consumption\n ' )
840
838
841
839
842
- class AutoWipeEnvironmentBase (object ):
840
+
841
+
842
+ class TestAutoWipeEnvironment (TestCase ):
843
843
fixtures = ['test_data' ]
844
- build_env_class = None
845
844
846
845
def setUp (self ):
847
846
self .pip = Project .objects .get (slug = 'pip' )
848
847
self .version = self .pip .versions .get (slug = '0.8' )
849
- self .build_env = self .build_env_class (
850
- project = self .pip ,
851
- version = self .version ,
852
- build = {'id' : DUMMY_BUILD_ID },
853
- )
854
-
855
- def test_save_environment_json (self ):
856
- config_data = {
857
- 'build' : {
858
- 'image' : '2.0' ,
859
- },
860
- 'python' : {
861
- 'version' : 2.7 ,
862
- },
863
- }
864
- yaml_config = create_load (config_data )()[0 ]
865
- config = ConfigWrapper (version = self .version , yaml_config = yaml_config )
866
-
867
- python_env = Virtualenv (
868
- version = self .version ,
869
- build_env = self .build_env ,
870
- config = config ,
871
- )
872
-
873
- with patch (
874
- 'readthedocs.doc_builder.python_environments.PythonEnvironment.environment_json_path' ,
875
- return_value = tempfile .mktemp (suffix = 'envjson' ),
876
- ):
877
- python_env .save_environment_json ()
878
- json_data = json .load (open (python_env .environment_json_path ()))
879
-
880
- expected_data = {
881
- 'build' : {
882
- 'image' : 'readthedocs/build:2.0' ,
883
- 'hash' : 'a1b2c3' ,
884
- },
885
- 'python' : {
886
- 'version' : 2.7 ,
887
- },
888
- }
889
- self .assertDictEqual (json_data , expected_data )
890
848
891
849
def test_is_obsolete_without_env_json_file (self ):
892
850
yaml_config = create_load ()()[0 ]
@@ -896,7 +854,7 @@ def test_is_obsolete_without_env_json_file(self):
896
854
exists .return_value = False
897
855
python_env = Virtualenv (
898
856
version = self .version ,
899
- build_env = self . build_env ,
857
+ build_env = None ,
900
858
config = config ,
901
859
)
902
860
@@ -910,7 +868,7 @@ def test_is_obsolete_with_invalid_env_json_file(self):
910
868
exists .return_value = True
911
869
python_env = Virtualenv (
912
870
version = self .version ,
913
- build_env = self . build_env ,
871
+ build_env = None ,
914
872
config = config ,
915
873
)
916
874
@@ -930,10 +888,10 @@ def test_is_obsolete_with_json_different_python_version(self):
930
888
931
889
python_env = Virtualenv (
932
890
version = self .version ,
933
- build_env = self . build_env ,
891
+ build_env = None ,
934
892
config = config ,
935
893
)
936
- env_json_data = '{"build": {"image": "readthedocs/build:2.0", "hash": "a1b2c3" }, "python": {"version": 3.5}}' # noqa
894
+ env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 3.5}}'
937
895
with patch ('os.path.exists' ) as exists , patch ('readthedocs.doc_builder.python_environments.open' , mock_open (read_data = env_json_data )) as _open : # noqa
938
896
exists .return_value = True
939
897
self .assertTrue (python_env .is_obsolete )
@@ -952,10 +910,10 @@ def test_is_obsolete_with_json_different_build_image(self):
952
910
953
911
python_env = Virtualenv (
954
912
version = self .version ,
955
- build_env = self . build_env ,
913
+ build_env = None ,
956
914
config = config ,
957
915
)
958
- env_json_data = '{"build": {"image": "readthedocs/build:2.0", "hash": "a1b2c3" }, "python": {"version": 2.7}}' # noqa
916
+ env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 2.7}}'
959
917
with patch ('os.path.exists' ) as exists , patch ('readthedocs.doc_builder.python_environments.open' , mock_open (read_data = env_json_data )) as _open : # noqa
960
918
exists .return_value = True
961
919
self .assertTrue (python_env .is_obsolete )
@@ -978,10 +936,10 @@ def test_is_obsolete_with_project_different_build_image(self):
978
936
979
937
python_env = Virtualenv (
980
938
version = self .version ,
981
- build_env = self . build_env ,
939
+ build_env = None ,
982
940
config = config ,
983
941
)
984
- env_json_data = '{"build": {"image": "readthedocs/build:2.0", "hash": "a1b2c3" }, "python": {"version": 2.7}}' # noqa
942
+ env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 2.7}}'
985
943
with patch ('os.path.exists' ) as exists , patch ('readthedocs.doc_builder.python_environments.open' , mock_open (read_data = env_json_data )) as _open : # noqa
986
944
exists .return_value = True
987
945
self .assertTrue (python_env .is_obsolete )
@@ -1000,55 +958,10 @@ def test_is_obsolete_with_json_same_data_as_version(self):
1000
958
1001
959
python_env = Virtualenv (
1002
960
version = self .version ,
1003
- build_env = self . build_env ,
961
+ build_env = None ,
1004
962
config = config ,
1005
963
)
1006
- env_json_data = '{"build": {"image": "readthedocs/build:2.0", "hash": "a1b2c3" }, "python": {"version": 3.5}}' # noqa
964
+ env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 3.5}}'
1007
965
with patch ('os.path.exists' ) as exists , patch ('readthedocs.doc_builder.python_environments.open' , mock_open (read_data = env_json_data )) as _open : # noqa
1008
966
exists .return_value = True
1009
967
self .assertFalse (python_env .is_obsolete )
1010
-
1011
- def test_is_obsolete_with_json_different_build_hash (self ):
1012
- config_data = {
1013
- 'build' : {
1014
- 'image' : '2.0' ,
1015
- },
1016
- 'python' : {
1017
- 'version' : 2.7 ,
1018
- },
1019
- }
1020
- yaml_config = create_load (config_data )()[0 ]
1021
- config = ConfigWrapper (version = self .version , yaml_config = yaml_config )
1022
-
1023
- # Set container_image manually
1024
- self .pip .container_image = 'readthedocs/build:2.0'
1025
- self .pip .save ()
1026
-
1027
- python_env = Virtualenv (
1028
- version = self .version ,
1029
- build_env = self .build_env ,
1030
- config = config ,
1031
- )
1032
- env_json_data = '{"build": {"image": "readthedocs/build:2.0", "hash": "foo"}, "python": {"version": 2.7}}' # noqa
1033
- with patch ('os.path.exists' ) as exists , patch ('readthedocs.doc_builder.python_environments.open' , mock_open (read_data = env_json_data )) as _open : # noqa
1034
- exists .return_value = True
1035
- self .assertTrue (python_env .is_obsolete )
1036
-
1037
-
1038
- @patch (
1039
- 'readthedocs.doc_builder.environments.DockerBuildEnvironment.image_hash' ,
1040
- PropertyMock (return_value = 'a1b2c3' ),
1041
- )
1042
- class AutoWipeDockerBuildEnvironmentTest (AutoWipeEnvironmentBase , TestCase ):
1043
- build_env_class = DockerBuildEnvironment
1044
-
1045
-
1046
- @pytest .mark .xfail (
1047
- reason = 'PythonEnvironment needs to be refactored to do not rely on DockerBuildEnvironment' ,
1048
- )
1049
- @patch (
1050
- 'readthedocs.doc_builder.environments.DockerBuildEnvironment.image_hash' ,
1051
- PropertyMock (return_value = 'a1b2c3' ),
1052
- )
1053
- class AutoWipeLocalBuildEnvironmentTest (AutoWipeEnvironmentBase , TestCase ):
1054
- build_env_class = LocalBuildEnvironment
0 commit comments