diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-01-06 17:52:38 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-01-06 17:52:38 +0100 |
commit | da03efeaed5c578d28ed50b5d91404e4c2e9bfbd (patch) | |
tree | 58b6bb4da138d2ff126ce39179f21978bc066adc | |
parent | 9df8aaabbcaae8c01879895516f06db0d5f8cd13 (diff) |
Add an help string in a comment in the generated empty files
-rw-r--r-- | lesana/collection.py | 2 | ||||
-rw-r--r-- | tests/data/simple/settings.yaml | 2 | ||||
-rw-r--r-- | tests/test_collection.py | 6 |
3 files changed, 9 insertions, 1 deletions
diff --git a/lesana/collection.py b/lesana/collection.py index 1965bc4..d924699 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -42,6 +42,8 @@ class Entry(object): def empty_data(self): data = '' for field in self.collection.settings['fields']: + if not field.get('help', None) is None: + data += "# {name} ({type}): {help}\n".format(**field) t = field['type'] if t == 'string': data += ("{name}: ''\n".format(**field)) diff --git a/tests/data/simple/settings.yaml b/tests/data/simple/settings.yaml index fc405a1..ad68fe3 100644 --- a/tests/data/simple/settings.yaml +++ b/tests/data/simple/settings.yaml @@ -13,5 +13,7 @@ fields: - name: quantity type: integer index: no + help: 'how many items are there' - name: other type: yaml + help: '' diff --git a/tests/test_collection.py b/tests/test_collection.py index 9e3df7c..8e8e5f1 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -104,7 +104,11 @@ class testEntries(unittest.TestCase): self.collection.save_entries(entries=[new_entry]) entry_fname = 'tests/data/simple/items/' + new_entry.fname with open(entry_fname) as fp: - written = ruamel.yaml.safe_load(fp) + text = fp.read() + self.assertIn('quantity (integer): how many items are there', text) + self.assertIn('other (yaml):', text) + self.assertNotIn('position (string)', text) + written = ruamel.yaml.safe_load(text) self.assertIsInstance(written['quantity'], int) self.assertIsInstance(written['name'], str) os.remove(entry_fname) |