add test of YamlData.from_string
diff --git a/reclass/storage/tests/test_yamldata.py b/reclass/storage/tests/test_yamldata.py
new file mode 100644
index 0000000..d8129ce
--- /dev/null
+++ b/reclass/storage/tests/test_yamldata.py
@@ -0,0 +1,37 @@
+#
+# -*- coding: utf-8 -*-
+#
+# This file is part of reclass (http://github.com/madduck/reclass)
+#
+
+from reclass.storage.yamldata import YamlData
+
+import unittest
+
+class TestYamlData(unittest.TestCase):
+
+ def setUp(self):
+ lines = [ 'classes:',
+ ' - testdir.test1',
+ ' - testdir.test2',
+ ' - test3',
+ '',
+ 'environment: base',
+ '',
+ 'parameters:',
+ ' _TEST_:',
+ ' alpha: 1',
+ ' beta: two' ]
+ self.data = '\n'.join(lines)
+ self.yamldict = { 'classes': [ 'testdir.test1', 'testdir.test2', 'test3' ],
+ 'environment': 'base',
+ 'parameters': { '_TEST_': { 'alpha': 1, 'beta': 'two' } }
+ }
+
+ def test_yaml_from_string(self):
+ res = YamlData.from_string(self.data, 'testpath')
+ self.assertEqual(res.uri, 'testpath')
+ self.assertEqual(res.get_data(), self.yamldict)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/reclass/storage/yamldata.py b/reclass/storage/yamldata.py
index 6894308..b28db06 100644
--- a/reclass/storage/yamldata.py
+++ b/reclass/storage/yamldata.py
@@ -68,13 +68,17 @@
exports = datatypes.Exports(exports)
if name is None:
- name = self._path
+ name = self._uri
env = self._data.get('environment', None)
return datatypes.Entity(classes, applications, parameters, exports,
name=name, environment=env, uri=self.uri)
+ def __str__(self):
+ return '<{0} {1}, {2}>'.format(self.__class__.__name__, self._uri,
+ self._data)
+
def __repr__(self):
- return '<{0} {1}, {2}>'.format(self.__class__.__name__, self._path,
+ return '<{0} {1}, {2}>'.format(self.__class__.__name__, self._uri,
self._data.keys())