예제 #1
0
 def test_non_existing_path(self, filepath, filename, config_instance):
     """Make sure that the path-parents are created if not present."""
     deeppath = os.path.join(filepath, filename)
     assert not os.path.lexists(deeppath)
     config_obj = config_instance()
     config_obj.filename = deeppath
     write_config_obj(config_obj)
     assert os.path.lexists(deeppath)
예제 #2
0
 def test_write_config_obj_fail_unicode_encode_error(
     self,
     invalid_config_obj,
     capsys,
 ):
     with pytest.raises(SystemExit):
         write_config_obj(invalid_config_obj)
     out, err = capsys.readouterr()
     assert not out and err
예제 #3
0
 def test_write_config_obj_fail_no_cannot_mkdir_p(
     self,
     simple_config_obj,
     filename,
     capsys,
 ):
     assert os.path.isfile(simple_config_obj.filename)
     invalid_filename = os.path.join(simple_config_obj.filename, filename)
     simple_config_obj.filename = invalid_filename
     with pytest.raises(SystemExit):
         write_config_obj(simple_config_obj)
     out, err = capsys.readouterr()
     assert not out and err
예제 #4
0
 def test_write_config_obj_fail_unknown_forced_error(
     self,
     simple_config_obj,
     mocker,
     capsys,
 ):
     # I'm not sure what else would make ConfigObj.write() throw besides
     # UnicodeEncodeError, but that doesn't mean we can't test it.
     arbitrary_error_mock = mock.Mock()
     arbitrary_error_mock.side_effect = Exception
     mocker.patch.object(simple_config_obj, 'write', arbitrary_error_mock)
     with pytest.raises(SystemExit):
         write_config_obj(simple_config_obj)
     out, err = capsys.readouterr()
     assert not out and err
예제 #5
0
 def test_write_config_obj_fail_no_filename(self, simple_config_obj):
     assert os.path.isfile(simple_config_obj.filename)
     simple_config_obj.filename = None
     with pytest.raises(AttributeError):
         write_config_obj(simple_config_obj)
예제 #6
0
 def test_write_config_obj_okay(self, simple_config_obj, filepath):
     assert os.path.isfile(simple_config_obj.filename)
     simple_config_obj.filename = filepath
     write_config_obj(simple_config_obj)
     assert os.path.isfile(filepath)
예제 #7
0
 def test_file_is_written(self, filepath, config_instance):
     """Ensure file is written. Content not checked; that's ConfigObj's job."""
     config_obj = config_instance()
     write_config_obj(config_obj)
     # E.g., '/tmp/pytest-of-user/pytest-188/test_file_is_written0/{}.conf'
     assert os.path.lexists(config_obj.filename)