Exemplo n.º 1
0
    def test_writing_to_yaml(self):
        params = Parameters.from_mapping({
            "hello":
            "world",
            "moo": {
                "nested_dict": {
                    "lalala": "fooo",
                    "meep": 2,
                    "list": [1, 2, 3]
                }
            },
            "some_path":
            Path("/hello/world"),
            "path_list": [Path("/meep/lalala"),
                          Path("/moo/cow")],
        })
        string_buffer = CharSink.to_string()
        YAMLParametersWriter().write(params, string_buffer)
        self.assertEqual(TestParameters.WRITING_REFERENCE,
                         string_buffer.last_string_written)

        with self.assertRaisesRegex(
                RuntimeError,
                "bytes and bytearrays are not legal parameter values"):
            YAMLParametersWriter().write(
                Parameters.from_mapping({"illegal": b"bytes"}),
                CharSink.to_nowhere())

        with self.assertRaisesRegex(
                RuntimeError,
                "bytes and bytearrays are not legal parameter values"):
            YAMLParametersWriter().write(
                Parameters.from_mapping({"illegal": bytearray()}),
                CharSink.to_nowhere())

        with self.assertRaisesRegex(
                RuntimeError,
                "Don't know how to serialize out .* as a parameter value"):
            YAMLParametersWriter().write(
                Parameters.from_mapping({"illegal": Parameters}),
                CharSink.to_nowhere())
Exemplo n.º 2
0
 def test_null_sink(self):
     sink = CharSink.to_nowhere()
     sink.write("foo")
     with sink.open() as out:
         out.write("meep")