3232
3333from . import utils
3434
35- CONFIG_FILENAME = 'test_config'
35+
36+ @pytest .fixture
37+ def config_path (tmp_path : Path ) -> Path :
38+ return tmp_path / 'test_config'
3639
3740
3841@pytest .fixture
3942def config (testrepo : Repository ) -> Generator [object , None , None ]:
4043 yield testrepo .config
41- try :
42- Path (CONFIG_FILENAME ).unlink ()
43- except OSError :
44- pass
4544
4645
4746def test_config (config : Config ) -> None :
@@ -64,42 +63,42 @@ def test_system_config() -> None:
6463 pass
6564
6665
67- def test_new () -> None :
66+ def test_new (config_path : Path ) -> None :
6867 # Touch file
69- open ( CONFIG_FILENAME , 'w' ). close ()
68+ config_path . touch ()
7069
71- config_write = Config (CONFIG_FILENAME )
70+ config_write = Config (str ( config_path ) )
7271 assert config_write is not None
7372
7473 config_write ['core.bare' ] = False
7574 config_write ['core.editor' ] = 'ed'
7675
77- config_read = Config (CONFIG_FILENAME )
76+ config_read = Config (str ( config_path ) )
7877 assert 'core.bare' in config_read
7978 assert not config_read .get_bool ('core.bare' )
8079 assert 'core.editor' in config_read
8180 assert config_read ['core.editor' ] == 'ed'
8281
8382
84- def test_add () -> None :
85- with open (CONFIG_FILENAME , 'w' ) as new_file :
83+ def test_add (config_path : Path ) -> None :
84+ with open (config_path , 'w' ) as new_file :
8685 new_file .write ('[this]\n \t that = true\n ' )
8786 new_file .write ('[something "other"]\n \t here = false' )
8887
8988 config = Config ()
90- config .add_file (CONFIG_FILENAME , 0 )
89+ config .add_file (config_path , 0 )
9190 assert 'this.that' in config
9291 assert config .get_bool ('this.that' )
9392 assert 'something.other.here' in config
9493 assert not config .get_bool ('something.other.here' )
9594
9695
97- def test_add_aspath () -> None :
98- with open (CONFIG_FILENAME , 'w' ) as new_file :
96+ def test_add_aspath (config_path : Path ) -> None :
97+ with open (config_path , 'w' ) as new_file :
9998 new_file .write ('[this]\n \t that = true\n ' )
10099
101100 config = Config ()
102- config .add_file (Path ( CONFIG_FILENAME ) , 0 )
101+ config .add_file (config_path , 0 )
103102 assert 'this.that' in config
104103
105104
@@ -148,12 +147,12 @@ def test_write(config: Config) -> None:
148147 assert 'core.dummy3' not in config
149148
150149
151- def test_multivar () -> None :
152- with open (CONFIG_FILENAME , 'w' ) as new_file :
150+ def test_multivar (config_path : Path ) -> None :
151+ with open (config_path , 'w' ) as new_file :
153152 new_file .write ('[this]\n \t that = foobar\n \t that = foobeer\n ' )
154153
155154 config = Config ()
156- config .add_file (CONFIG_FILENAME , 6 )
155+ config .add_file (config_path , 6 )
157156 assert 'this.that' in config
158157
159158 assert ['foobar' , 'foobeer' ] == list (config .get_multivar ('this.that' ))
@@ -185,27 +184,27 @@ def test_iterator(config: Config) -> None:
185184 assert lst ['core.bare' ]
186185
187186
188- def test_valueless_key_iteration () -> None :
187+ def test_valueless_key_iteration (config_path : Path ) -> None :
189188 # A valueless key (no `= value`) has a NULL value pointer in libgit2.
190189 # Iterating over such entries must not raise a RuntimeError.
191- with open (CONFIG_FILENAME , 'w' ) as new_file :
190+ with open (config_path , 'w' ) as new_file :
192191 new_file .write ('[section]\n \t valuelesskey\n \t normalkey = somevalue\n ' )
193192
194193 config = Config ()
195- config .add_file (CONFIG_FILENAME , 6 )
194+ config .add_file (config_path , 6 )
196195
197196 entries = {entry .name : entry for entry in config }
198197 assert 'section.valuelesskey' in entries
199198 assert 'section.normalkey' in entries
200199
201200
202- def test_valueless_key_value () -> None :
201+ def test_valueless_key_value (config_path : Path ) -> None :
203202 # A valueless key must expose value=None and raw_value=None.
204- with open (CONFIG_FILENAME , 'w' ) as new_file :
203+ with open (config_path , 'w' ) as new_file :
205204 new_file .write ('[section]\n \t valuelesskey\n \t normalkey = somevalue\n ' )
206205
207206 config = Config ()
208- config .add_file (CONFIG_FILENAME , 6 )
207+ config .add_file (config_path , 6 )
209208
210209 entries = {entry .name : entry for entry in config }
211210 assert entries ['section.valuelesskey' ].raw_value is None
0 commit comments