def test_savingAddsEntry(self):
        """
        L{KnownHostsFile.save} will write out a new file with any entries
        that have been added.
        """
        path = self.pathWithContent(sampleHashedLine +
                                    otherSamplePlaintextLine)
        knownHostsFile = KnownHostsFile.fromPath(path)
        newEntry = knownHostsFile.addHostKey(b"some.example.com",
            Key.fromString(thirdSampleKey))
        expectedContent = (
            sampleHashedLine +
            otherSamplePlaintextLine + HashedEntry.MAGIC +
            b2a_base64(newEntry._hostSalt).strip() + b"|" +
            b2a_base64(newEntry._hostHash).strip() + b" ssh-rsa " +
            thirdSampleEncodedKey + b"\n")

        # Sanity check, let's make sure the base64 API being used for the test
        # isn't inserting spurious newlines.
        self.assertEqual(3, expectedContent.count(b"\n"))
        knownHostsFile.save()
        self.assertEqual(expectedContent, path.getContent())

        L{KnownHostsFile.save} will write out a new file with any entries
        that have been added.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_knownhosts.py