0

I'm learning how to use unittest in python. I have a class that receives a pandas dataframe in it's init method.

class GenericClass:

    def __init__(self, data):
        
        if not (isinstance(data, pd.DataFrame) or isinstance(data, pd.Series)):
            raise ValueError(f'The object {data} must be a pd.DataFrame or a pd.Series')
        
        self.data = data

I've created a file called test.py. And in this file i'll test the methods of GenericClass.

import unittest
from file import GenericClass

class TestHistan(unittest.TestCase):

    def test_input(self):
        # no idea on how to implement this

My question is, how do i make a test function that tests the inputs passed on the init method of the generic Class?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Occhima
  • 153
  • 2
  • 9
  • What do you mean *"tests the inputs"*? What does the class *do* with that attribute? At the very least you want a test that invalid inputs get rejected and a test that valid ones don't. – jonrsharpe Jul 21 '20 at 15:30
  • Good question. Does this answer it? [How do you test that a Python function throws an exception?](https://stackoverflow.com/a/3166985/1766544) – Kenny Ostrom Jul 21 '20 at 16:48
  • @KennyOstrom, Yes!!, thank you – Occhima Jul 21 '20 at 17:05

0 Answers0