summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-07-29 14:15:11 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-07-30 17:10:08 +0000
commitfac47acd5ab8e3410929e8c36ceaa4ecf070de10 (patch)
treea880bdeeffc2d62804b97e85551132319258dae9 /scripts
parentb36072a5af5947e5dbb73395d821f1a57e0ef773 (diff)
downloadmorph-fac47acd5ab8e3410929e8c36ceaa4ecf070de10.tar.gz
Add scenario (yarn) tests for most of branching and merging
These scenarios test the basics of most of the subcommands the branch and merge plugin provides. They don't purport to be complete, but give some indication that things work, and form a basis upon which further things can be built. Yarn also isn't included in a Baserock release yet, so we need to keep the cmdtests until Baserock 10 has been released. The existing cmdtest tests are not modified by this: they are left intact, until they can analysed in detail for things to be added to the scenarios. After that, the cmdtest tests will start to go away. Merging is not covered by these tests: it is not clear how merge should work, and the current code is known to do the wrong thing in many cases. Scenarios for merge will be added later. Building is also not covered. Testing builds well needs some additional, careful thinking, and that isn't ready for this patch series. It will be added later.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/yaml-extract76
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/yaml-extract b/scripts/yaml-extract
new file mode 100755
index 00000000..98b332b7
--- /dev/null
+++ b/scripts/yaml-extract
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+#
+# Extract field from YAML format morphologies, using a very simple
+# query language. This is useful for black box testing.
+#
+# Usage: yaml-extract FILE PARAM...
+#
+# Where FILE is the name of the YAML morphology, and PARAM are a sequence
+# of query parameters.
+#
+# The program reads in the YAML file, and then selects successively deeper
+# parts of the object hieararchy in the file. If the object currently
+# being looked at is a dictionary, PARAM is a field in the dictionary,
+# and the next PARAM will look at the value stored with that key.
+# If the current object is a list, PARAM can either be an integer list
+# index, or a search key of the form KEY=VALUE, in which case the list
+# is searched for the first member, which must be a dict, which has
+# a key KEY that stores a value VALUE.
+#
+# Example:
+#
+# yaml-extract system.morph strata morph=core ref
+#
+# This would report the ref of the core stratum in a system.
+#
+# Note that this does not try to parse morphologies as morphologies,
+# and so doesn't do special processing such as providing computed
+# values for missing fields (e.g., the morph field if name is given).
+# Construct your tests accordingly.
+
+# Copyright (C) 2013 Codethink Limited
+#
+# This program 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; version 2 of the License.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import sys
+import yaml
+
+
+with open(sys.argv[1]) as f:
+ obj = yaml.safe_load(f)
+# print "AAA", repr(obj)
+for thing in sys.argv[2:]:
+ # print "XXX", repr(obj), repr(thing)
+ if type(obj) == dict:
+ obj = obj[thing]
+ elif type(obj) == list:
+ if '=' in thing:
+ # We need to search a list member dict with a given field.
+ key, value = thing.split('=', 1)
+ for item in obj:
+ if item.get(key) == value:
+ obj = item
+ break
+ else:
+ raise Exception(
+ "Couldn't find list item containing %s" % thing)
+ else:
+ # We can just index.
+ obj = obj[int(thing)]
+ else:
+ raise Exception("Can't handle %s with %s" % (repr(obj), repr(thing)))
+
+print obj
+