I am writing to write unit test cases for my project and relatively new to this. I have a function which checks if a given file is a PDF or not (function below):
def file_verify(orig_pdf):
try:
read_pdf = PyPDF2.PdfFileRead(open(orig_pdf,'rb'))
except PyPDF2.utils.PdfReadError:
return orig_pdf, "error: Invalid PDF is not supported!"
else:
return orig_pdf, os.path.basename(orig_pdf) + "is of PDF file format"
Now how would I write a unit test for this function in python to ensure it is working correctly?
Edit: I was able to write the unit test function so far (based on the information I received online) like this:
testdata_filename = 'my pdf location'
class TestVerifyPDF(unittest.TestCase):
def setUp(self):
self.testfile = open(testdata_filename)
self.testfile = self.testfile.read()
def tearDown(self):
self.testfile.close()
def test_pdf(self):
<test here>