def test_pop(): d = {'a.b.c': 0, 'a.b.d': 0, 'a.x': 0} p = ParameterSet(**d) v = p.pop('a.b') assert_equals(p.keys(), ['a.x']) assert_equals(v.items(), [ ('c', 0), ('d', 0), ])
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. # import sys import os from askap.parset import ParameterSet, encode if len(sys.argv) != 2: print """usage: \t %s <parmeterset_file> """ % (os.path.basename(sys.argv[0]) ) sys.exit(1) p = ParameterSet(sys.argv[1]) buffer = "" title = "Documentation for "+ os.path.basename(sys.argv[1])+"\n" title += "="*(len(title)-1)+"\n" print title for k in p.keys(): print "**"+k+"**", " = :literal:`%s`" % encode(p[k]) doc = p.get_doc(k) or "**undocumented**" for line in doc.split("\n"): print " "*2, line print
def run(self): """ Implements the directive """ # Get content and options file_path = self.arguments[0] use_title = 'show-title' in self.options use_header = 'show-header' in self.options main_key = self.options.get('key', None) show_key = 'show-key' in self.options if not file_path: return [self._report('file_path -option missing')] # Transform the path suitable for processing file_path = self._get_directive_path(file_path) parset = ParameterSet(file_path) if main_key: parset = parset[main_key] title, messages = self.make_title() if not parset: return [nodes.paragraph(text='')] table_data = [] docparser = Parser() # Iterates rows: put the given data in rst elements for key in parset.keys(): the_val = encode(parset[key]) the_doc = parset.get_doc(key) or '' if main_key and show_key: key = ".".join([main_key.split(".")[-1], key]) node1 = nodes.strong(text=key) node2 = nodes.literal(text=the_val) subdoc = utils.new_document('<>', self.state.document.settings) docparser.parse(the_doc, subdoc) node3 = subdoc.children table_data.append([node1, node2, node3]) col_widths = self.get_column_widths(3) self.check_table_dimensions(table_data, 0, 0) header_rows = 0 if use_header: header_rows = 1 table_data.insert(0, [ nodes.strong(text="Key"), nodes.strong(text="Default"), nodes.strong(text="Description"), ]) # Generate the table node from the given list of elements table_node = self.build_table_from_list(table_data, col_widths, header_rows, 0) # Optional class parameter table_node['classes'] += self.options.get('class', []) if use_title and title: if main_key: ttxt = title.astext() title = nodes.title(text="".join([ttxt, ' (', main_key, ')'])) table_node.insert(0, title) return [table_node] + messages
def run(self): """ Implements the directive """ # Get content and options file_path = self.arguments[0] use_title = 'show-title' in self.options use_header = 'show-header' in self.options main_key = self.options.get('key', None) show_key = 'show-key' in self.options if not file_path: return [self._report('file_path -option missing')] # Transform the path suitable for processing file_path = self._get_directive_path(file_path) parset = ParameterSet(file_path) if main_key: parset = parset[main_key] title, messages = self.make_title() if not parset: return [nodes.paragraph(text='')] table_data = [] docparser = Parser() # Iterates rows: put the given data in rst elements for key in parset.keys(): the_val = encode(parset[key]) the_doc = parset.get_doc(key) or '' if main_key and show_key: key = ".".join([main_key.split(".")[-1],key]) node1 = nodes.strong(text=key) node2 = nodes.literal(text=the_val) subdoc = utils.new_document('<>', self.state.document.settings) docparser.parse(the_doc, subdoc) node3 = subdoc.children table_data.append([node1, node2, node3]) col_widths = self.get_column_widths(3) self.check_table_dimensions(table_data, 0, 0) header_rows = 0 if use_header: header_rows = 1 table_data.insert(0, [nodes.strong(text="Key"), nodes.strong(text="Default"), nodes.strong(text="Description"), ]) # Generate the table node from the given list of elements table_node = self.build_table_from_list(table_data, col_widths, header_rows, 0) # Optional class parameter table_node['classes'] += self.options.get('class', []) if use_title and title: if main_key: ttxt = title.astext() title = nodes.title(text="".join([ttxt,' (',main_key,')'])) table_node.insert(0, title) return [table_node] + messages
def test_pop(): d = {'a.b.c': 0, 'a.b.d': 0, 'a.x' : 0} p = ParameterSet(**d) v = p.pop('a.b') assert_equals(p.keys(), ['a.x']) assert_equals(v.items(), [('c', 0),('d', 0),])
def test_del(): d = {'a.b.c': 0, 'a.b.d': 0, 'a.x' : 0} p = ParameterSet(**d) del p['a.b'] assert_equals(p.keys(), ['a.x'])
def test_keys(): keys = ['a', 'x.y.z'] p = ParameterSet(keys[1], 1) p.set_value(keys[0], 1) assert_equals(p.keys(), keys)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. # import sys import os from askap.parset import ParameterSet, encode if len(sys.argv) != 2: print """usage: \t %s <parmeterset_file> """ % (os.path.basename(sys.argv[0])) sys.exit(1) p = ParameterSet(sys.argv[1]) buffer = "" title = "Documentation for " + os.path.basename(sys.argv[1]) + "\n" title += "=" * (len(title) - 1) + "\n" print title for k in p.keys(): print "**" + k + "**", " = :literal:`%s`" % encode(p[k]) doc = p.get_doc(k) or "**undocumented**" for line in doc.split("\n"): print " " * 2, line print