@@ -178,3 +178,32 @@ def test_remove_env_bin_from_path():
178
178
assert (nodeenv .remove_env_bin_from_path (
179
179
'//home://home/env/bin://home/bin' , '//home/env/bin' )
180
180
== '//home://home/bin' )
181
+
182
+
183
+ @pytest .mark .parametrize (
184
+ "node_version_file_content, expected_node_version" ,
185
+ [
186
+ ("v22.14.0" , "22.14.0" ),
187
+ ("22.14.0" , "22.14.0" ),
188
+ ("v22.14.0\n " , "22.14.0" ),
189
+ ("v22.14.0\r \n " , "22.14.0" ),
190
+ ],
191
+ )
192
+ def test_node_version_file (node_version_file_content , expected_node_version ):
193
+ def custom_exists (path ):
194
+ if path == ".node-version" :
195
+ return True
196
+ else :
197
+ return os .path .exists (path )
198
+
199
+ def custom_open (file_path , * args , ** kwargs ):
200
+ if file_path == ".node-version" :
201
+ return mock .mock_open (read_data = node_version_file_content )()
202
+ else :
203
+ return open (file_path , * args , ** kwargs )
204
+
205
+ with mock .patch ("os.path.exists" , new = custom_exists ), mock .patch (
206
+ "builtins.open" , new = custom_open
207
+ ):
208
+ nodeenv .Config ._load ([])
209
+ assert nodeenv .Config .node == expected_node_version
0 commit comments