-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from Caylo/rst-help
Added output format options for --help
- Loading branch information
Showing
7 changed files
with
262 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# # | ||
# Copyright 2015-2015 Ghent University | ||
# | ||
# This file is part of vsc-base, | ||
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), | ||
# with support of Ghent University (http://ugent.be/hpc), | ||
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en), | ||
# the Hercules foundation (http://www.herculesstichting.be/in_English) | ||
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). | ||
# | ||
# http://github.com/hpcugent/vsc-base | ||
# | ||
# vsc-base is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Library General Public License as | ||
# published by the Free Software Foundation, either version 2 of | ||
# the License, or (at your option) any later version. | ||
# | ||
# vsc-base is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Library General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Library General Public License | ||
# along with vsc-base. If not, see <http://www.gnu.org/licenses/>. | ||
# # | ||
""" | ||
Functions for generating rst documentation | ||
@author: Caroline De Brouwer (Ghent University) | ||
""" | ||
|
||
INDENT_4SPACES = ' ' * 4 | ||
|
||
|
||
class LengthNotEqualException(ValueError): | ||
pass | ||
|
||
|
||
def mk_rst_table(titles, columns): | ||
""" | ||
Returns an rst table with given titles and columns (a nested list of string columns for each column) | ||
""" | ||
title_cnt, col_cnt = len(titles), len(columns) | ||
if title_cnt != col_cnt: | ||
msg = "Number of titles/columns should be equal, found %d titles and %d columns" % (title_cnt, col_cnt) | ||
raise LengthNotEqualException, msg | ||
table = [] | ||
col_widths = [] | ||
tmpl = [] | ||
line= [] | ||
|
||
# figure out column widths | ||
for i, title in enumerate(titles): | ||
width = max(map(len, columns[i] + [title])) | ||
|
||
# make line template | ||
tmpl.append('{%s:{c}<%s}' % (i, width)) | ||
|
||
line = [''] * col_cnt | ||
line_tmpl = INDENT_4SPACES.join(tmpl) | ||
table_line = line_tmpl.format(*line, c='=') | ||
|
||
table.append(table_line) | ||
table.append(line_tmpl.format(*titles, c=' ')) | ||
table.append(table_line) | ||
|
||
for row in map(list, zip(*columns)): | ||
table.append(line_tmpl.format(*row, c=' ')) | ||
|
||
table.extend([table_line, '']) | ||
|
||
return table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
## | ||
# Copyright 2015-2015 Ghent University | ||
# | ||
# This file is part of vsc-base, | ||
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), | ||
# with support of Ghent University (http://ugent.be/hpc), | ||
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en), | ||
# the Hercules foundation (http://www.herculesstichting.be/in_English) | ||
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). | ||
# | ||
# http://github.com/hpcugent/vsc-base | ||
# | ||
# vsc-base is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation v2. | ||
# | ||
# vsc-base is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>. | ||
## | ||
""" | ||
Unit tests for the docs module. | ||
@author: Kenneth Hoste (Ghent University) | ||
@author: Caroline De Brouwer (Ghent University) | ||
""" | ||
import os | ||
from unittest import TestLoader, TestCase, main | ||
from vsc.utils.testing import EnhancedTestCase | ||
|
||
from vsc.utils.docs import mk_rst_table | ||
|
||
|
||
class DocsTest(EnhancedTestCase): | ||
"""Tests for docs functions.""" | ||
|
||
def test_mk_rst_table(self): | ||
"""Test mk_rst_table function.""" | ||
entries = [['one', 'two', 'three']] | ||
t = 'This title is longer than the entries in the column' | ||
titles = [t] | ||
|
||
# small table | ||
table = mk_rst_table(titles, entries) | ||
check = [ | ||
'=' * len(t), | ||
t, | ||
'=' * len(t), | ||
'one' + ' ' * (len(t) - 3), | ||
'two' + ' ' * (len(t) -3), | ||
'three' + ' ' * (len(t) - 5), | ||
'=' * len(t), | ||
'', | ||
] | ||
|
||
self.assertEqual(table, check) | ||
|
||
def suite(): | ||
""" returns all the testcases in this module """ | ||
return TestLoader().loadTestsFromTestCase(DocsTest) | ||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.