From f0e7d31bbcf07c1e36623aacf19efa9d41021fcb Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 24 Jul 2020 19:17:28 -0700 Subject: [PATCH] Bring rdataset to full coverage. --- tests/test_rdataset.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_rdataset.py b/tests/test_rdataset.py index ad6b557e..a80d6504 100644 --- a/tests/test_rdataset.py +++ b/tests/test_rdataset.py @@ -81,5 +81,46 @@ class RdatasetTestCase(unittest.TestCase): self.assertRaises(ValueError, lambda: dns.rdataset.from_rdata_list(300, [])) + def testToTextNoName(self): + rds = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1') + text = rds.to_text() + self.assertEqual(text, '300 IN A 10.0.0.1') + + def testToTextOverrideClass(self): + rds = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1') + text = rds.to_text(override_rdclass=dns.rdataclass.NONE) + self.assertEqual(text, '300 NONE A 10.0.0.1') + + def testRepr(self): + rds = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1') + self.assertEqual(repr(rds), "]>") + + def testTruncatedRepr(self): + rds = dns.rdataset.from_text('in', 'txt', 300, + 'a' * 200) + # * 99 not * 100 below as the " counts as one of the 100 chars + self.assertEqual(repr(rds), + ']>') + + def testStr(self): + rds = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1') + self.assertEqual(str(rds), "300 IN A 10.0.0.1") + + def testMultilineToText(self): + rds = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1', '10.0.0.2') + self.assertEqual(rds.to_text(), "300 IN A 10.0.0.1\n300 IN A 10.0.0.2") + + def testCoveredRepr(self): + rds = dns.rdataset.from_text('in', 'rrsig', 300, + 'NSEC 1 3 3600 ' + + '20190101000000 20030101000000 ' + + '2143 foo Ym9ndXM=') + # Using startswith as I don't care about the repr of the rdata, + # just the covers + print(repr(rds)) + self.assertTrue(repr(rds).startswith( + '