From: Josh Soref <2119212+jsoref@users.noreply.github.com> Date: Wed, 12 Nov 2025 19:14:11 +0000 (-0500) Subject: Use assertEqual X-Git-Tag: rec-5.4.0-alpha1~95^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cdafb7f98a4f2dfd1b8ddd1101bc3b17ce110db;p=thirdparty%2Fpdns.git Use assertEqual https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertEqual Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com> --- diff --git a/regression-tests.auth-py/authtests.py b/regression-tests.auth-py/authtests.py index f308d49bd7..b09273b46d 100644 --- a/regression-tests.auth-py/authtests.py +++ b/regression-tests.auth-py/authtests.py @@ -651,7 +651,7 @@ options { raise AssertionError("RRSIG found in answers for:\n%s" % ret) def assertAnswerEmpty(self, msg): - self.assertTrue(len(msg.answer) == 0, "Data found in the the answer section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.answer]))) + self.assertEqual(len(msg.answer), 0, "Data found in the the answer section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.answer]))) def assertAnswerNotEmpty(self, msg): self.assertTrue(len(msg.answer) > 0, "Answer is empty") diff --git a/regression-tests.dnsdist/test_Caching.py b/regression-tests.dnsdist/test_Caching.py index 35d3167331..6e0a70b9b4 100644 --- a/regression-tests.dnsdist/test_Caching.py +++ b/regression-tests.dnsdist/test_Caching.py @@ -2246,7 +2246,7 @@ class TestCachingDontAge(DNSDistTest): (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertEqual(receivedResponse, response) for an in receivedResponse.answer: - self.assertTrue(an.ttl == ttl) + self.assertEqual(an.ttl, ttl) # now we wait a bit for the TTL to decrease time.sleep(1) @@ -2255,7 +2255,7 @@ class TestCachingDontAge(DNSDistTest): (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertEqual(receivedResponse, response) for an in receivedResponse.answer: - self.assertTrue(an.ttl == ttl) + self.assertEqual(an.ttl, ttl) total = 0 for key in self._responsesCounter: diff --git a/regression-tests.dnsdist/test_DNSCrypt.py b/regression-tests.dnsdist/test_DNSCrypt.py index 28a35431a1..7286527524 100644 --- a/regression-tests.dnsdist/test_DNSCrypt.py +++ b/regression-tests.dnsdist/test_DNSCrypt.py @@ -121,9 +121,9 @@ class TestDNSCrypt(DNSCryptTest): self.assertEqual(query, receivedQuery) self.assertEqual(receivedResponse.question, response.question) self.assertTrue(receivedResponse.flags & ~dns.flags.TC) - self.assertTrue(len(receivedResponse.answer) == 0) - self.assertTrue(len(receivedResponse.authority) == 0) - self.assertTrue(len(receivedResponse.additional) == 0) + self.assertEqual(len(receivedResponse.answer), 0) + self.assertEqual(len(receivedResponse.authority), 0) + self.assertEqual(len(receivedResponse.additional), 0) def testCertRotation(self): """ diff --git a/regression-tests.recursor-dnssec/recursortests.py b/regression-tests.recursor-dnssec/recursortests.py index 18d897fc98..249dd66d4d 100644 --- a/regression-tests.recursor-dnssec/recursortests.py +++ b/regression-tests.recursor-dnssec/recursortests.py @@ -1116,10 +1116,10 @@ distributor-threads={threads} raise AssertionError("RRSIG found in answers for:\n%s" % ret) def assertAnswerEmpty(self, msg): - self.assertTrue(len(msg.answer) == 0, "Data found in the the answer section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.answer]))) + self.assertEqual(len(msg.answer), 0, "Data found in the the answer section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.answer]))) def assertAdditionalEmpty(self, msg): - self.assertTrue(len(msg.additional) == 0, "Data found in the the additional section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.additional]))) + self.assertEqual(len(msg.additional), 0, "Data found in the the additional section for %s:\n%s" % (msg.question[0].to_text(), '\n'.join([i.to_text() for i in msg.additional]))) def assertRcodeEqual(self, msg, rcode): if not isinstance(msg, dns.message.Message): diff --git a/regression-tests.recursor-dnssec/test_Protobuf.py b/regression-tests.recursor-dnssec/test_Protobuf.py index 0b392f443a..894c81ff0b 100644 --- a/regression-tests.recursor-dnssec/test_Protobuf.py +++ b/regression-tests.recursor-dnssec/test_Protobuf.py @@ -285,17 +285,17 @@ class TestRecursorProtobuf(RecursorTest): def checkProtobufIdentity(self, msg, requestorId, deviceId, deviceName): #print(msg) - self.assertTrue((requestorId == '') == (not msg.HasField('requestorId'))) - self.assertTrue((deviceId == b'') == (not msg.HasField('deviceId'))) - self.assertTrue((deviceName == '') == (not msg.HasField('deviceName'))) + self.assertEqual(requestorId == '', not msg.HasField('requestorId')) + self.assertEqual(deviceId == b'', not msg.HasField('deviceId')) + self.assertEqual(deviceName == '', not msg.HasField('deviceName')) self.assertEqual(msg.requestorId, requestorId) self.assertEqual(msg.deviceId, deviceId) self.assertEqual(msg.deviceName, deviceName) def checkProtobufEDE(self, msg, ede, edeText): #print(msg) - self.assertTrue((ede == 0) == (not msg.HasField('ede'))) - self.assertTrue((edeText == '') == (not msg.HasField('edeText'))) + self.assertEqual(ede == 0, not msg.HasField('ede')) + self.assertEqual(edeText == '', not msg.HasField('edeText')) self.assertEqual(msg.ede, ede) self.assertEqual(msg.edeText, edeText) @@ -305,8 +305,8 @@ class TestRecursorProtobuf(RecursorTest): return opt def checkProtobufOT(self, msg, openTelemetryData, openTelemetryTraceID): - self.assertTrue(openTelemetryData == msg.HasField('openTelemetryData')) - self.assertTrue(openTelemetryTraceID == msg.HasField('openTelemetryTraceID')) + self.assertEqual(openTelemetryData, msg.HasField('openTelemetryData')) + self.assertEqual(openTelemetryTraceID, msg.HasField('openTelemetryTraceID')) def setUp(self): super(TestRecursorProtobuf, self).setUp()