def setUp(self): self.parser = cli.setup_parser() self.profile_path = tempfile.mkdtemp() profile = Profile(self.profile_path, 'testing') self.db = profile.get_database() for talk in self.presentations: self.db.insert_presentation(talk)
class TestProfile(unittest.TestCase): """Tests Profile.""" def setUp(self): self.profile_path = tempfile.mkdtemp() self.profile = Profile(self.profile_path, 'testing') def tearDown(self): shutil.rmtree(self.profile_path) def test_get_filepath(self): """Tests that get_filepath(...) returns a path prefixed with the profile's folder.""" filepath = self.profile.get_filepath('testing.db') self.assertTrue(filepath.startswith(self.profile_path)) def test_get_storage_valid_suffix(self): """Tests that get_storage(...) returns the correct ConfigStorage class for a particular file suffix.""" json_storage = self.profile.get_storage('testing.json') self.assertIsInstance(json_storage, JSONConfigStorage) config_parser_storage = self.profile.get_storage('testing.conf') self.assertIsInstance(config_parser_storage, ConfigParserStorage) def test_get_storage_cache(self): """Tests that get_storage(...) caches ConfigStorage instances properly.""" storage1 = self.profile.get_storage('testing.conf') storage2 = self.profile.get_storage('testing.conf') self.assertEqual(storage1, storage2) def test_get_storage_invalid_suffix(self): """Tests that get_storage(...) does not accept an invalid filename suffix.""" self.assertRaises(KeyError, self.profile.get_storage, ('testing.json,')) def test_get_config(self): """Tests that get_config(...) returns the correct config instance and that it is .save()-able.""" config = self.profile.get_config('testing.conf', TestConfig, storage_args=['this_section']) self.assertIsInstance(config, TestConfig) self.assertIsNone(config.save()) def test_get_config_read_only(self): """Tests that get_config(...) returns a read-only config instance.""" config = self.profile.get_config('testing.conf', TestConfig, storage_args=['this_section'], read_only=True) self.assertIsInstance(config, TestConfig) self.assertRaises(StorageNotSetError, config.save) def test_get_database(self): """Tests that get_database(...) returns an instance of QtDBConnector.""" database = self.profile.get_database('testing.db') self.assertIsInstance(database, QtDBConnector) def test_get_database_cache(self): """Tests that get_database(...) caches QtDBConnector properly.""" database1 = self.profile.get_database('testing.db') database2 = self.profile.get_database('testing.db') self.assertEqual(database1, database2)
def setUp(self): ''' Stardard init method: runs before each test_* method Initializes a PluginManager ''' self.profile_path = tempfile.mkdtemp() profile = Profile(self.profile_path, 'testing') dirname = os.path.dirname(__file__) self._csvfile = os.path.join(dirname, 'sample_talks.csv') db_file = os.path.join(self.profile_path, 'presentations.db') self.db = QtDBConnector(db_file, PluginManager(profile))
def setUp(self): self.profile_path = tempfile.mkdtemp() self.profile = Profile(self.profile_path, 'testing')