def testOptions(self): with option_context() as local_options: self.assertIsNone(local_options.access_id, None) self.assertIsNone(local_options.access_key, None) self.assertIsNone(local_options.end_point, None) self.assertIsNone(local_options.default_project, None) self.assertIsNone(local_options.log_view_host, None) self.assertIsNone(local_options.tunnel_endpoint, None) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) local_options.access_id = 'test' self.assertEqual(local_options.access_id, 'test') local_options.register_option('nest.inner.value', 50) self.assertEqual(local_options.nest.inner.value, 50) self.assertIsNone(options.access_id, None) self.assertIsNone(options.access_key, None) self.assertIsNone(options.end_point, None) self.assertIsNone(options.default_project, None) self.assertIsNone(options.log_view_host, None) self.assertIsNone(options.tunnel_endpoint, None) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertRaises(AttributeError, lambda: options.nest.inner.value)
def testProjection(self): projected = self.expr['name', self.expr.id.rename('new_id')] self.assertIsInstance(projected, CollectionExpr) self.assertEqual( projected._schema, Schema.from_lists(['name', 'new_id'], [types.string, types.int64])) projected = self.expr[[self.expr.name, self.expr.id.astype('string')]] self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual( projected._schema, Schema.from_lists(['name', 'id'], [types.string, types.string])) self.assertRaises(ExpressionError, lambda: self.expr[[self.expr.id + self.expr.fid]]) with option_context() as options: options.interactive = True self.assertRaises( ExpressionError, lambda: self.expr['name', 'id'][[ self.expr.name, ]])
def testOptions(self): old_config = Config(deepcopy(options._config)) with option_context() as local_options: if options.account is None: self.assertEqual(options.account, old_config.account) else: self.assertEqual(options.account.access_id, old_config.account.access_id) self.assertEqual(options.account.secret_access_key, old_config.account.secret_access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.account = AliyunAccount('test', '') self.assertEqual(local_options.account.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator(is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) if options.account is None: self.assertEqual(options.account, old_config.account) else: self.assertEqual(options.account.access_id, old_config.account.access_id) self.assertEqual(options.account.secret_access_key, old_config.account.secret_access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive) def set_notexist(): options.display.val = 3 self.assertRaises(OptionError, set_notexist)
def testProjection(self): projected = self.expr['name', self.expr.id.rename('new_id')] self.assertIsInstance(projected, CollectionExpr) self.assertEqual( projected._schema, Schema.from_lists(['name', 'new_id'], [types.string, types.int64])) projected = self.expr[[self.expr.name, self.expr.id.astype('string')]] self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual( projected._schema, Schema.from_lists(['name', 'id'], [types.string, types.string])) projected = self.expr.select(self.expr.name, Scalar('abc').rename('word'), size=5) self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual( projected._schema, Schema.from_lists(['name', 'word', 'size'], [types.string, types.string, types.int8])) self.assertIsInstance(projected._fields[1], StringScalar) self.assertEqual(projected._fields[1].value, 'abc') self.assertIsInstance(projected._fields[2], Int8Scalar) self.assertEqual(projected._fields[2].value, 5) expr = self.expr[lambda x: x.exclude('id')] self.assertEqual(expr.schema.names, [n for n in expr.schema.names if n != 'id']) self.assertRaises( ExpressionError, lambda: self.expr[self.expr.distinct('id', 'fid'), 'name']) self.assertRaises(ExpressionError, lambda: self.expr[[self.expr.id + self.expr.fid]]) with option_context() as options: options.interactive = True self.expr['name', 'id'][[ self.expr.name, ]] self.assertRaises(ExpressionError, lambda: self.expr[self.expr.name]) self.assertRaises( ExpressionError, lambda: self.expr['name', self.expr.groupby('name').id.sum()]) expr = self.expr.filter(self.expr.id < 0) expr[self.expr.name, self.expr.id]
def testDumpAndLoad(self): with option_context() as local_options: local_options.register_option('test.value', 50, validator=any_validator( is_null, is_integer)) d = local_options.dumps() self.assertEqual(d['test.value'], 50) d['test.value'] = 100 local_options.loads(d) self.assertEqual(local_options.test.value, 100)
def testOptions(self): old_config = Config(deepcopy(options._config)) with option_context() as local_options: self.assertEqual(options.access_id, old_config.access_id) self.assertEqual(options.access_key, old_config.access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.access_id = 'test' self.assertEqual(local_options.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator(is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) self.assertEqual(options.access_id, old_config.access_id) self.assertEqual(options.access_key, old_config.access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive) def set_notexist(): options.display.val = 3 self.assertRaises(OptionError, set_notexist)
def testOptions(self): with option_context() as local_options: self.assertIsNone(local_options.access_id) self.assertIsNone(local_options.access_key) self.assertIsNone(local_options.end_point) self.assertIsNone(local_options.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.access_id = 'test' self.assertEqual(local_options.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator( is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) self.assertIsNone(options.access_id) self.assertIsNone(options.access_key) self.assertIsNone(options.end_point) self.assertIsNone(options.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive)
def inner(self, *args, **kwargs): try: import cython ts = 'py', 'c' except ImportError: ts = 'py', import warnings warnings.warn('No c code tests for crc32c') for t in ts: with option_context() as options: setattr(options, 'force_{0}'.format(t), True) reload_module(_crc) if t == 'py': self.assertEquals(_crc.Crc32c._method, t) else: self.assertFalse(hasattr(_crc.Crc32c, '_method')) func(self, *args, **kwargs)
def testProjection(self): projected = self.expr['name', self.expr.id.rename('new_id')] self.assertIsInstance(projected, CollectionExpr) self.assertEqual(projected._schema, Schema.from_lists(['name', 'new_id'], [types.string, types.int64])) projected = self.expr[[self.expr.name, self.expr.id.astype('string')]] self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual(projected._schema, Schema.from_lists(['name', 'id'], [types.string, types.string])) self.assertRaises(ExpressionError, lambda: self.expr[[self.expr.id + self.expr.fid]]) with option_context() as options: options.interactive = True self.assertRaises(ExpressionError, lambda: self.expr['name', 'id'][[self.expr.name, ]])
def testProjection(self): projected = self.expr['name', self.expr.id.rename('new_id')] self.assertIsInstance(projected, CollectionExpr) self.assertEqual(projected._schema, Schema.from_lists(['name', 'new_id'], [types.string, types.int64])) projected = self.expr[[self.expr.name, self.expr.id.astype('string')]] self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual(projected._schema, Schema.from_lists(['name', 'id'], [types.string, types.string])) projected = self.expr.select(self.expr.name, Scalar('abc').rename('word'), size=5) self.assertIsInstance(projected, ProjectCollectionExpr) self.assertEqual(projected._schema, Schema.from_lists(['name', 'word', 'size'], [types.string, types.string, types.int8])) self.assertIsInstance(projected._fields[1], StringScalar) self.assertEqual(projected._fields[1].value, 'abc') self.assertIsInstance(projected._fields[2], Int8Scalar) self.assertEqual(projected._fields[2].value, 5) expr = self.expr[lambda x: x.exclude('id')] self.assertEqual(expr.schema.names, [n for n in expr.schema.names if n != 'id']) self.assertRaises(ExpressionError, lambda: self.expr[self.expr.distinct('id', 'fid'), 'name']) self.assertRaises(ExpressionError, lambda: self.expr[[self.expr.id + self.expr.fid]]) with option_context() as options: options.interactive = True self.assertRaises(ExpressionError, lambda: self.expr['name', 'id'][[self.expr.name, ]]) self.assertRaises(ExpressionError, lambda: self.expr[self.expr.name]) self.assertRaises(ExpressionError, lambda: self.expr['name', self.expr.groupby('name').id.sum()])