def test_relation_set_file_non_str(self, check_call, check_output, remove):
"""If relation-set accepts a --file parameter, it's used.
Any value that is not a string is converted to a string before encoding
the settings to YAML.
"""
# check_output(["relation-set", "--help"]) is used to determine
# whether we can pass --file to it.
check_output.return_value = "--file"
hookenv.relation_set(foo={"bar": 1})
check_output.assert_called_with(
["relation-set", "--help"], universal_newlines=True)
# relation-set is called with relation-set --file <temp_file>
# with data as YAML and the temp_file is then removed.
self.assertEqual(1, len(check_call.call_args[0]))
command = check_call.call_args[0][0]
self.assertEqual(3, len(command))
self.assertEqual("relation-set", command[0])
self.assertEqual("--file", command[1])
temp_file = command[2]
with open(temp_file, "r") as f:
self.assertEqual("{foo: '{''bar'': 1}'}", f.read().strip())
remove.assert_called_with(temp_file)
评论列表
文章目录