def test_extract_data_CorrectText(self): txt_to_test = txt_error + txt_valid for bug_path in txt_to_test: in_file = open(bug_path, "r") text = in_file.read() in_file.close() self.assertEqual(extract_data(bug_path), text)
def test_extractData_WrongPath(self): for bug in [20, {}, {'key': 'value'}, []]: with self.assertRaises(TypeError): extract_data(bug)
def test_extractData_NonExistingPath(self): for bug in WrongFolder: with self.assertRaises(IOError): extract_data(bug)
def test_extractData_ErrorPath(self): for bug in ErrorFolder: with self.assertRaises(IOError): extract_data(bug)
def test_extractData_str(self): for bug in ValidFolder: in_file = open(bug, "r") text = in_file.read() in_file.close() self.assertEqual(type(extract_data(bug)), str)
error_path = os.path.join(path, 'error_bug') valid_path = os.path.join(path, 'valid_bug') empty_path = os.path.join(path, 'wrong_bug') ErrorFolder = [ error_path + '\\' + TxtFileName for TxtFileName in os.listdir(error_path) ] ValidFolder = [ valid_path + '\\' + TxtFileName for TxtFileName in os.listdir(valid_path) ] WrongFolder = [ empty_path + '\\' + TxtFileName for TxtFileName in os.listdir(empty_path) ] #---------------------------------------------------------------------------------------- big_list = extract_data(landscapePath).split('\n') pattern_ = extract_data(bug_path).split('\n') #---------------------------------------------------------------------------------------- class TestExtractData(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_extractData_str(self): for bug in ValidFolder: in_file = open(bug, "r") text = in_file.read()
def test_errorPath(self): for n in [20, [], {'index':'Test'}, {set}]: with self.assertRaises(TypeError): extract_data(n)
def test_NoneExsistingPath(self): for txt in txt_wrong: with self.assertRaises(IOError): extract_data(txt)
def test_extract_data_IsString(self): txt_to_test = txt_wrong + txt_error + txt_valid for bug in txt_to_test: self.assertEqual(type(extract_data(bug)), str)
import os import codecs from Code.BugFinder import extract_data, bug_finder, boundry_bug_Counter #_______________________________________________________________________________ path = os.getcwd() valid_path = path + '\\valid_bug' error_path = path + '\\error_bug' wrong_path = path + '\\wrong_bug' #bugempty = os.path.join(path, 'Empty_txt.txt') bugpath = os.path.join(path, 'bug.txt') landscape_path = os.path.join(path, 'landscape.txt') line_list = extract_data(landscape_path).split('\n') pattern_ = extract_data(bugpath).split('\n') #readfile = lambda bugpath: codecs.open(bugpath, 'r').read().split('\n') #print [readfile(text) for text in [bugpath]] txt_valid = [valid_path + '\\' + TxtTestCase for TxtTestCase in os.listdir(valid_path)] txt_error = [error_path + '\\' + TxtTestCase for TxtTestCase in os.listdir(error_path)] txt_wrong = [wrong_path + '\\' + TxtTestCase for TxtTestCase in os.listdir(wrong_path)] print txt_error #------------------------------------------------------------------------------- class TestExtractDara(unittest.TestCase): #Override the setUp() class method to set up initial state for all test methods.