|
@@ -1,7 +1,9 @@
|
|
from io import StringIO
|
|
from io import StringIO
|
|
|
|
+import os
|
|
import sys
|
|
import sys
|
|
|
|
|
|
from flexmock import flexmock
|
|
from flexmock import flexmock
|
|
|
|
+import pytest
|
|
|
|
|
|
from borgmatic.config import generate as module
|
|
from borgmatic.config import generate as module
|
|
|
|
|
|
@@ -15,12 +17,22 @@ def test_insert_newline_before_comment_does_not_raise():
|
|
|
|
|
|
|
|
|
|
def test_write_configuration_does_not_raise():
|
|
def test_write_configuration_does_not_raise():
|
|
|
|
+ flexmock(os.path).should_receive('exists').and_return(False)
|
|
builtins = flexmock(sys.modules['builtins'])
|
|
builtins = flexmock(sys.modules['builtins'])
|
|
builtins.should_receive('open').and_return(StringIO())
|
|
builtins.should_receive('open').and_return(StringIO())
|
|
|
|
|
|
module.write_configuration('config.yaml', {})
|
|
module.write_configuration('config.yaml', {})
|
|
|
|
|
|
|
|
|
|
|
|
+def test_write_configuration_with_already_existing_file_raises():
|
|
|
|
+ flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
+ builtins = flexmock(sys.modules['builtins'])
|
|
|
|
+ builtins.should_receive('open').and_return(StringIO())
|
|
|
|
+
|
|
|
|
+ with pytest.raises(FileExistsError):
|
|
|
|
+ module.write_configuration('config.yaml', {})
|
|
|
|
+
|
|
|
|
+
|
|
def test_add_comments_to_configuration_does_not_raise():
|
|
def test_add_comments_to_configuration_does_not_raise():
|
|
# Ensure that it can deal with fields both in the schema and missing from the schema.
|
|
# Ensure that it can deal with fields both in the schema and missing from the schema.
|
|
config = module.yaml.comments.CommentedMap([('foo', 33), ('bar', 44), ('baz', 55)])
|
|
config = module.yaml.comments.CommentedMap([('foo', 33), ('bar', 44), ('baz', 55)])
|