[mousetrap/gnome3-wip: 231/240] Add more tests for mousetrap.config.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 231/240] Add more tests for mousetrap.config.
- Date: Mon, 8 Sep 2014 15:31:59 +0000 (UTC)
commit 82200ec152f04960c9df6bea7c20903f298ad469
Author: Stoney Jackson <dr stoney gmail com>
Date: Mon Jun 30 23:34:36 2014 -0400
Add more tests for mousetrap.config.
src/mousetrap/config.py | 3 ++
src/mousetrap/tests/test_config.py | 56 ++++++++++++++++++++++++++++++++++-
src/mousetrap/tests/test_core.py | 2 +-
3 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/src/mousetrap/config.py b/src/mousetrap/config.py
index d8959bc..8e47b07 100644
--- a/src/mousetrap/config.py
+++ b/src/mousetrap/config.py
@@ -22,6 +22,9 @@ class Config(dict):
_rmerge(self, config)
return self
+ def load_dict(self, dictionary):
+ _rmerge(self, dictionary)
+
def __getitem__(self, key):
'''
Allow access to class configuration by passing instance of class as
diff --git a/src/mousetrap/tests/test_config.py b/src/mousetrap/tests/test_config.py
index 00f4688..a18b59e 100644
--- a/src/mousetrap/tests/test_config.py
+++ b/src/mousetrap/tests/test_config.py
@@ -51,7 +51,59 @@ class test__rmerge(unittest.TestCase):
class test_Config(unittest.TestCase):
def setUp(self):
- self.config = Config().load_default()
+ self.config = Config()
+ self.files = Files()
+
+ def tearDown(self):
+ self.files.delete()
+
+ def test_load_default(self):
+ self.config.load_default()
+ self.assertIsInstance(self.config['assembly'], list)
def test_load(self):
- self.assertTrue(isinstance(self.config['assembly'], list))
+ self.files.write('f1',\
+"""
+x: 1
+y: 2
+""")
+ self.files.write('f2',\
+"""
+x: 3
+z: 4
+""")
+ self.config.load([self.files.path('f1'), self.files.path('f2')])
+ self.assertEquals({'x': 3, 'y': 2, 'z': 4}, self.config)
+
+ def test_classes_config(self):
+ self.config.load_dict({
+ 'classes': {
+ self.__class__.__module__ + '.' + self.__class__.__name__: {
+ 'x': 4}}})
+ self.assertEquals(4, self.config[self]['x'])
+
+
+class Files(object):
+ def __init__(self, directory=None):
+ if directory is None:
+ directory = __file__ + '.data'
+ from os.path import exists
+ from os import mkdir
+ if not exists(directory):
+ mkdir(directory)
+ self.directory = directory
+
+ def write(self, file_name, data):
+ with open(self.path(file_name), 'w') as data_file:
+ data_file.write(data)
+
+ def read(self, file_name, data):
+ with open(self.path(file_name), 'r') as data_file:
+ return data_file.read()
+
+ def path(self, file_name):
+ return self.directory + '/' + file_name
+
+ def delete(self):
+ from shutil import rmtree
+ rmtree(self.directory)
diff --git a/src/mousetrap/tests/test_core.py b/src/mousetrap/tests/test_core.py
index 0345894..a4f9b37 100644
--- a/src/mousetrap/tests/test_core.py
+++ b/src/mousetrap/tests/test_core.py
@@ -2,7 +2,7 @@ import unittest
from mousetrap.core import Loop, Observable
-class test_observable(unittest.TestCase):
+class test_Observable(unittest.TestCase):
def setUp(self):
self.observable = Observable()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]