FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlobject/sqlobject/tests/test_decimal.py at master · sqlobject/sqlobject · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sqlobject
/
sqlobject
Public
Notifications
You must be signed in to change notification settings
Fork
26
Star
156
Code
Issues
2
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlobject
/
sqlobject
/
tests
/
test_decimal.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (53 loc) · 2.32 KB
Breadcrumbs
sqlobject
/
sqlobject
/
tests
/
test_decimal.py
Copy path
File metadata and controls
63 lines (53 loc) · 2.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from
decimal
import
Decimal
import
pytest
from
sqlobject
import
DecimalCol
,
DecimalStringCol
,
SQLObject
,
UnicodeCol
from
sqlobject
.
tests
.
dbtest
import
setupClass
,
supports
########################################
# Decimal columns
########################################
try
:
support_decimal_column
=
supports
(
'decimalColumn'
)
except
NameError
:
# The module was imported during documentation building
pass
else
:
if
not
support_decimal_column
:
pytestmark
=
pytest
.
mark
.
skip
(
"These tests require Decimal support"
)
class
DecimalTable
(
SQLObject
):
name
=
UnicodeCol
(
length
=
255
)
col1
=
DecimalCol
(
size
=
6
,
precision
=
4
)
col2
=
DecimalStringCol
(
size
=
6
,
precision
=
4
)
col3
=
DecimalStringCol
(
size
=
6
,
precision
=
4
,
quantize
=
True
)
def
test_1_decimal
():
setupClass
(
DecimalTable
)
d
=
DecimalTable
(
name
=
'test'
,
col1
=
21.12
,
col2
=
'10.01'
,
col3
=
'10.01'
)
# psycopg2 returns float as Decimal
if
isinstance
(
d
.
col1
,
Decimal
):
assert
d
.
col1
==
Decimal
(
"21.12"
)
else
:
assert
d
.
col1
==
21.12
assert
d
.
col2
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col2'
].
to_python
(
'10.01'
,
d
.
_SO_validatorState
)
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col2'
].
from_python
(
'10.01'
,
d
.
_SO_validatorState
)
==
"10.01"
assert
d
.
col3
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col3'
].
to_python
(
'10.01'
,
d
.
_SO_validatorState
)
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col3'
].
from_python
(
'10.01'
,
d
.
_SO_validatorState
)
==
"10.0100"
def
test_2_decimal
():
setupClass
(
DecimalTable
)
d
=
DecimalTable
(
name
=
'test'
,
col1
=
Decimal
(
"21.12"
),
col2
=
Decimal
(
'10.01'
),
col3
=
Decimal
(
'10.01'
))
assert
d
.
col1
==
Decimal
(
"21.12"
)
assert
d
.
col2
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col2'
].
to_python
(
Decimal
(
'10.01'
),
d
.
_SO_validatorState
)
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col2'
].
from_python
(
Decimal
(
'10.01'
),
d
.
_SO_validatorState
)
==
"10.01"
assert
d
.
col3
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col3'
].
to_python
(
Decimal
(
'10.01'
),
d
.
_SO_validatorState
)
==
Decimal
(
"10.01"
)
assert
DecimalTable
.
sqlmeta
.
columns
[
'col3'
].
from_python
(
Decimal
(
'10.01'
),
d
.
_SO_validatorState
)
==
"10.0100"
Back
|
FazBrowse Home
|
New Git URL