def all_models(cls): if not hasattr(Alerted, "_all_models"): Alerted._all_models = { cls.__tablename__: cls for cls in util.collect_subclasses(db.Model) } return Alerted._all_models
def tearDown(self): self.teardown() try: from corral import util, db with db.session_scope() as session: for model in util.collect_subclasses(db.Model): session.query(model).delete() except Exception: pass
def tearDown(self): self.teardown() try: from corral import util, db with db.session_scope() as session: for model in util.collect_subclasses(db.Model): session.query(model).delete() except: pass
def test_collect_subclasses(self): class Base(object): pass class Level1(Base): pass class Level2(Level1): pass actual = util.collect_subclasses(Base) expected = (Level1, Level2) self.assertCountEqual(actual, expected)
def run_tests(verbosity=1, failfast=False): """Run test of corral""" suite = unittest.TestSuite() loader = unittest.TestLoader() runner = unittest.runner.TextTestRunner( verbosity=verbosity, failfast=failfast) load_test_modules() for testcase in util.collect_subclasses(base.BaseTest): tests = loader.loadTestsFromTestCase(testcase) if tests.countTestCases(): suite.addTests(tests) return runner.run(suite)
def run_tests(verbosity=1, failfast=False): """Run test of corral""" suite = unittest.TestSuite() loader = unittest.TestLoader() runner = unittest.runner.TextTestRunner(verbosity=verbosity, failfast=failfast) load_test_modules() for testcase in util.collect_subclasses(base.BaseTest): tests = loader.loadTestsFromTestCase(testcase) if tests.countTestCases(): suite.addTests(tests) return runner.run(suite)
def setup(self): self.tn2model = { sc.__tablename__: sc for sc in util.collect_subclasses(db.Model)}
def setup(self): self.tn2model = { sc.__tablename__: sc for sc in util.collect_subclasses(db.Model) }
def all_models(cls): if not hasattr(Alerted, "_all_models"): Alerted._all_models = { cls.__tablename__: cls for cls in util.collect_subclasses(db.Model)} return Alerted._all_models
def write_row(self, row, idx): raise NotImplementedError() @abc.abstractmethod def teardown(self, fp): raise NotImplementedError() class CSV(Writer): def setup(self, fp): self.writer = csv.writer(fp) def write_row(self, row, idx): return self.writer.writerow(row) def teardown(self, fp): pass # ============================================================================= # FUNCTIONS # ============================================================================= _WRITERS = {cls.fmt(): cls for cls in util.collect_subclasses(Writer)} def create_writer(fmt, query, columns): if fmt not in expressions.DOWNLOAD_FORMATS: raise ValueError("Invalid Format '{}'".format(fmt)) return _WRITERS[fmt](query, columns)