Permalink
Browse files

Add requirements.txt and travisci config, fix broken tests

  • Loading branch information...
1 parent 70fad14 commit aada3b90be30d323c96c4096b62f1c1bf00c76a9 Sidnei da Silva committed May 8, 2012
Showing with 41 additions and 16 deletions.
  1. +10 −0 .travis.yml
  2. +7 −3 lib/carbon/conf.py
  3. +21 −13 lib/carbon/tests/test_conf.py
  4. +3 −0 requirements.txt
View
@@ -0,0 +1,10 @@
+# http://travis-ci.org/#!/graphite-project/carbon
+language: python
+python:
+ - 2.6
+ - 2.7
+install:
+ - pip install -r requirements.txt --use-mirrors
+ - python setup.py install --prefix=$VIRTUAL_ENV --install-lib=$VIRTUAL_ENV/lib/python$TRAVIS_PYTHON_VERSION/site-packages
+script:
+ - PYTHONPATH=lib trial carbon
View
@@ -449,7 +449,12 @@ def read_config(program, options, **kwargs):
for name, value in kwargs.items():
settings.setdefault(name, value)
- graphite_root = os.environ['GRAPHITE_ROOT']
+ graphite_root = kwargs.get("ROOT_DIR")
+ if graphite_root is None:
+ graphite_root = os.environ.get('GRAPHITE_ROOT')
+ if graphite_root is None:
+ raise ValueError("Either ROOT_DIR or GRAPHITE_ROOT "
+ "needs to be provided.")
# Default config directory to root-relative, unless overriden by the
# 'GRAPHITE_CONF_DIR' environment variable.
@@ -485,8 +490,7 @@ def read_config(program, options, **kwargs):
config = options["config"]
if not exists(config):
- print "Error: missing required config %s" % config
- sys.exit(1)
+ raise ValueError("Error: missing required config %r" % config)
settings.readFrom(config, section)
settings.setdefault("instance", options["instance"])
@@ -23,6 +23,12 @@ class FakeOptions(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
+ def __getitem__(self, name):
+ return self.__dict__[name]
+
+ def __setitem__(self, name, value):
+ self.__dict__[name] = value
+
class DefaultParserTest(TestCase):
@@ -40,7 +46,7 @@ def test_default_parser(self):
self.assertTrue(parser.has_option("--logdir"))
self.assertEqual(None, parser.defaults["logdir"])
self.assertTrue(parser.has_option("--instance"))
- self.assertEqual(None, parser.defaults["instance"])
+ self.assertEqual("a", parser.defaults["instance"])
class ParseOptionsTest(TestCase):
@@ -80,28 +86,29 @@ def test_root_dir_is_required(self):
At minimum, the caller must provide a 'ROOT_DIR' setting.
"""
try:
- read_config("carbon-foo", FakeOptions())
+ read_config("carbon-foo", FakeOptions(config=None))
except ValueError, e:
- self.assertEqual("ROOT_DIR needs to be provided.", e.message)
+ self.assertEqual("Either ROOT_DIR or GRAPHITE_ROOT "
+ "needs to be provided.", e.message)
else:
self.fail("Did not raise exception.")
def test_config_is_not_required(self):
"""
- If the '--config' option is not provided, it will default to the
- 'carbon.conf' file inside 'ROOT_DIR/conf'.
+ If the '--config' option is not provided, it defaults to
+ ROOT_DIR/conf/carbon.conf.
"""
root_dir = self.makeDir()
conf_dir = join(root_dir, "conf")
makedirs(conf_dir)
self.makeFile(content="[foo]",
basename="carbon.conf",
dirname=conf_dir)
- settings = read_config("carbon-foo",
- FakeOptions(config=None, instance=None,
- pidfile=None, logdir=None),
- ROOT_DIR=root_dir)
- self.assertEqual(conf_dir, settings.CONF_DIR)
+ options = FakeOptions(config=None, instance=None,
+ pidfile=None, logdir=None)
+ read_config("carbon-foo", options, ROOT_DIR=root_dir)
+ self.assertEqual(join(root_dir, "conf", "carbon.conf"),
+ options["config"])
def test_config_dir_from_environment(self):
"""
@@ -194,7 +201,8 @@ def test_log_dir_for_instance_relative_to_storage_dir(self):
FakeOptions(config=config, instance="x",
pidfile=None, logdir=None),
ROOT_DIR="foo")
- self.assertEqual(join("foo", "storage", "log", "carbon-foo-x"),
+ self.assertEqual(join("foo", "storage", "log",
+ "carbon-foo", "carbon-foo-x"),
settings.LOG_DIR)
def test_log_dir_for_instance_relative_to_provided_storage_dir(self):
@@ -209,7 +217,7 @@ def test_log_dir_for_instance_relative_to_provided_storage_dir(self):
FakeOptions(config=config, instance="x",
pidfile=None, logdir=None),
ROOT_DIR="foo", STORAGE_DIR="bar")
- self.assertEqual(join("bar", "log", "carbon-foo-x"),
+ self.assertEqual(join("bar", "log", "carbon-foo", "carbon-foo-x"),
settings.LOG_DIR)
def test_pidfile_relative_to_storage_dir(self):
@@ -343,4 +351,4 @@ def test_log_dir_from_instance_config(self):
FakeOptions(config=config, instance="x",
pidfile=None, logdir=None),
ROOT_DIR="foo")
- self.assertEqual("boo-x", settings.LOG_DIR)
+ self.assertEqual("boo/carbon-foo-x", settings.LOG_DIR)
View
@@ -0,0 +1,3 @@
+Twisted==11.1.0
+git+git://github.com/graphite-project/whisper.git#egg=whisper
+mocker==1.1

0 comments on commit aada3b9

Please sign in to comment.