skeleton python project with tests.
This commit is contained in:
parent
2ef3a9166d
commit
dc8f42fc96
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
|
||||
#def process_template(in_f, out_f):
|
||||
|
||||
|
||||
def read_config(path):
|
||||
return json.loads(open(path).read())
|
||||
|
||||
|
||||
# given a root directory, return a list of tuples
|
||||
# containing input and output paths
|
||||
def template_paths(root):
|
||||
res = []
|
||||
for cur_root, subdirs, files in os.walk(root):
|
||||
for f in files:
|
||||
inout = ( os.path.join(cur_root, f), os.path.join(strip_prefix(root, cur_root), f) )
|
||||
res.append(inout)
|
||||
return res
|
||||
|
||||
def strip_prefix(prefix, s):
|
||||
return s[len(prefix):] if s.startswith(prefix) else s
|
|
@ -0,0 +1,18 @@
|
|||
try:
|
||||
from setuptools import setup
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
config = {
|
||||
'name': 'cornfig'
|
||||
'description': 'applies cornfiguration from cloud metadata.',
|
||||
'author': 'echohead',
|
||||
'url': 'github.com/echohead/cornfig',
|
||||
'version': '0.1',
|
||||
'install_requires': ['nose'],
|
||||
'packages': ['cornfig'],
|
||||
'scripts': [],
|
||||
'install_requires': ['pystache']
|
||||
}
|
||||
|
||||
setup(**config)
|
|
@ -0,0 +1,26 @@
|
|||
from nose.tools import *
|
||||
from cornfig.cornfig import *
|
||||
import os
|
||||
|
||||
TEMPLATES = os.path.join(os.path.dirname(__file__), 'templates')
|
||||
TEMPLATE_PATHS = ["/etc/keystone/keystone.conf"]
|
||||
|
||||
def setup():
|
||||
pass
|
||||
|
||||
def teardown():
|
||||
pass
|
||||
|
||||
def test_template_paths():
|
||||
expected = map(lambda p: (os.path.join(TEMPLATES, p[1:]), p), TEMPLATE_PATHS)
|
||||
assert template_paths(TEMPLATES) == expected
|
||||
|
||||
@raises(Exception)
|
||||
def test_read_config_bad_json():
|
||||
with tempfile.TemporaryFile() as t:
|
||||
t.write("{{{{")
|
||||
read_config(t.path)
|
||||
|
||||
@raises(Exception)
|
||||
def test_read_config_no_file():
|
||||
read_config("/nosuchfile")
|
|
@ -0,0 +1,2 @@
|
|||
adf
|
||||
asdf
|
Loading…
Reference in New Issue