def test_parsable_setup_parsing(): """Test Parsable setup_parsing() method.""" the_file = Parsable() Parsable.read = utils.mock_read_data the_file.data = FILE the_file.setup_parsing({ 'htdocs' : ('DocumentRoot (.*)',), 'debug' : 'DEBUG = (.*)', 'secure' : ('SECURE[ ]*=[ ]*([^ \n]*)', 'SECURE = {0}'), 'speed' : ('SPEED[ ]*=[ ]*([^ \n]*)', 'SPEED = {0}'), 'list' : ('LIST[ ]*=[ ]*([^ \n]*)', 'LIST = {0}'), }) assert the_file.htdocs[0] == '/var/www/google.com' assert the_file.htdocs[1] == '/var/www/example.com' assert the_file.debug == 'True' assert the_file.secure == 'False' the_file.secure = 'True' assert the_file.secure == 'True' assert the_file.speed is None the_file.speed = 'fastest' assert the_file.speed == 'fastest' the_file.speed = 'fastest' # setting it more than once with the same value # shouldn't affect the number of times it is added. assert isinstance(the_file.speed, str) \ or isinstance(the_file.speed, unicode) # Shouldn't be a list, checking unicode # for Python 2 support. assert len(the_file.list) == 2 # Should be a list
def test_parsable_setup_parsing_on_empty_file(): """Test Parsable setup_paring() using an empty file.""" the_file = Parsable() Parsable.read = utils.mock_read_data the_file.data = EMPTY_FILE the_file.setup_parsing({ 'htdocs' : ('DocumentRoot (.*)', 'DocumentRoot {0}'), 'secure' : ('SECURE[ ]*=[ ]*([^ \n]*)', 'SECURE = {0}'), }) assert the_file.htdocs is None the_file.htdocs = '/var/www/google.com' assert the_file.htdocs == '/var/www/google.com' assert the_file.secure is None the_file.secure = 'True' assert the_file.secure == 'True'