| 1 | from rdfalchemy import Literal,Namespace |
|---|
| 2 | from datetime import datetime |
|---|
| 3 | from decimal import Decimal |
|---|
| 4 | from rdflib.Literal import bind as bindLiteral |
|---|
| 5 | |
|---|
| 6 | import logging |
|---|
| 7 | log = logging.getLogger() |
|---|
| 8 | if not log.handlers: |
|---|
| 9 | log.addHandler(logging.StreamHandler()) |
|---|
| 10 | #log.setLevel(10) |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | XSD = Namespace(u'http://www.w3.org/2001/XMLSchema#') |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | def toPython_decimal_test(): |
|---|
| 18 | """docstring for toPython""" |
|---|
| 19 | # test a normal iso |
|---|
| 20 | d = Literal('.1', datatype=XSD.decimal).toPython() |
|---|
| 21 | assert isinstance(d, Decimal) |
|---|
| 22 | payments = [Literal(s,datatype=XSD.decimal) for s in '.1 .1 .1 -.3'.split()] |
|---|
| 23 | assert sum([payment.toPython() for payment in payments]) == 0 |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | def toPython_datetime_test(): |
|---|
| 27 | """docstring for toPython""" |
|---|
| 28 | # test a normal iso |
|---|
| 29 | d = Literal('2008-02-09T10:46:29', datatype=XSD.dateTime).toPython() |
|---|
| 30 | assert isinstance(d, datetime) |
|---|
| 31 | d = Literal('2008-02-09T10:46:29Z', datatype=XSD.dateTime).toPython() |
|---|
| 32 | assert isinstance(d, datetime) |
|---|
| 33 | d = Literal('2008-02-09T10:46:29-07:00', datatype=XSD.dateTime).toPython() |
|---|
| 34 | assert isinstance(d, datetime) |
|---|
| 35 | |
|---|
| 36 | d = Literal('2008-02-09T10:46:29.1', datatype=XSD.dateTime).toPython() |
|---|
| 37 | assert isinstance(d, datetime) |
|---|
| 38 | d = Literal('2008-02-09T10:46:29.123', datatype=XSD.dateTime).toPython() |
|---|
| 39 | assert isinstance(d, datetime) |
|---|
| 40 | d = Literal('2008-02-09T10:46:29.123456', datatype=XSD.dateTime).toPython() |
|---|
| 41 | assert isinstance(d, datetime) |
|---|
| 42 | # test a normal iso with fractional seconds |
|---|
| 43 | |
|---|
| 44 | d = Literal('2008-02-09 10:46:29', datatype=XSD.dateTime).toPython() |
|---|
| 45 | assert isinstance(d, datetime) |
|---|
| 46 | # test an "almost" iso string |
|---|
| 47 | |
|---|