Пример #1
0
class Test_ConfigUtil_FindingConfigFile(object):
    '''Test that the ConfigUtil class knows corner cases of finding a config file'''
    def setUp(self):
        self.config_util = ConfigUtil()
        self.fullpath = fudge.Fake('fullpath')
        self.filename = fudge.Fake('filename')

    @fudge.patch('os.path.exists', 'os.path.abspath')
    def test_it_complains_if_config_file_doesnt_exist(self, fake_exists, fake_abspath):
        self.config_util.values['config_file'] = self.filename
        fake_abspath.expects_call().with_args(self.filename).returns(self.fullpath)
        fake_exists.expects_call().with_args(self.fullpath).returns(False)

        finder = lambda : self.config_util.find_config_file()
        finder |should| throw(MissingConfigFile, "Config file doesn't exist at fake:fullpath")

    @fudge.patch('os.path.exists', 'os.path.abspath')
    def test_it_defaults_to_noyjson(self, fake_exists, fake_abspath):
        fake_abspath.expects_call().with_args('noy.json').returns(self.fullpath)
        fake_exists.expects_call().with_args(self.fullpath).returns(True)
        self.config_util.find_config_file() |should| equal_to(self.fullpath)

    @fudge.patch('os.path.exists', 'os.path.abspath')
    def test_it_doesnt_care_if_default_doesnt_exist(self, fake_exists, fake_abspath):
        fake_abspath.expects_call().with_args('noy.json').returns(self.fullpath)
        fake_exists.expects_call().with_args(self.fullpath).returns(False)
        self.config_util.find_config_file() |should| equal_to(None)

    @fudge.patch('os.path.exists', 'os.path.abspath')
    def test_it_doesnt_care_if_provided_default_doesnt_exist(self, fake_exists, fake_abspath):
        self.config_util.values['config_file'] = Default(self.filename)
        fake_abspath.expects_call().with_args(self.filename).returns(self.fullpath)
        fake_exists.expects_call().with_args(self.fullpath).returns(False)
        self.config_util.find_config_file() |should| equal_to(None)