Python recently deprecated some test methods in favour of others. Adjust the code to avoid warnings. Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx> --- tests/pylibfdt_tests.py | 198 ++++++++++++++++++++-------------------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py index 021a5a8..64b5bd1 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -118,34 +118,34 @@ class PyLibfdtBasicTests(unittest.TestCase): def testImport(self): """Check that we can import the library correctly""" - self.assertEquals(type(libfdt), types.ModuleType) + self.assertEqual(type(libfdt), types.ModuleType) def testBadFdt(self): """Check that a filename provided accidentally is not accepted""" with self.assertRaises(FdtException) as e: fdt = libfdt.Fdt(b'a string') - self.assertEquals(e.exception.err, -libfdt.BADMAGIC) + self.assertEqual(e.exception.err, -libfdt.BADMAGIC) def testSubnodeOffset(self): """check that we can locate a subnode by name""" node1 = self.fdt.path_offset('/subnode@1') - self.assertEquals(self.fdt.subnode_offset(0, 'subnode@1'), node1) + self.assertEqual(self.fdt.subnode_offset(0, 'subnode@1'), node1) with self.assertRaises(FdtException) as e: self.fdt.subnode_offset(0, 'missing') - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) node2 = self.fdt.path_offset('/subnode@1/subsubnode') - self.assertEquals(self.fdt.subnode_offset(node1, 'subsubnode'), node2) + self.assertEqual(self.fdt.subnode_offset(node1, 'subsubnode'), node2) def testPathOffset(self): """Check that we can find the offset of a node""" - self.assertEquals(self.fdt.path_offset('/'), 0) + self.assertEqual(self.fdt.path_offset('/'), 0) self.assertTrue(self.fdt.path_offset('/subnode@1') > 0) with self.assertRaises(FdtException) as e: self.fdt.path_offset('/wibble') - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) - self.assertEquals(self.fdt.path_offset('/wibble', QUIET_NOTFOUND), + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(self.fdt.path_offset('/wibble', QUIET_NOTFOUND), -libfdt.NOTFOUND) def testPropertyOffset(self): @@ -156,54 +156,54 @@ class PyLibfdtBasicTests(unittest.TestCase): next_offset = self.fdt.next_property_offset(offset) self.assertTrue(next_offset > offset) offset = next_offset - self.assertEquals(self.fdt.next_property_offset(offset, QUIET_NOTFOUND), + self.assertEqual(self.fdt.next_property_offset(offset, QUIET_NOTFOUND), -libfdt.NOTFOUND) def testPropertyOffsetExceptions(self): """Check that exceptions are raised as expected""" with self.assertRaises(FdtException) as e: self.fdt.first_property_offset(107) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) # Quieten the NOTFOUND exception and check that a BADOFFSET # exception is still raised. with self.assertRaises(FdtException) as e: self.fdt.first_property_offset(107, QUIET_NOTFOUND) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) with self.assertRaises(FdtException) as e: self.fdt.next_property_offset(107, QUIET_NOTFOUND) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) # Check that NOTFOUND can be quietened. node = self.fdt.path_offset('/subnode@1/ss1') - self.assertEquals(self.fdt.first_property_offset(node, QUIET_NOTFOUND), + self.assertEqual(self.fdt.first_property_offset(node, QUIET_NOTFOUND), -libfdt.NOTFOUND) with self.assertRaises(FdtException) as e: self.fdt.first_property_offset(node) - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) def testGetName(self): """Check that we can get the name of a node""" - self.assertEquals(self.fdt.get_name(0), '') + self.assertEqual(self.fdt.get_name(0), '') node = self.fdt.path_offset('/subnode@1/subsubnode') - self.assertEquals(self.fdt.get_name(node), 'subsubnode') + self.assertEqual(self.fdt.get_name(node), 'subsubnode') with self.assertRaises(FdtException) as e: self.fdt.get_name(-2) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) def testGetPropertyByOffset(self): """Check that we can read the name and contents of a property""" root = 0 poffset = self.fdt.first_property_offset(root) prop = self.fdt.get_property_by_offset(poffset) - self.assertEquals(prop.name, 'compatible') - self.assertEquals(prop, b'test_tree1\0') + self.assertEqual(prop.name, 'compatible') + self.assertEqual(prop, b'test_tree1\0') with self.assertRaises(FdtException) as e: self.fdt.get_property_by_offset(-2) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) - self.assertEquals( + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual( -libfdt.BADOFFSET, self.fdt.get_property_by_offset(-2, [libfdt.BADOFFSET])) @@ -211,21 +211,21 @@ class PyLibfdtBasicTests(unittest.TestCase): """Check that we can read the contents of a property by name""" root = self.fdt.path_offset('/') value = self.fdt.getprop(root, "compatible") - self.assertEquals(value, b'test_tree1\0') - self.assertEquals(-libfdt.NOTFOUND, self.fdt.getprop(root, 'missing', + self.assertEqual(value, b'test_tree1\0') + self.assertEqual(-libfdt.NOTFOUND, self.fdt.getprop(root, 'missing', QUIET_NOTFOUND)) with self.assertRaises(FdtException) as e: self.fdt.getprop(root, 'missing') - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) node = self.fdt.path_offset('/subnode@1/subsubnode') value = self.fdt.getprop(node, "compatible") - self.assertEquals(value, b'subsubnode1\0subsubnode\0') + self.assertEqual(value, b'subsubnode1\0subsubnode\0') def testStrError(self): """Check that we can get an error string""" - self.assertEquals(libfdt.strerror(-libfdt.NOTFOUND), + self.assertEqual(libfdt.strerror(-libfdt.NOTFOUND), 'FDT_ERR_NOTFOUND') def testNextNodeOffset(self): @@ -236,7 +236,7 @@ class PyLibfdtBasicTests(unittest.TestCase): while depth >= 0: node_list.append([depth, self.fdt.get_name(node)]) node, depth = self.fdt.next_node(node, depth, (libfdt.BADOFFSET,)) - self.assertEquals(node_list, [ + self.assertEqual(node_list, [ [0, ''], [1, 'subnode@1'], [2, 'subsubnode'], @@ -253,155 +253,155 @@ class PyLibfdtBasicTests(unittest.TestCase): while node >= 0: node_list.append(self.fdt.get_name(node)) node = self.fdt.next_subnode(node, QUIET_NOTFOUND) - self.assertEquals(node_list, ['subnode@1', 'subnode@2']) + self.assertEqual(node_list, ['subnode@1', 'subnode@2']) def testFirstNextSubnodeOffsetExceptions(self): """Check except handling for first/next subnode functions""" node = self.fdt.path_offset('/subnode@1/subsubnode', QUIET_NOTFOUND) - self.assertEquals(self.fdt.first_subnode(node, QUIET_NOTFOUND), + self.assertEqual(self.fdt.first_subnode(node, QUIET_NOTFOUND), -libfdt.NOTFOUND) with self.assertRaises(FdtException) as e: self.fdt.first_subnode(node) - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) node = self.fdt.path_offset('/subnode@1/ss1', QUIET_NOTFOUND) - self.assertEquals(self.fdt.next_subnode(node, QUIET_NOTFOUND), + self.assertEqual(self.fdt.next_subnode(node, QUIET_NOTFOUND), -libfdt.NOTFOUND) with self.assertRaises(FdtException) as e: self.fdt.next_subnode(node) - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) def testDeleteProperty(self): """Test that we can delete a property""" node_name = '/subnode@1' - self.assertEquals(self.GetPropList(node_name), + self.assertEqual(self.GetPropList(node_name), ['compatible', 'reg', 'prop-int']) node = self.fdt.path_offset('/%s' % node_name) - self.assertEquals(self.fdt.delprop(node, 'reg'), 0) - self.assertEquals(self.GetPropList(node_name), + self.assertEqual(self.fdt.delprop(node, 'reg'), 0) + self.assertEqual(self.GetPropList(node_name), ['compatible', 'prop-int']) def testHeader(self): """Test that we can access the header values""" - self.assertEquals(self.fdt.magic(), 0xd00dfeed) - self.assertEquals(self.fdt.totalsize(), len(self.fdt._fdt)) - self.assertEquals(self.fdt.off_dt_struct(), 88) - self.assertEquals(self.fdt.off_dt_strings(), 652) - self.assertEquals(self.fdt.off_mem_rsvmap(), 40) - self.assertEquals(self.fdt.version(), 17) - self.assertEquals(self.fdt.last_comp_version(), 16) - self.assertEquals(self.fdt.boot_cpuid_phys(), 0) - self.assertEquals(self.fdt.size_dt_strings(), 105) - self.assertEquals(self.fdt.size_dt_struct(), 564) + self.assertEqual(self.fdt.magic(), 0xd00dfeed) + self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt)) + self.assertEqual(self.fdt.off_dt_struct(), 88) + self.assertEqual(self.fdt.off_dt_strings(), 652) + self.assertEqual(self.fdt.off_mem_rsvmap(), 40) + self.assertEqual(self.fdt.version(), 17) + self.assertEqual(self.fdt.last_comp_version(), 16) + self.assertEqual(self.fdt.boot_cpuid_phys(), 0) + self.assertEqual(self.fdt.size_dt_strings(), 105) + self.assertEqual(self.fdt.size_dt_struct(), 564) def testPack(self): """Test that we can pack the tree after deleting something""" orig_size = self.fdt.totalsize() node = self.fdt.path_offset('/subnode@2', QUIET_NOTFOUND) - self.assertEquals(self.fdt.delprop(node, 'prop-int'), 0) - self.assertEquals(orig_size, self.fdt.totalsize()) - self.assertEquals(self.fdt.pack(), 0) + self.assertEqual(self.fdt.delprop(node, 'prop-int'), 0) + self.assertEqual(orig_size, self.fdt.totalsize()) + self.assertEqual(self.fdt.pack(), 0) self.assertTrue(self.fdt.totalsize() < orig_size) - self.assertEquals(self.fdt.totalsize(), len(self.fdt.as_bytearray())) + self.assertEqual(self.fdt.totalsize(), len(self.fdt.as_bytearray())) def testBadPropertyOffset(self): """Test that bad property offsets are detected""" with self.assertRaises(FdtException) as e: self.fdt.get_property_by_offset(13) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) with self.assertRaises(FdtException) as e: self.fdt.first_property_offset(3) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) with self.assertRaises(FdtException) as e: self.fdt.next_property_offset(3) - self.assertEquals(e.exception.err, -libfdt.BADOFFSET) + self.assertEqual(e.exception.err, -libfdt.BADOFFSET) def testBadPathOffset(self): """Test that bad path names are detected""" - with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADPATH)): + with self.assertRaisesRegex(FdtException, get_err(libfdt.BADPATH)): self.fdt.path_offset('not-present') def testQuietAll(self): """Check that exceptions can be masked by QUIET_ALL""" - self.assertEquals(-libfdt.NOTFOUND, + self.assertEqual(-libfdt.NOTFOUND, self.fdt.path_offset('/missing', QUIET_ALL)) - self.assertEquals(-libfdt.BADOFFSET, + self.assertEqual(-libfdt.BADOFFSET, self.fdt.get_property_by_offset(13, QUIET_ALL)) - self.assertEquals(-libfdt.BADPATH, + self.assertEqual(-libfdt.BADPATH, self.fdt.path_offset('missing', QUIET_ALL)) def testIntegers(self): """Check that integers can be passed and returned""" - self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt._fdt, 0)) + self.assertEqual(0, libfdt.fdt_get_phandle(self.fdt._fdt, 0)) node2 = self.fdt.path_offset('/subnode@2') - self.assertEquals(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2)) + self.assertEqual(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2)) def testGetPhandle(self): """Test for the get_phandle() method""" - self.assertEquals(0, self.fdt.get_phandle(0)) + self.assertEqual(0, self.fdt.get_phandle(0)) node2 = self.fdt.path_offset('/subnode@2') - self.assertEquals(0x2000, self.fdt.get_phandle(node2)) + self.assertEqual(0x2000, self.fdt.get_phandle(node2)) def testGetAlias(self): """Test for the get_alias() method""" - self.assertEquals("/subnode@1", self.fdt3.get_alias('s1')) - self.assertEquals("/subnode@1/subsubnode", self.fdt3.get_alias('ss1')) - self.assertEquals("/subnode@1/subsubnode/subsubsubnode", self.fdt3.get_alias('sss1')) + self.assertEqual("/subnode@1", self.fdt3.get_alias('s1')) + self.assertEqual("/subnode@1/subsubnode", self.fdt3.get_alias('ss1')) + self.assertEqual("/subnode@1/subsubnode/subsubsubnode", self.fdt3.get_alias('sss1')) def testParentOffset(self): """Test for the parent_offset() method""" - self.assertEquals(-libfdt.NOTFOUND, + self.assertEqual(-libfdt.NOTFOUND, self.fdt.parent_offset(0, QUIET_NOTFOUND)) with self.assertRaises(FdtException) as e: self.fdt.parent_offset(0) - self.assertEquals(e.exception.err, -libfdt.NOTFOUND) + self.assertEqual(e.exception.err, -libfdt.NOTFOUND) node1 = self.fdt.path_offset('/subnode@2') - self.assertEquals(0, self.fdt.parent_offset(node1)) + self.assertEqual(0, self.fdt.parent_offset(node1)) node2 = self.fdt.path_offset('/subnode@2/subsubnode@0') - self.assertEquals(node1, self.fdt.parent_offset(node2)) + self.assertEqual(node1, self.fdt.parent_offset(node2)) def testNodeOffsetByPhandle(self): """Test for the node_offset_by_phandle() method""" - self.assertEquals(-libfdt.NOTFOUND, + self.assertEqual(-libfdt.NOTFOUND, self.fdt.node_offset_by_phandle(1, QUIET_NOTFOUND)) node1 = self.fdt.path_offset('/subnode@2') - self.assertEquals(node1, self.fdt.node_offset_by_phandle(0x2000)) + self.assertEqual(node1, self.fdt.node_offset_by_phandle(0x2000)) node2 = self.fdt.path_offset('/subnode@2/subsubnode@0') - self.assertEquals(node2, self.fdt.node_offset_by_phandle(0x2001)) + self.assertEqual(node2, self.fdt.node_offset_by_phandle(0x2001)) def get_prop(self, name): return self.fdt2.getprop(0, name) def testGetIntProperties(self): """Test that we can access properties as integers""" - self.assertEquals(0xdeadbeef, self.get_prop("prop-hex32").as_uint32()) - self.assertEquals(123, self.get_prop("prop-uint32").as_uint32()) - self.assertEquals(-2, self.get_prop("prop-int32").as_int32()) - self.assertEquals(9223372036854775807, + self.assertEqual(0xdeadbeef, self.get_prop("prop-hex32").as_uint32()) + self.assertEqual(123, self.get_prop("prop-uint32").as_uint32()) + self.assertEqual(-2, self.get_prop("prop-int32").as_int32()) + self.assertEqual(9223372036854775807, self.get_prop("prop-uint64").as_uint64()) - self.assertEquals(-2, self.get_prop("prop-int64").as_int64()) + self.assertEqual(-2, self.get_prop("prop-int64").as_int64()) def testReserveMap(self): """Test that we can access the memory reserve map""" - self.assertEquals(2, self.fdt.num_mem_rsv()) - self.assertEquals([ 0xdeadbeef00000000, 0x100000], + self.assertEqual(2, self.fdt.num_mem_rsv()) + self.assertEqual([ 0xdeadbeef00000000, 0x100000], self.fdt.get_mem_rsv(0)) - self.assertEquals([123456789, 0o10000], self.fdt.get_mem_rsv(1)) + self.assertEqual([123456789, 0o10000], self.fdt.get_mem_rsv(1)) def testEmpty(self): """Test that we can create an empty tree""" - self.assertEquals(-libfdt.NOSPACE, + self.assertEqual(-libfdt.NOSPACE, Fdt.create_empty_tree(1, (libfdt.NOSPACE,))) fdt = Fdt.create_empty_tree(128) - self.assertEquals(128, fdt.totalsize()) + self.assertEqual(128, fdt.totalsize()) def testOpenInto(self): """Test that we can resize a tree""" fdt = Fdt.create_empty_tree(128) - self.assertEquals(128, fdt.totalsize()) + self.assertEqual(128, fdt.totalsize()) fdt.resize(256) - self.assertEquals(256, fdt.totalsize()) + self.assertEqual(256, fdt.totalsize()) fdt.pack() self.assertTrue(fdt.totalsize() < 128) @@ -409,27 +409,27 @@ class PyLibfdtBasicTests(unittest.TestCase): """Test that we can update and create properties""" node = self.fdt.path_offset('/subnode@1') self.fdt.setprop(node, 'compatible', TEST_BYTES_1) - self.assertEquals(TEST_BYTES_1, self.fdt.getprop(node, 'compatible')) + self.assertEqual(TEST_BYTES_1, self.fdt.getprop(node, 'compatible')) # Check that this property is missing, and that we don't have space to # add it - self.assertEquals(-libfdt.NOTFOUND, + self.assertEqual(-libfdt.NOTFOUND, self.fdt.getprop(node, 'missing', QUIET_NOTFOUND)) - self.assertEquals(-libfdt.NOSPACE, + self.assertEqual(-libfdt.NOSPACE, self.fdt.setprop(node, 'missing', TEST_BYTES_1, quiet=(libfdt.NOSPACE,))) # Expand the device tree so we now have room self.fdt.resize(self.fdt.totalsize() + 50) self.fdt.setprop(node, 'missing', TEST_BYTES_1) - self.assertEquals(TEST_BYTES_1, self.fdt.getprop(node, 'missing')) + self.assertEqual(TEST_BYTES_1, self.fdt.getprop(node, 'missing')) def testSetPropU32(self): """Test that we can update and create integer properties""" node = 0 prop = 'prop-int' self.fdt.setprop_u32(node, prop, TEST_VALUE_1) - self.assertEquals(struct.pack('>I', TEST_VALUE_1), + self.assertEqual(struct.pack('>I', TEST_VALUE_1), self.fdt.getprop(node, prop)) def testSetPropU64(self): @@ -437,16 +437,16 @@ class PyLibfdtBasicTests(unittest.TestCase): node = 0 prop = 'prop-int64' self.fdt.setprop_u64(node, prop, TEST_VALUE64_1) - self.assertEquals(struct.pack('>Q', TEST_VALUE64_1), + self.assertEqual(struct.pack('>Q', TEST_VALUE64_1), self.fdt.getprop(node, prop)) def testSetPropStr(self): """Test that we can set a property to a particular string""" node = 0 prop = 'prop-str' - self.assertEquals(TEST_STRING_1, self.fdt.getprop(node, prop).as_str()) + self.assertEqual(TEST_STRING_1, self.fdt.getprop(node, prop).as_str()) self.fdt.setprop_str(node, prop, TEST_STRING_2) - self.assertEquals(TEST_STRING_2, self.fdt.getprop(node, prop).as_str()) + self.assertEqual(TEST_STRING_2, self.fdt.getprop(node, prop).as_str()) with self.assertRaises(ValueError) as e: self.fdt.getprop(node, 'prop-int').as_str() self.assertIn('lacks nul termination', str(e.exception)) @@ -460,7 +460,7 @@ class PyLibfdtBasicTests(unittest.TestCase): self.fdt.resize(self.fdt.totalsize() + 50) prop = 'prop-unicode' self.fdt.setprop_str(node, prop, TEST_STRING_3) - self.assertEquals(TEST_STRING_3, + self.assertEqual(TEST_STRING_3, self.fdt.getprop(node, prop).as_str()) def testSetName(self): @@ -468,7 +468,7 @@ class PyLibfdtBasicTests(unittest.TestCase): node = self.fdt.path_offset('/subnode@1') old_val = self.fdt.get_name(node) self.fdt.set_name(node, 'test') - self.assertEquals('test', self.fdt.get_name(node)) + self.assertEqual('test', self.fdt.get_name(node)) with self.assertRaises(ValueError) as e: self.fdt.set_name(node, 'some\0name') @@ -481,27 +481,27 @@ class PyLibfdtBasicTests(unittest.TestCase): def testAddDeleteNodes(self): """Test that we can add and delete nodes""" node_name = '/subnode@1' - self.assertEquals(self.GetSubnodes(node_name), ['subsubnode', 'ss1']) + self.assertEqual(self.GetSubnodes(node_name), ['subsubnode', 'ss1']) node = self.fdt.path_offset('%s/subsubnode' % node_name) - self.assertEquals(self.fdt.del_node(node, 'subsubnode'), 0) - self.assertEquals(self.GetSubnodes(node_name), ['ss1']) + self.assertEqual(self.fdt.del_node(node, 'subsubnode'), 0) + self.assertEqual(self.GetSubnodes(node_name), ['ss1']) node = self.fdt.path_offset(node_name) offset = self.fdt.add_subnode(node, 'more') self.assertTrue(offset > 0) - self.assertEquals(self.GetSubnodes(node_name), ['more', 'ss1']) + self.assertEqual(self.GetSubnodes(node_name), ['more', 'ss1']) class PyLibfdtSwTests(unittest.TestCase): """Test class for pylibfdt sequential-write DT creation """ def assertOk(self, err_code): - self.assertEquals(0, err_code) + self.assertEqual(0, err_code) def testCreate(self): # First check the minimum size and also the FdtSw() constructor - with self.assertRaisesRegexp(FdtException, get_err(libfdt.NOSPACE)): - self.assertEquals(-libfdt.NOSPACE, FdtSw(3)) + with self.assertRaisesRegex(FdtException, get_err(libfdt.NOSPACE)): + self.assertEqual(-libfdt.NOSPACE, FdtSw(3)) sw = FdtSw() sw.add_reservemap_entry(TEST_ADDR_1, TEST_SIZE_1) -- 2.24.0.rc1.363.gb1bccd3e3d-goog