Commit a1798dd3 authored by Kipp Cannon's avatar Kipp Cannon

docstring Python 2<-->3 portability

- use print() to display string-valued things
- use assert to test the type when it matters
parent 580907dc
......@@ -55,8 +55,8 @@ suffix can be retrieved by converting the object to an integer.
Example:
>>> x.table_name
u'process'
>>> print(x.table_name)
process
>>> int(x)
10
......@@ -172,7 +172,7 @@ def get_ilwdchar_class(tbl_name, col_name, namespace = globals()):
Example:
>>> for i in range(10):
... print str(process_id(i))
... print(str(process_id(i)))
...
process:process_id:0
process:process_id:1
......@@ -246,10 +246,10 @@ class ilwdchar(object):
>>> x = ilwdchar(u"process:process_id:10")
>>> str(x)
'process:process_id:10'
>>> x.table_name
u'process'
>>> x.column_name
u'process_id'
>>> print(x.table_name)
process
>>> print(x.column_name)
process_id
>>> int(x)
10
>>> x.index_offset
......
......@@ -139,8 +139,7 @@ class attributeproxy(property):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> # internally, value is stored as unicode (for XML)
>>> x.getAttribute("Scale")
u'16'
>>> assert x.getAttribute("Scale") == "16"
>>> # deleting an attribute restores the default value if defined
>>> del x.Scale
>>> x.Scale
......@@ -444,11 +443,11 @@ class LLWNameAttr(six.text_type):
>>> x = Test()
>>> x.Name = u"blah"
>>> # internally, suffix has been appended
>>> x.getAttribute("Name")
u'blah:test'
>>> print(x.getAttribute("Name"))
blah:test
>>> # but attributeproxy reports original value
>>> x.Name
u'blah'
>>> print(x.Name)
blah
>>> # only lower-case Latin letters, numerals, and '_' are allowed
>>> x.Name = u"Hello-world"
Traceback (most recent call last):
......
......@@ -189,22 +189,14 @@ class instrumentsproperty(object):
>>> print(instrumentsproperty.get(None))
None
>>> instrumentsproperty.get(u"")
set([])
>>> instrumentsproperty.get(u" , ,,")
set([])
>>> instrumentsproperty.get(u"H1")
set([u'H1'])
>>> instrumentsproperty.get(u"SWIFT")
set([u'SWIFT'])
>>> instrumentsproperty.get(u"H1L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1L1,")
set([u'H1L1'])
>>> instrumentsproperty.get(u"H1,L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1+L1")
set([u'H1', u'L1'])
>>> assert instrumentsproperty.get(u"") == set([])
>>> assert instrumentsproperty.get(u" , ,,") == set([])
>>> assert instrumentsproperty.get(u"H1") == set([u'H1'])
>>> assert instrumentsproperty.get(u"SWIFT") == set([u'SWIFT'])
>>> assert instrumentsproperty.get(u"H1L1") == set([u'H1', u'L1'])
>>> assert instrumentsproperty.get(u"H1L1,") == set([u'H1L1'])
>>> assert instrumentsproperty.get(u"H1,L1") == set([u'H1', u'L1'])
>>> assert instrumentsproperty.get(u"H1+L1") == set([u'H1', u'L1'])
"""
if ifos is None:
return None
......@@ -259,18 +251,12 @@ class instrumentsproperty(object):
>>> print(instrumentsproperty.set(None))
None
>>> instrumentsproperty.set(())
u''
>>> instrumentsproperty.set((u"H1",))
u'H1'
>>> instrumentsproperty.set((u"H1",u"H1",u"H1"))
u'H1'
>>> instrumentsproperty.set((u"H1",u"L1"))
u'H1,L1'
>>> instrumentsproperty.set((u"SWIFT",))
u'SWIFT'
>>> instrumentsproperty.set((u"H1L1",))
u'H1L1,'
>>> assert instrumentsproperty.set(()) == u''
>>> assert instrumentsproperty.set((u"H1",)) == u'H1'
>>> assert instrumentsproperty.set((u"H1",u"H1",u"H1")) == u'H1'
>>> assert instrumentsproperty.set((u"H1",u"L1")) == u'H1,L1'
>>> assert instrumentsproperty.set((u"SWIFT",)) == u'SWIFT'
>>> assert instrumentsproperty.set((u"H1L1",)) == u'H1L1,'
"""
if instruments is None:
return None
......@@ -429,10 +415,8 @@ class Process(table.Table.RowType):
>>> x = Process()
>>> x.instruments = (u"H1", u"L1")
>>> x.ifos
u'H1,L1'
>>> x.instruments
set([u'H1', u'L1'])
>>> assert x.ifos == u'H1,L1'
>>> assert x.instruments == set([u'H1', u'L1'])
"""
__slots__ = tuple(map(table.Column.ColumnName, ProcessTable.validcolumns))
......@@ -480,18 +464,17 @@ class ProcessParams(table.Table.RowType):
>>> x = ProcessParams()
>>> x.pyvalue = u"test"
>>> x.type
u'lstring'
>>> x.value
u'test'
>>> x.pyvalue
u'test'
>>> print(x.type)
lstring
>>> print(x.value)
test
>>> print(x.pyvalue)
test
>>> x.pyvalue = 6.
>>> x.type
u'real_8'
>>> x.value
u'6'
>>> x.pyvalue
>>> print(x.type)
real_8
>>> assert x.value == u'6'
>>> print(x.pyvalue)
6.0
>>> x.pyvalue = None
>>> print(x.type)
......@@ -501,10 +484,9 @@ class ProcessParams(table.Table.RowType):
>>> print(x.pyvalue)
None
>>> x.pyvalue = True
>>> x.type
u'int_4s'
>>> x.value
u'1'
>>> print(x.type)
int_4s
>>> assert x.value == u'1'
>>> x.pyvalue
1
"""
......@@ -611,10 +593,9 @@ class SearchSummary(table.Table.RowType):
>>> x = SearchSummary()
>>> x.instruments = (u"H1", u"L1")
>>> x.ifos
u'H1,L1'
>>> x.instruments
set([u'H1', u'L1'])
>>> print(x.ifos)
H1,L1
>>> assert x.instruments == set([u'H1', u'L1'])
>>> x.in_start = x.out_start = LIGOTimeGPS(0)
>>> x.in_end = x.out_end = LIGOTimeGPS(10)
>>> x.in_segment
......@@ -1354,10 +1335,9 @@ class CoincInspiral(table.Table.RowType):
>>> x = CoincInspiral()
>>> x.instruments = (u"H1", u"L1")
>>> x.ifos
u'H1,L1'
>>> x.instruments
set([u'H1', u'L1'])
>>> print(x.ifos)
H1,L1
>>> assert x.instruments == set([u'H1', u'L1'])
>>> x.end = LIGOTimeGPS(10)
>>> x.end
LIGOTimeGPS(10, 0)
......@@ -1575,7 +1555,7 @@ class SimInspiral(table.Table.RowType):
>>> x.time_geocent = LIGOTimeGPS(6e8)
>>> print(x.time_geocent)
600000000
>>> print(x.end_time_gmst)
>>> print(round(x.end_time_gmst, 8))
-2238.39417156
"""
__slots__ = tuple(map(table.Column.ColumnName, SimInspiralTable.validcolumns))
......@@ -1712,7 +1692,7 @@ class SimBurst(table.Table.RowType):
>>> x.time_geocent = LIGOTimeGPS(6e8)
>>> print(x.time_geocent)
600000000
>>> print(x.time_geocent_gmst)
>>> print(round(x.time_geocent_gmst, 8))
-2238.39417156
"""
__slots__ = tuple(map(table.Column.ColumnName, SimBurstTable.validcolumns))
......@@ -1909,10 +1889,9 @@ class SummValue(table.Table.RowType):
>>> x = SummValue()
>>> x.instruments = (u"H1", u"L1")
>>> x.ifo
u'H1,L1'
>>> x.instruments
set([u'H1', u'L1'])
>>> print(x.ifo)
H1,L1
>>> assert x.instruments == set([u'H1', u'L1'])
>>> x.start = LIGOTimeGPS(0)
>>> x.end = LIGOTimeGPS(10)
>>> x.segment
......@@ -2109,10 +2088,9 @@ class SegmentDef(table.Table.RowType):
>>> x = SegmentDef()
>>> x.instruments = (u"H1", u"L1")
>>> x.ifos
u'H1,L1'
>>> x.instruments
set([u'H1', u'L1'])
>>> print(x.ifos)
H1,L1
>>> assert x.instruments == set([u'H1', u'L1'])
"""
__slots__ = tuple(map(table.Column.ColumnName, SegmentDefTable.validcolumns))
......
......@@ -172,12 +172,12 @@ class Column(ligolw.Column):
>>> tbl.appendChild(TableStream(AttributesImpl({u"Name": u"test"}))) # doctest: +ELLIPSIS
<ligo.lw.table.TableStream object at ...>
>>> tbl._update_column_info()
>>> col.Name
u'snr'
>>> col.Type
u'real_8'
>>> col.table_name
u'test'
>>> print(col.Name)
snr
>>> print(col.Type)
real_8
>>> print(col.table_name)
test
>>> # append 3 rows (with nothing in them)
>>> tbl.append(tbl.RowType())
>>> tbl.append(tbl.RowType())
......@@ -224,11 +224,15 @@ class Column(ligolw.Column):
doing the correct manipulations. Therefore, the assignment
operation below
>>> col.Name, col.getAttribute("Name")
(u'snr', u'test:snr')
>>> print(col.Name)
snr
>>> print(col.getAttribute("Name"))
test:snr
>>> col.Name = col.Name
>>> col.Name, col.getAttribute("Name")
(u'snr', u'snr')
>>> print(col.Name)
snr
>>> print(col.getAttribute("Name"))
snr
does not preserve the value of the "Name" attribute (though it does
preserve the stripped form reported by the .Name property). This
......@@ -763,15 +767,15 @@ class Table(ligolw.Table, list):
>>> from ligo.lw import lsctables
>>> tbl = lsctables.New(lsctables.ProcessParamsTable, [])
>>> col = tbl.appendColumn("param")
>>> col.getAttribute("Name")
u'param'
>>> col.Name
u'param'
>>> print(col.getAttribute("Name"))
param
>>> print(col.Name)
param
>>> col = tbl.appendColumn(u"process:process_id")
>>> col.getAttribute("Name")
u'process:process_id'
>>> col.Name
u'process_id'
>>> print(col.getAttribute("Name"))
process:process_id
>>> print(col.Name)
process_id
"""
try:
self.getColumnByName(name)
......
......@@ -227,7 +227,7 @@ static struct PyMethodDef methods[] = {
"...\n"\
">>> rows = tokenizer.RowBuilder(Row, [\"time\", \"snr\"])\n"\
">>> for row in rows.append([10, 6.8, 15, 29.1]):\n"\
"... print row.snr\n"\
"... print(row.snr)\n"\
"..."
},
{NULL,}
......
......@@ -298,7 +298,7 @@ PyTypeObject ligolw_RowDumper_Type = {
">>> rows[2].status = \"good\"\n" \
">>> rowdumper = RowDumper((\"snr\", \"status\"), (\"%.16g\".__mod__, \"\\\"%s\\\"\".__mod__))\n" \
">>> for line in rowdumper.dump(rows):\n" \
"... print line\n" \
"... print(line)\n" \
"... \n" \
"10.1,\"bad\"\n" \
"15.2,\"bad\"\n" \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment