view tests/unit.py @ 30:b27a7cb2dd5b

stub test for configuration providers
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Mar 2012 17:05:02 -0700
parents c516ab813079
children da4d5c5831c6
line wrap: on
line source

#!/usr/bin/env python

"""
unit tests
"""

import configuration
import os
import sys
import unittest

from example import ExampleConfiguration # example configuration to test

# globals
here = os.path.dirname(os.path.abspath(__file__))

class ConfigurationUnitTest(unittest.TestCase):

    def test_cli(self):
        """test command line interface"""

        example = ExampleConfiguration()

        # parse command line arguments
        options, args = example.parse(['-a', 'ts', '--develop', '-e', '/home/jhammel/bin/firefox'])

        # ensure that the options appropriately get set
        self.assertEqual(bool(args), False) # no arguments
        self.assertEqual(options.develop, True)
        self.assertEqual(options.activeTests, ['ts'])
        self.assertEqual(options.browser_path, '/home/jhammel/bin/firefox')

        # ensure that the configuration appropriately gets updated
        self.assertEqual(example.config['develop'], True)
        self.assertEqual(example.config['activeTests'], ['ts'])
        self.assertEqual(example.config['browser_path'], '/home/jhammel/bin/firefox')

    def test_configuration_providers(self):
        """test file-based configuration providers"""
        # require json/simplejson and pyyaml to be installed

        example = ExampleConfiguration()

        # see what providers you got
        json_provider = example.configuration_provider('json')
        self.assertTrue(isinstance(json_provider, configuration.JSON))

if __name__ == '__main__':
    unittest.main()