Replace various `assert*()` calls with more specific ones.
diff --git a/compiler/util/ir_data_fields_test.py b/compiler/util/ir_data_fields_test.py
index 2853fde..7a0db26 100644
--- a/compiler/util/ir_data_fields_test.py
+++ b/compiler/util/ir_data_fields_test.py
@@ -115,17 +115,17 @@
one_of_field_test = OneofFieldTest()
one_of_field_test.int_field_1 = 10
self.assertEqual(one_of_field_test.int_field_1, 10)
- self.assertEqual(one_of_field_test.int_field_2, None)
+ self.assertIsNone(one_of_field_test.int_field_2)
one_of_field_test.int_field_2 = 20
- self.assertEqual(one_of_field_test.int_field_1, None)
+ self.assertIsNone(one_of_field_test.int_field_1)
self.assertEqual(one_of_field_test.int_field_2, 20)
# Do it again
one_of_field_test.int_field_1 = 10
self.assertEqual(one_of_field_test.int_field_1, 10)
- self.assertEqual(one_of_field_test.int_field_2, None)
+ self.assertIsNone(one_of_field_test.int_field_2)
one_of_field_test.int_field_2 = 20
- self.assertEqual(one_of_field_test.int_field_1, None)
+ self.assertIsNone(one_of_field_test.int_field_1)
self.assertEqual(one_of_field_test.int_field_2, 20)
# Now create a new instance and make sure changes to it are not reflected
@@ -133,8 +133,8 @@
one_of_field_test_2 = OneofFieldTest()
one_of_field_test_2.int_field_1 = 1000
self.assertEqual(one_of_field_test_2.int_field_1, 1000)
- self.assertEqual(one_of_field_test_2.int_field_2, None)
- self.assertEqual(one_of_field_test.int_field_1, None)
+ self.assertIsNone(one_of_field_test_2.int_field_2)
+ self.assertIsNone(one_of_field_test.int_field_1)
self.assertEqual(one_of_field_test.int_field_2, 20)
def test_set_to_none(self):
@@ -206,12 +206,12 @@
def test_copy_values_list(self):
"""Tests that CopyValuesList copies values"""
data_list = ir_data_fields.CopyValuesList(ListCopyTestClass)
- self.assertEqual(len(data_list), 0)
+ self.assertEmpty(data_list)
list_test = ListCopyTestClass(non_union_field=2, seq_field=[5, 6, 7])
list_tests = [ir_data_fields.copy(list_test) for _ in range(4)]
data_list.extend(list_tests)
- self.assertEqual(len(data_list), 4)
+ self.assertLen(data_list, 4)
for i in data_list:
self.assertEqual(i, list_test)
@@ -219,10 +219,10 @@
"""Test that lists passed to constructors are converted to CopyValuesList"""
seq_field = [5, 6, 7]
list_test = ListCopyTestClass(non_union_field=2, seq_field=seq_field)
- self.assertEqual(len(list_test.seq_field), len(seq_field))
+ self.assertLen(list_test.seq_field, len(seq_field))
self.assertIsNot(list_test.seq_field, seq_field)
self.assertEqual(list_test.seq_field, seq_field)
- self.assertTrue(isinstance(list_test.seq_field, ir_data_fields.CopyValuesList))
+ self.assertIsInstance(list_test.seq_field, ir_data_fields.CopyValuesList)
def test_copy_oneof(self):
"""Tests copying an IR data class that has oneof fields."""
diff --git a/compiler/util/ir_data_utils_test.py b/compiler/util/ir_data_utils_test.py
index 82baac6..c54a031 100644
--- a/compiler/util/ir_data_utils_test.py
+++ b/compiler/util/ir_data_utils_test.py
@@ -270,7 +270,7 @@
# We start with an empty type
type_def = ir_data.TypeDefinition()
self.assertTrue(type_def.HasField("attribute"))
- self.assertEqual(len(type_def.attribute), 0)
+ self.assertEmpty(type_def.attribute)
# Now setup a builder
builder = ir_data_utils.builder(type_def)
@@ -284,12 +284,12 @@
builder.attribute.append(attribute)
self.assertEqual(builder.attribute, [attribute])
self.assertTrue(type_def.HasField("attribute"))
- self.assertEqual(len(type_def.attribute), 1)
+ self.assertLen(type_def.attribute, 1)
self.assertEqual(type_def.attribute[0], attribute)
# Lets make it longer and then try iterating
builder.attribute.append(attribute)
- self.assertEqual(len(type_def.attribute), 2)
+ self.assertLen(type_def.attribute, 2)
for attr in builder.attribute:
# Modify the attributes
attr.name.text = "bob"
@@ -305,7 +305,7 @@
name=ir_data.Word(text="bob"),
)
- self.assertEqual(len(type_def.attribute), 3)
+ self.assertLen(type_def.attribute, 3)
for attr in type_def.attribute:
self.assertEqual(attr, new_attribute)
@@ -380,7 +380,7 @@
builder.fields_in_dependency_order.append(11)
self.assertTrue(structure.HasField("fields_in_dependency_order"))
- self.assertEqual(len(structure.fields_in_dependency_order), 2)
+ self.assertLen(structure.fields_in_dependency_order, 2)
self.assertEqual(structure.fields_in_dependency_order[0], 12)
self.assertEqual(structure.fields_in_dependency_order[1], 11)
self.assertEqual(builder.fields_in_dependency_order, [12, 11])