def test_log_makes_exactly_one_write_call(self):
        fake_file = mock.Mock()
        fake_contextmgr = mock.Mock(
            __enter__=lambda _self: fake_file,
            __exit__=lambda _self, t, v, tb: None
        )

        fake_line = "text" * 1000000

        with mock.patch("paasta_tools.utils.io.FileIO", return_value=fake_contextmgr, autospec=True) as mock_FileIO:
            fw = utils.FileLogWriter("/dev/null", flock=False)

            with mock.patch("paasta_tools.utils.format_log_line", return_value=fake_line, autospec=True) as fake_fll:
                fw.log("service", "line", "component", level="level", cluster="cluster", instance="instance")

            fake_fll.assert_called_once_with("level", "cluster", "service", "instance", "component", "line")

            mock_FileIO.assert_called_once_with("/dev/null", mode=fw.mode, closefd=True)
            fake_file.write.assert_called_once_with("%s\n" % fake_line)
We want to make sure that log() makes exactly one call to write, since that's how we ensure atomicity.
dataset/ETHPy150Open Yelp/paasta/tests/test_utils.py/TestFileLogWriter.test_log_makes_exactly_one_write_call