@@ -95,3 +95,36 @@ def test_invalid_image_name():
95
95
"""
96
96
with pytest .raises (SystemExit ):
97
97
make_r2d (["--image-name" , "_invalid" , "." ])
98
+
99
+
100
+ def test_build_config_priority (tmp_path ):
101
+ config_file = str (tmp_path .joinpath ("repo2docker_config.py" ))
102
+ with open (config_file , "w" ) as f :
103
+ f .write ("c.Repo2Docker.dry_run = True" )
104
+ r2d = make_r2d (["--config" , config_file , "." ])
105
+ assert r2d .dry_run
106
+ r2d = make_r2d (["--config" , config_file , "--build" , "." ])
107
+ assert not r2d .dry_run
108
+ with open (config_file , "w" ) as f :
109
+ f .write ("c.Repo2Docker.dry_run = False" )
110
+ r2d = make_r2d (["--config" , config_file , "--no-build" , "." ])
111
+ assert r2d .dry_run
112
+
113
+
114
+ @pytest .mark .parametrize (
115
+ "trait, arg, default" ,
116
+ [
117
+ ("output_image_spec" , "--image-name" , "" ),
118
+ ("ref" , "--ref" , None ),
119
+ ],
120
+ )
121
+ def test_config_priority (tmp_path , trait , arg , default ):
122
+ config_file = str (tmp_path .joinpath ("repo2docker_config.py" ))
123
+ r2d = make_r2d (["." ])
124
+ assert getattr (r2d , trait ) == default
125
+ with open (config_file , "w" ) as f :
126
+ f .write (f"c.Repo2Docker.{ trait } = 'config'" )
127
+ r2d = make_r2d (["--config" , config_file , "." ])
128
+ assert getattr (r2d , trait ) == "config"
129
+ r2d = make_r2d (["--config" , config_file , arg , "cli" , "." ])
130
+ assert getattr (r2d , trait ) == "cli"
0 commit comments