Self-Tests: Improve sandboxing

Take a copy of `stbt.conf` so tests are free to make modifications to it.
Also move `$XDG_CACHE_HOME` into test sandbox dir.  This will be useful
for smart TV support as the calibration and test programs will need to
generate videos for display on the TVs.
tests: refactoring: Use set_config consistently

Standardise on a way of setting configuration values in tests using the
recent work on improved test sandboxing and the introduction of
`_set_config()`.

The tests are now shorter, more declarative and easier to read.  This
helper function replaces a surprising diversity in the ways in which sed
was used.
Allow passing a numpy array as a template to match functions

This allows templates to be generated on-the-fly without having to create
intermediate image files.  This will be used for Smart TV support some of
our test patterns are generated from textual descriptions and we want to
match sub-images within them.  e.g. the "letters" test pattern looks like:

    ABCDEFG
    HIJKLMN
    OPQRSTU

and we want to check the locations of each of the letters to confirm that
they're in the right places.

Nonetheless it seems that this could be generally very useful.

Possible example uses:

* You are navigating a carousel of DVD box covers and want to check that
  it correctly wraps back to the beginning.  The code could look like:

        # Grab the currently shown DVD cover given that we know its
        # location and size:
        initial_dvd_cover = stbt.get_frame()[300:700,500:700]

        stbt.press("KEY_RIGHT")
        stbt.press_until_match("KEY_RIGHT", initial_dvd_cover)

* You have an image and you want to find out which way up it is being
  displayed:

        def get_orientation():
            arrow = cv2.imread("arrow.png")
            if matches(arrow):
                return 1
            elif matches(cv2.flip(arrow)):
                return -1
            else:
                raise RuntimeError("Can't find arrow")

Future work: This feature (and stb-tester in general) would really benefit
with some tutorial style documentation to help introduce concepts and
explain when the various features of stb-tester should be applied.