Pass context to safe_substitute as a dict and not kwargs.  This allows the FormattedDict to be used, which makes sure values in the context have been formatted before use.  Added a test case to replicate this.