def testTaskClassType(self): typed = Task(type='SQL', query='select * from dual') self.assertIsInstance(typed, SQLTask) unknown_typed = Task(type='UnknownType') self.assertIs(type(unknown_typed), Task) self.assertRaises(ODPSError, lambda: unknown_typed.serialize()) untyped = Task() self.assertIs(type(untyped), Task) self.assertRaises(ODPSError, lambda: untyped.serialize())
def testSQLCostTaskToXML(self): query = 'select * from dual' task = SQLCostTask(query=query) to_xml = task.serialize() right_xml = sql_cost_template % {'sql': query} self.assertEqual(to_str(to_xml), to_str(right_xml)) task = Task.parse(None, to_xml) self.assertIsInstance(task, SQLCostTask)
def testCupidTaskToXML(self): task = CupidTask('task_1', 'plan_text', {'odps.cupid.wait.am.start.time': 600}) to_xml = task.serialize() right_xml = cupid_template self.assertEqual(to_str(to_xml), to_str(right_xml)) task = Task.parse(None, to_xml) self.assertIsInstance(task, CupidTask)
def testMergeTaskToXML(self): task = MergeTask('task_1', table='table_name') task.update_settings({'odps.merge.cross.paths': True}) to_xml = task.serialize() right_xml = merge_template % dict(name='task_1', table='table_name') self.assertEqual(to_str(to_xml), to_str(right_xml)) task = Task.parse(None, to_xml) self.assertIsInstance(task, MergeTask)
def testSQLTaskToXML(self): query = 'select * from dual' task = SQLTask(query=query) to_xml = task.serialize() right_xml = template % {'sql': query} self.assertEqual(to_str(to_xml), to_str(right_xml)) task = Task.parse(None, to_xml) self.assertIsInstance(task, SQLTask)