Here are the examples of the python api sqlalchemy.types.Numeric taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
Example 1
def test_numeric(self):
from sqlalchemy import Column, types
column = Column('_column', types.Numeric)
elements = self._get_elements((('column', column),))
self.assertEqual(len(elements), 1)
self.assertEqual(elements[0].attrib, {
'minOccurs': '0',
'name': 'column',
'nillable': 'true',
'type': 'xsd:decimal'})
3
Example 2
def test_numeric_precision(self):
from sqlalchemy import Column, types
column = Column('_column', types.Numeric(precision=5))
elements = self._get_elements((('column', column),))
self.assertEqual(len(elements), 1)
self.assertEqual(elements[0].attrib, {
'minOccurs': '0',
'name': 'column',
'nillable': 'true'})
restrictions = elements[0].findall(
self._make_xpath('. simpleType restriction'))
self.assertEqual(len(restrictions), 1)
self.assertEqual(restrictions[0].attrib, {'base': 'xsd:decimal'})
totalDigitss = restrictions[0].findall(
self._make_xpath('. totalDigits'))
self.assertEqual(len(totalDigitss), 1)
self.assertEqual(totalDigitss[0].attrib, {'value': '5'})
3
Example 3
def test_numeric_scale(self):
from sqlalchemy import Column, types
column = Column('_column', types.Numeric(scale=2))
elements = self._get_elements((('column', column),))
self.assertEqual(len(elements), 1)
self.assertEqual(elements[0].attrib, {
'minOccurs': '0',
'name': 'column',
'nillable': 'true'})
restrictions = elements[0].findall(
self._make_xpath('. simpleType restriction'))
self.assertEqual(len(restrictions), 1)
self.assertEqual(restrictions[0].attrib, {'base': 'xsd:decimal'})
fractionDigitss = restrictions[0].findall(
self._make_xpath('. fractionDigits'))
self.assertEqual(len(fractionDigitss), 1)
self.assertEqual(fractionDigitss[0].attrib, {'value': '2'})
0
Example 4
def __init__(self, *args, **kwargs):
if self.impl == types.Numeric:
kwargs['scale'] = 28
kwargs['precision'] = 1000
types.TypeDecorator.__init__(self, *args, **kwargs)
0
Example 5
Project: python-sync-db Source File: codec_tests.py
def test_encode_numeric():
num = decimal.Decimal('3.3')
e = encode(types.Numeric())
d = decode(types.Numeric())
assert num == d(e(num))
0
Example 6
Project: python-sync-db Source File: codec_tests.py
def test_encode_float_numeric():
num = 3.3
e = encode(types.Numeric(asdecimal=False))
d = decode(types.Numeric(asdecimal=False))
assert num == d(e(num))
0
Example 7
def is_numeric(self, col_name):
try:
return isinstance(self.list_columns[col_name].type, sa.types.Numeric)
except:
return False
0
Example 8
Project: papyrus Source File: test_renderers.py
def test_numeric_precision_scale(self):
from sqlalchemy import Column, types
column = Column('_column', types.Numeric(5, 2))
elements = self._get_elements((('column', column),))
self.assertEqual(len(elements), 1)
self.assertEqual(elements[0].attrib, {
'minOccurs': '0',
'name': 'column',
'nillable': 'true'})
restrictions = elements[0].findall(
self._make_xpath('. simpleType restriction'))
self.assertEqual(len(restrictions), 1)
self.assertEqual(restrictions[0].attrib, {'base': 'xsd:decimal'})
totalDigitss = restrictions[0].findall(
self._make_xpath('. totalDigits'))
self.assertEqual(len(totalDigitss), 1)
self.assertEqual(totalDigitss[0].attrib, {'value': '5'})
fractionDigitss = restrictions[0].findall(
self._make_xpath('. fractionDigits'))
self.assertEqual(len(fractionDigitss), 1)
self.assertEqual(fractionDigitss[0].attrib, {'value': '2'})
0
Example 9
def widget(self, column):
"""
Returns WTForms widget for given column.
:param column: SQLAlchemy Column object
"""
widget = column.info.get('widget', None)
if widget is not None:
return widget
kwargs = {}
step = column.info.get('step', None)
if step is not None:
kwargs['step'] = step
else:
if isinstance(column.type, sa.types.Numeric):
if (
column.type.scale is not None and
not column.info.get('choices')
):
kwargs['step'] = self.scale_to_step(column.type.scale)
if kwargs:
widget_class = self.WIDGET_MAP[
self.get_field_class(column)
]
return widget_class(**kwargs)