aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-01-26 17:17:38 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-01-26 17:17:38 -0600
commit39cc3d5a0a717199783c292373e181e410608344 (patch)
treefa05b16c5e3de70d01695837b96545c8ae527315
parentMerge branch 'master' of github.com:eugenetriguba/config_file (diff)
downloadconfig-file-39cc3d5a0a717199783c292373e181e410608344.zip
Rename reset() to restore_original()
-rw-r--r--CHANGELOG.md11
-rw-r--r--README.md13
-rw-r--r--config_file/config_file.py8
-rw-r--r--tests/test_config_file.py4
4 files changed, 24 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0005a05..5369103 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+Changed
+
+ - BREAKING: The `reset()` method on `ConfigFile` is now called `restore_original()`.
+ The behavior is the same. This was done to better describe what exactly that method
+ is doing. Since the file is not written back out with every `set()` or `delete()`
+ and calling `save()` explicitly is required, `reset()` may have been confused with
+ resetting the changes you've made rather than deleting and restoring the original
+ configuration file.
+
## 0.6.0 - 2020-01-24
Changed
diff --git a/README.md b/README.md
index cf81e5d..f59a2ed 100644
--- a/README.md
+++ b/README.md
@@ -102,24 +102,25 @@ config.has('calendar.start_week_on_sunday')
```
### Save when you're done
-The contents are only written back out when you call `save()`.
+The contents are only written back out when you call `save()`. `set()` and `delete()` both
+modify the contents of the file and
```python
config.save()
>>> True
```
-### Reset the file back to its original
+### Restore the file back to its original
The current configuration file would be deleted and replaced by a copy of the original.
-By default, since our passed in config file was at path `~/.config/test/config.ini`, `reset()`
-will look for `~/.config/test/config.original.ini`.
+By default, since our passed in config file was at path `~/.config/test/config.ini`,
+`restore_original()` will look for `~/.config/test/config.original.ini`.
```python
-config.reset()
+config.restore_original()
>>> True
# But you can also specify the original config file explicitly.
-config.reset(original_file_path="~/some_other_directory/this_is_actually_the_original.ini")
+config.restore_original(original_file_path="~/some_other_directory/this_is_actually_the_original.ini")
>>> True
```
diff --git a/config_file/config_file.py b/config_file/config_file.py
index 5827d08..bc05d97 100644
--- a/config_file/config_file.py
+++ b/config_file/config_file.py
@@ -96,11 +96,11 @@ class ConfigFile:
"""
return self.parser.has(section_key)
- def reset(self, original_file_path=None):
+ def restore_original(self, original_file_path=None):
"""
- Resets the config file by deleting it and copying the original back
- in its place. The contents of this config file are then set to the
- newly reset config file.
+ Restores the original the config file by deleting it and copying the original
+ back in its place. The internal contents of this config file object are then set
+ to the newly reset config file.
:param original_file_path: The path to the original config file to reset it to.
If this is not provided and, say, your configuration file is config.json, the
diff --git a/tests/test_config_file.py b/tests/test_config_file.py
index 1daba6f..3d2a5d2 100644
--- a/tests/test_config_file.py
+++ b/tests/test_config_file.py
@@ -22,7 +22,7 @@ def test_that_config_file_initializes_correctly(tmp_path, file_contents, file_na
"file_contents, file_name, original_file_name",
[("[calendar]\nsunday_index = 0\n\n", "config.ini", "config.original.ini")],
)
-def test_that_config_file_can_reset(
+def test_that_config_file_can_restore_the_original(
tmpdir, file_contents, file_name, original_file_name
):
config_path = tmpdir / file_name
@@ -33,7 +33,7 @@ def test_that_config_file_can_reset(
config = ConfigFile(str(config_path))
config.set("calendar.sunday_index", 0)
- config.reset()
+ config.restore_original()
assert config.stringify() == ConfigFile(str(original_config_path)).stringify()
assert config_path.read_text(encoding="utf-8") == original_config_path.read_text(
encoding="utf-8"