예제 #1
0
    def test_load_file_invalid_syntax(self):
        '''Test _load_file() function with invalid syntax'''
        with pytest.raises(exc.CheckbConfigError):
            contents = StringIO(u'a single string (not dict)')
            config._load_file(contents)

        with pytest.raises(exc.CheckbConfigError):
            contents = StringIO(u'tab:\t #this is invalid in YAML')
            config._load_file(contents)
예제 #2
0
    def test_load_file_invalid_type(self):
        '''Test _load_file() function with invalid option type'''
        # tmpdir is string, with string it should pass
        contents = StringIO(u'tmpdir: foo')
        config._load_file(contents)

        # but with anything else, it should fail
        with pytest.raises(exc.CheckbConfigError):
            contents = StringIO(u'tmpdir: False')
            config._load_file(contents)
예제 #3
0
    def test_load_file_commented(self):
        '''Test _load_file() function with fully commented out file'''
        contents = StringIO(u'''
# first commented line
# second: line
# last line
        ''')
        conf_object = config._load_file(contents)
        assert conf_object == {}
예제 #4
0
    def test_load_file_options(self):
        '''Test _load_file() function with some options present'''
        contents = StringIO(u'''# a header comment
option1: value1
# option2: value2
option3: 15
option4: ''
option5: False''')
        conf_object = config._load_file(contents)
        assert {
            'option1': 'value1',
            'option3': 15,
            'option4': '',
            'option5': False
        } == conf_object
예제 #5
0
 def test_load_file_empty(self):
     '''Test _load_file() function with empty file'''
     contents = StringIO(u'')
     conf_object = config._load_file(contents)
     assert conf_object == {}