class TestExternalTable: def setup(self): self.archive = Archive('tests', Hive()) @raises(TemplateNotFound) def test_missing_hql(self): misnamed = self.archive.add(ExternalTable( 'atomic', 'misnamed' )) misnamed.hql() def test_graph(self): events = self.archive.add(ExternalTable( 'atomic', 'events', partitioned=True )) assert_equal('ExternalTable(atomic.events)', events.graph()) def test_partitioning(self): pattern = re.compile('.*RECOVER PARTITIONS', re.DOTALL) events = self.archive.add(ExternalTable( 'atomic', 'events', partitioned=True )) assert_true(pattern.match(events.create_hql())) # Reset Archive self.setup() events = self.archive.add(ExternalTable( 'atomic', 'events' )) assert_is_none(pattern.match(events.create_hql()))
class TestArchive: def setup(self): self.archive = Archive('tests', Hive()) self.events = ExternalTable( 'atomic', 'events', partitioned=True ) def test_lookup(self): self.archive.add(self.events) events = self.archive.lookup('events') assert_is_not_none(events) assert_equal('events', events.name) assert_equal(self.events, events) @raises(KeyError) def test_missing_lookup(self): self.archive.lookup('doesnotexist') @raises(RuntimeError) def test_unique_names(self): self.archive.add(self.events) self.archive.add(self.events) @raises(RuntimeError) def test_missing_input(self): self.archive.add(self.events) doesnotexist = View( 'atomic', 'doesnotexist', self.events ) self.archive.add(View( 'atomic', 'missing_input', doesnotexist )) def test_graph(self): self.archive.add(self.events) assert_equal( 'Archive: tests\nExternalTable(atomic.events)', self.archive.graph() ) def test_stats(self): self.archive.add(self.events) stats = self.archive.optimize() assert_equal(1, stats['archive']['databases']) assert_equal(1, stats['archive']['depth']) assert_equal(1, stats['archive']['queries']) assert_equal(1, stats['databases']['references']['atomic']) assert_equal(set(['atomic']), stats['databases']['unique_databases']) assert_equal(1, stats['queries']['references']['events']) assert_equal(set(['events']), stats['queries']['unique_queries'])