Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
    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)
Пример #5
0
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)
Пример #6
0
    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)
Пример #7
0
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)
Пример #8
0
 def setup(self):
     self.tn2model = {
         sc.__tablename__: sc for sc in util.collect_subclasses(db.Model)}
Пример #9
0
 def setup(self):
     self.tn2model = {
         sc.__tablename__: sc
         for sc in util.collect_subclasses(db.Model)
     }
Пример #10
0
 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
Пример #11
0
    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)