def test_file_one(self): test001File = "TestFiles/test_one.001" results = self.read_results_file("TestFiles/test_one_result.txt") dataDict = cpap_extraction.extract_file(test001File) dataFile = cpap_extraction.open_file(test001File) header = cpap_extraction.extract_header(dataFile) headerstr = str(header).strip() self.assertEqual(headerstr, results.pop(0)) for packet in dataDict["packet_data"]: self.assertEqual(str(packet).strip(), results.pop(0)) self.assertTrue( results.pop(0) in str(dataDict["data"][5]["data_vals"])) self.assertTrue( results.pop(0) in str(dataDict["raw"]["Respitory Rate"]["Values"])) self.assertTrue(len(results) == 0)
def test_open_file_does_not_exist(self, mocked_os, mocked_file): # Use a context manager to test raising exceptions: # https://docs.python.org/3.6/library/unittest.html with self.assertRaises(FileNotFoundError): cpap_extraction.open_file('Any file')
def test_open_file_exists(self, mocked_os, mocked_file): with self.assertRaises(TypeError): cpap_extraction.open_file('Any file') mocked_file.assert_called_once_with('Any file', 'rb')