Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
["valid_ext.rst", "valid_ext.RST", ".rst", "RST"], [ptw.RstGridTableWriter]
)
)
+ list(
itertools.product(
["valid_ext.sqlite", "valid_ext.sqlite3", ".sqlite", "SQLITE"],
[ptw.SqliteTableWriter],
)
)
+ list(
itertools.product(
["valid_ext.tex", "valid_ext.TEX", ".tex", "TEX"], [ptw.LatexMatrixWriter]
)
)
+ list(
itertools.product(
["valid_ext.tsv", "valid_ext.TSV", ".tsv", "TSV"], [ptw.TsvTableWriter]
value=[["v1\nv1", "v2\n\nv2", "v3\r\nv3"]],
expected=dedent(
"""\
.. table:: line breaks will be converted to a white space
+-----+-----+-----+
| a b | c d | e f |
+=====+=====+=====+
|v1 v1|v2 v2|v3 v3|
+-----+-----+-----+
"""
),
),
]
table_writer_class = pytablewriter.RstGridTableWriter
class Test_RstGridTableWriter_write_new_line(object):
def test_normal(self, capsys):
writer = table_writer_class()
writer.write_null_line()
out, _err = capsys.readouterr()
assert out == "\n"
class Test_RstGridTableWriter_write_table(object):
@pytest.mark.parametrize(
["table", "indent", "header", "value", "expected"],
[
for c, v in _maps.items():
label = ':mod:`{0}`'.format(c[1]) if c[1] is not None else c[0]
i = list([label])
for platform in _platforms:
if platform in v:
i.append('|yes|')
else:
i.append('|no|')
writer.value_matrix.append(i)
writer.write_table()
doc.write(_footer)
for component, value in _maps.items():
with open('../docs/reference/supported_platforms/{0}.rst'.format(component[0]), 'w+') as doc:
writer = pytablewriter.RstGridTableWriter()
writer.stream = doc
# writer.table_name = "Supported platforms"
writer.header_list = ["Component"] + _platforms
writer.value_matrix = []
i = list([component[0]])
for platform in _platforms:
if platform in value:
i.append('|yes|')
else:
i.append('|no|')
writer.value_matrix.append(i)
writer.write_table()
doc.write(_footer)
print("Done.")
import sys
# ่ฆๅๅ
ฅ็ๆไปถๅ
filepath = "table.rst"
# ---python2 ๆๆ--- #
reload(sys) # ้ๆฐ่ฝฝๅ
ฅsys.setdefaultencoding ๆนๆณ
sys.setdefaultencoding('utf-8')
# End of reload #
file1 = open(filepath, 'w+') # ๆๅผๆไปถ
file1.truncate() # ๆธ
็ฉบๆไปถๅ
ๅฎน
file1.close()
# set as rst writer
writer = pytablewriter.RstGridTableWriter()
# change the stream to a string buffer to get the output as a string
writer.stream = six.StringIO()
writer.header_list = ['SPIๅฑ', 'zero']
writer.value_matrix = [
['3v3', '3v3'],
['GND', 'GND'],
['DC', 'PWM1'],
['RST', '3v3'],
['CS', 'CS'],
['CLK', 'CLK'],
['MISO', 'MISO'],
['MOSI', 'MOSI'],
]
# encoding: utf-8
"""
.. codeauthor:: Tsuyoshi Hombashi
"""
import pytablewriter
csv_data = u""""i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09:00"
2,2.20,"bbb",2.2,"2.2",False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
3,3.33,"cccc",-3.0,"ccc",True,Infinity,NaN,NaN,"2017-01-01 00:00:00+09:00"
"""
writer = pytablewriter.RstGridTableWriter()
writer.from_csv(csv_data)
writer.write_table()
import pytablewriter
from preview_generator.manager import PreviewManager
pm = PreviewManager("/tmp/cache")
writer = pytablewriter.RstGridTableWriter()
writer.table_name = "Supported mimetypes table"
writer.headers = ["MIME type", "Extension"]
matrix = []
for builder in pm._factory.builders_classes:
try:
mimetypes = builder.get_supported_mimetypes()
if not mimetypes:
continue
matrix.append(["**{}**".format(builder.get_label())])
for mimetype in mimetypes:
extensions = ", ".join(pm.get_file_extensions(mimetype)) or " - "
matrix.append([mimetype, extensions])
except NotImplementedError:
pass # probably abstract class, so ignore it