def test_get_column_enforce_type_typeerror(self):
     """Ensure that a TypeError is raised when type enforcement fails in get_column"""
     row = {"col1": 1, "col2": 2}
     with self.assertRaises(TypeError):
         get_column(row, "col1", enforce_type=str)
     with self.assertRaises(TypeError):
         get_column(row, "col2", enforce_type=float)
 def test_get_column_nullable(self):
     """Ensure that the nullable argument to get_column works as expected"""
     row = {"col1": None}
     self.assertEqual(get_column(row, "col1"), None)
     self.assertEqual(get_column(row, "col1", nullable=True), None)
     with self.assertRaises(ValueError):
         get_column(row, "col1", nullable=False)
    def test_get_column_transform_and_enforce_type(self):
        """Test the transform and enforce_type arguments together in get_column"""
        row = {"col1": "1", "col2": 2}

        self.assertEqual(
            get_column(row, "col1", transform=int, enforce_type=int), 1)

        with self.assertRaises(TypeError):
            get_column(row, "col1", transform=str, enforce_type=int)
 def test_get_column_keyerror(self):
     """Ensure that a KeyError is raised when a column name isn't valid in get_column"""
     row = {"col1": 1, "col2": 2, "col3": 3}
     with self.assertRaises(KeyError):
         get_column(row, "col_not_here")
 def test_get_column_enforce_type(self):
     """Ensure that the enforce_type argument to get_column works as expected"""
     row = {"col1": 1, "col2": 2}
     self.assertEqual(get_column(row, "col1", enforce_type=int), 1)
     self.assertEqual(get_column(row, "col2", enforce_type=int), 2)
 def test_get_column_transform_valuerror(self):
     """Ensure that a ValueError is raised when transformation fails in get_column"""
     row = {"col1": "not_an_int"}
     with self.assertRaises(ValueError):
         get_column(row, "col1", transform=int)
 def test_get_column_transform(self):
     """Ensure that the transform argument to get_column works as expected"""
     row = {"col1": 1, "col2": 2, "col3": 3}
     self.assertEqual(get_column(row, "col1", transform=str), "1")
     self.assertEqual(get_column(row, "col2", transform=lambda x: x + 1), 3)
     self.assertEqual(get_column(row, "col3", transform=lambda x: 0), 0)
 def test_get_column_basic(self):
     """Test the basic functionality of the get_column function"""
     row = {"col1": "val1", "col2": 2, "col3": True}
     self.assertEqual(get_column(row, "col1"), "val1")
     self.assertEqual(get_column(row, "col2"), 2)
     self.assertEqual(get_column(row, "col3"), True)