From 8ec0cae371a0b392b81bf34d5ee849c233ebbf65 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Tue, 13 Dec 2016 17:36:40 +0100 Subject: Rename schema.yaml to settings.yaml --- lesana/collection.py | 20 ++++++++++++-------- tests/data/simple/schema.yaml | 12 ------------ tests/data/simple/settings.yaml | 12 ++++++++++++ tests/data/wrong/schema.yaml | 12 ------------ tests/data/wrong/settings.yaml | 12 ++++++++++++ tests/test_collection.py | 10 +++++----- 6 files changed, 41 insertions(+), 37 deletions(-) delete mode 100644 tests/data/simple/schema.yaml create mode 100644 tests/data/simple/settings.yaml delete mode 100644 tests/data/wrong/schema.yaml create mode 100644 tests/data/wrong/settings.yaml diff --git a/lesana/collection.py b/lesana/collection.py index 64b4246..cff94f7 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -30,18 +30,21 @@ class Collection(object): def __init__(self, directory=None): self.basedir = directory or os.getcwd() try: - with open(os.path.join(self.basedir, 'schema.yaml')) as fp: - self.schema = ruamel.yaml.load(fp, ruamel.yaml.RoundTripLoader) + with open(os.path.join(self.basedir, 'settings.yaml')) as fp: + self.settings = ruamel.yaml.load( + fp, + ruamel.yaml.RoundTripLoader + ) except FileNotFoundError: - self.schema = ruamel.yaml.load("{}") + self.settings = ruamel.yaml.load("{}") os.makedirs(os.path.join(self.basedir, '.lesana'), exist_ok=True) - if 'lang' in self.schema: + if 'lang' in self.settings: try: - self.stemmer = xapian.Stem(self.schema['lang']) + self.stemmer = xapian.Stem(self.settings['lang']) except xapian.InvalidArgumentError: logging.warning( - "Invalid language %s, in schema.yaml: using english.", - self.schema['lang'] + "Invalid language %s, in settings.yaml: using english.", + self.settings['lang'] ) self.stemmer = xapian.Stem('english') else: @@ -105,7 +108,8 @@ class Collection(object): except IOError as e: logging.warning("Could not load file {}: {}".format( fname, - str(e))) + str(e)) + ) else: updated += 1 return updated diff --git a/tests/data/simple/schema.yaml b/tests/data/simple/schema.yaml deleted file mode 100644 index 177aa92..0000000 --- a/tests/data/simple/schema.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: "Simple lesana collection" -lang: 'english' -fields: - - name: name - type: string - index: free - - name: description - type: text - index: free - - name: position - type: string - index: facet diff --git a/tests/data/simple/settings.yaml b/tests/data/simple/settings.yaml new file mode 100644 index 0000000..177aa92 --- /dev/null +++ b/tests/data/simple/settings.yaml @@ -0,0 +1,12 @@ +name: "Simple lesana collection" +lang: 'english' +fields: + - name: name + type: string + index: free + - name: description + type: text + index: free + - name: position + type: string + index: facet diff --git a/tests/data/wrong/schema.yaml b/tests/data/wrong/schema.yaml deleted file mode 100644 index 56031e4..0000000 --- a/tests/data/wrong/schema.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: "Lesana collection with certain errors" -lang: 'somethingish' -fields: - - name: name - type: string - index: free - - name: description - type: text - index: free - - name: position - type: string - index: facet diff --git a/tests/data/wrong/settings.yaml b/tests/data/wrong/settings.yaml new file mode 100644 index 0000000..56031e4 --- /dev/null +++ b/tests/data/wrong/settings.yaml @@ -0,0 +1,12 @@ +name: "Lesana collection with certain errors" +lang: 'somethingish' +fields: + - name: name + type: string + index: free + - name: description + type: text + index: free + - name: position + type: string + index: facet diff --git a/tests/test_collection.py b/tests/test_collection.py index b70c85f..be9a4e5 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -12,7 +12,7 @@ class testCollectionLoading(unittest.TestCase): def test_empty(self): self.collection = lesana.Collection('tests/data/empty') - self.assertEqual(self.collection.schema, {}) + self.assertEqual(self.collection.settings, {}) self.collection.update_cache() self.assertIsNotNone(self.collection.cache) @@ -20,9 +20,9 @@ class testCollectionLoading(unittest.TestCase): def test_simple(self): self.collection = lesana.Collection('tests/data/simple') - self.assertIsNotNone(self.collection.schema) - self.assertEqual(self.collection.schema['name'], "Simple lesana collection") - self.assertEqual(len(self.collection.schema['fields']), 3) + self.assertIsNotNone(self.collection.settings) + self.assertEqual(self.collection.settings['name'], "Simple lesana collection") + self.assertEqual(len(self.collection.settings['fields']), 3) self.collection.update_cache() self.assertIsNotNone(self.collection.cache) @@ -36,7 +36,7 @@ class testCollectionLoading(unittest.TestCase): self.assertIn("Invalid language", cm.output[0]) # The collection will default to english, but should still work. self.collection.update_cache() - self.assertIsNotNone(self.collection.schema) + self.assertIsNotNone(self.collection.settings) self.assertIsNotNone(self.collection.cache) self.assertIsNotNone(self.collection.stemmer) -- cgit v1.2.3