def test_subcontext_lookup_success(self, path, expected_result): # type: (Tuple[str, ...], List[int]) -> None ec = EvaluationContext(self.table_context) ec.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table')), EMPTY_NODE) ec.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table2')), EMPTY_NODE) subcontext = EvaluationContext(self.table_context) subcontext.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table3')), EMPTY_NODE) ec.add_subcontext(subcontext) result = ec.lookup(path) self.assertEqual(list(result.series), expected_result) self.assertEqual(result.type_, BQScalarType.INTEGER)
def test_subcontext_lookup_error_already_has_subcontext(self): # type: () -> None ec = EvaluationContext(self.table_context) ec.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table')), EMPTY_NODE) ec.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table2')), EMPTY_NODE) subcontext1 = EvaluationContext(self.table_context) subcontext1.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table3')), EMPTY_NODE) ec.add_subcontext(subcontext1) subcontext2 = EvaluationContext(self.table_context) subcontext2.add_table_from_node( TableReference(('my_project', 'my_dataset', 'my_table4')), EMPTY_NODE) with self.assertRaisesRegexp(ValueError, 'Context already has subcontext'): ec.add_subcontext(subcontext2)