aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin W. Smith <benjaminwarfield@just-another.net>2009-11-07 18:54:45 -0500
committerBenjamin W. Smith <benjaminwarfield@just-another.net>2009-11-07 18:54:45 -0500
commitb957efd57065b350a7e32fea5d70aae4bfccd33f (patch)
tree6e8f39ef95868d5e323b3d1c5501f33d562dda3d
parent077d64b5b49673b79cd99b9abc410f5b486a9e4c (diff)
downloadmrbelvedere-b957efd57065b350a7e32fea5d70aae4bfccd33f.tar.bz2
mrbelvedere-b957efd57065b350a7e32fea5d70aae4bfccd33f.tar.xz
mrbelvedere-b957efd57065b350a7e32fea5d70aae4bfccd33f.zip
Stub out template parser tests and code. Ignore .swp files (why hadn't I done that before?!)HEADmaster
-rw-r--r--.hgignore1
-rw-r--r--mrbelvedere/template_parser.py22
-rw-r--r--tests/test_template_parser.py36
3 files changed, 59 insertions, 0 deletions
diff --git a/.hgignore b/.hgignore
index f9ae076..a1f944b 100644
--- a/.hgignore
+++ b/.hgignore
@@ -1,5 +1,6 @@
1\.pyc$ 1\.pyc$
2\.coverage$ 2\.coverage$
3\.swp$
3^build$ 4^build$
4^dist$ 5^dist$
5^build$ 6^build$
diff --git a/mrbelvedere/template_parser.py b/mrbelvedere/template_parser.py
new file mode 100644
index 0000000..6217d30
--- /dev/null
+++ b/mrbelvedere/template_parser.py
@@ -0,0 +1,22 @@
1""" Parse build templates
2"""
3import yaml
4
5
6class TemplateParser(object):
7
8 def __init__(self):
9 self.yaml = yaml
10 self._current_template_file = None
11 self.template_data = None
12
13 @property
14 def template_file(self):
15 return self._current_template_file
16
17 @template_file.setter
18 def template_file(self, file):
19 self._current_template_file = open(file)
20
21 def load_template(self):
22 self.template_data = self.yaml.load(self.template_file.read()).get('template')
diff --git a/tests/test_template_parser.py b/tests/test_template_parser.py
new file mode 100644
index 0000000..5cb6e2b
--- /dev/null
+++ b/tests/test_template_parser.py
@@ -0,0 +1,36 @@
1#!/usr/bin/env python
2from dingus import Dingus, DingusTestCase, DontCare
3import nose.tools as nose_tools
4from mrbelvedere import template_parser
5from mrbelvedere.template_parser import TemplateParser
6import yaml
7
8class WhenSettingUp(DingusTestCase(TemplateParser, exclude=['yaml'])):
9
10 def setup(self):
11 super(WhenSettingUp, self).setup()
12 self.template_parser = TemplateParser()
13
14 def should_setup_yaml(self):
15 assert isinstance(self.template_parser.yaml, type(yaml))
16
17 def should_degine_template_data_attribute(self):
18 assert self.template_parser.template_data is None
19
20 def should_define_file_attribute(self):
21 assert self.template_parser._current_template_file is None
22
23 def should_set_file_to_parse(self):
24 self.template_parser.template_file = 'examples/webserver.yaml'
25 assert self.template_parser.template_file is not None
26
27 def should_load_template(self):
28 self.template_parser.template_file = 'examples/webserver.yaml'
29 self.template_parser.load_template()
30 assert self.template_parser.template_data is not None
31
32 def should_raise_io_error(self):
33 try:
34 self.template_parser.template_file = 'examples/invalid_template.yaml'
35 except IOError:
36 assert True