def get_config(cls, config=None, files=None, use_local=True, use_profile=True): """ Gets a config, checking the project local config, the user-set profile, and any addition files. """ if isinstance(config, cls): return config if isinstance(config, dict): return cls(**config) files = files or () return cls().merge( cls.read_from_file(filename) for use, filename in chain( ((use_profile, cls.get_profile()), (use_local, cls.get_local())), zip(repeat(True), files), ) if use )
def test_file_cache_from_disk(self): """ Asserts that the disk caching works. """ # We will use this file, as it is the only file we know that exists. # The first time this is run after a change, __file__ will point to # the source code file; however, if we run this twice in a row, it # points to the byte-compiled file. filename = fix_filename(__file__) db = Qdb(cmd_manager=NopCommandManager()) db.cache_file(filename) with open(filename) as f: contents = f.read()[:-1] # Drop the last newline. # Assert that querying the entire file works. self.assertEqual(db.get_file(filename), contents) for n, line in zip(count(start=1), contents.splitlines()): # Iterate over all the lines of the file, asserting that we # have saved them correctly. This also asserts that the line # indexing is working as intended. self.assertEqual(db.get_line(filename, n), line)
def test_file_cache_from_disk(self): """ Asserts that the disk caching works. """ # We will use this file, as it is the only file we know that exists. # The first time this is run after a change, __file__ will point to # the source code file; however, if we run this twice in a row, it # points to the byte-compiled file. filename = fix_filename(__file__) db = Qdb(cmd_manager=NopCommandManager()) db.cache_file(filename) with open(filename) as f: contents = f.read()[:-1] # Drop the last newline. # Assert that querying the entire file works. self.assertEquals(db.get_file(filename), contents) for n, line in zip(count(start=1), contents.splitlines()): # Iterate over all the lines of the file, asserting that we # have saved them correctly. This also asserts that the line # indexing is working as intended. self.assertEquals(db.get_line(filename, n), line)