def test_05(self): x = FileReader() x.add_file("plant_uml") x.read_file() x.find_classes() if len(x.all_my_classes) > 0: pass
def test_04(self): x = FileReader() x.add_file("plant_uml") x.read_file() if x.my_file is "plant_uml": pass if len(x.my_class_content) > 0: pass
def unit_test_five(my_file): print("Run Test 5 - File Reader adds class") x = FileReader() x.add_file(my_file) x.read_file() x.find_classes() if len(x.all_my_classes) > 0: print("Class added from file") else: print("ERROR - class not added")
def main(): system = System(0.02) reader = FileReader(system) reader.read_file() global app app = QApplication(sys.argv) gui = GUI(system) sys.exit(app.exec_())
def unit_test_four(my_file): print("Run Test 4 - File Reader opens file") x = FileReader() x.add_file(my_file) x.read_file() if x.my_file is my_file: print("correct file added") else: print("ERROR - incorrect file added") if len(x.my_class_content) > 0: print("File read complete") else: print("ERROR - file not read")
def test_hash_at_start_skips_line(self, mocked_open): """ Check that a file is read and the data added to the list_lines attribute, ignoring lines that start with '#' """ mocked_open.side_effect = [ mock.mock_open( read_data="#CR\rCRLF\r\n# LF\nNo end of file").return_value ] __file_path = "Path to File" test_object = FileReader() test_object.read_file(__file_path) mocked_open.assert_called_with(__file_path, "r") self.assertEqual(2, len(test_object.list_lines), "Should be 2 items in the list")
def test_five_hyphens_at_start_ends_read(self, mocked_open): """ Check that a file is read and the data added to the list_lines attribute, stopping reading when we see a line that starts with '-----' """ mocked_open.side_effect = [ mock.mock_open( read_data="CR\rCRLF\r\n-----LF\nNo end of file").return_value ] __file_path = "Path to File" test_object = FileReader() test_object.read_file(__file_path) mocked_open.assert_called_with(__file_path, "r") self.assertEqual(2, len(test_object.list_lines), "Should be 2 items in the list")
def test_file_is_open_and_read(self, mocked_open): """ Check that a file is read and the data added to the list_lines attribute """ mocked_open.side_effect = [ mock.mock_open(read_data="Category\tName\tRANKED\tG1\tG2\r" "CRLF\r\n" "LF\n" "No end of file").return_value ] __file_path = "Path to File" test_object = FileReader() test_object.read_file(__file_path) mocked_open.assert_called_with(__file_path, "r") self.assertEqual(4, len(test_object.list_lines), "Should be 4 items in the list")
def validate(self, file, id): self.invalid_data = [] self.clean_data_sets = [] file_reader = FileReader() file_data = file_reader.read_file(file) for data_dic in file_data: self.data_validate(data_dic) if self.invalid_data: if id == "file": return self.invalid_data + self.clean_data_sets if id == "db": return self.clean_data_sets else: return self.clean_data_sets
def learn(): # splits() print("Done Splitting...") tester = Tester() test_set = tester.getTestSet() print("Finished tester Stuff") answers = [] reader = FileReader("training.txt") X = reader.read_file() print("Starting SVD..") svd = TruncatedSVD(n_components=10, n_iter=10, random_state=42) dense = svd.fit_transform(X) print("Done with SVD, starting K Means...") km = KMeans(n_clusters=100) ans = km.fit_predict(dense) print("Done with K Means...") inverseAns = {cluster: [] for cluster in range(100)} # centroids = svd.inverse_transform(km.cluster_centers_) for trainingProdKey, trainingProdIndex in reader.product.items(): inverseAns[ans[trainingProdIndex]].append(trainingProdKey) print('Done inverting clusters') i = 0 for prod in test_set: # print("Inside Loop") answers.append(predict(prod, reader.product, ans, inverseAns)) if i % (len(test_set) // 100) == 0: print("\rDone with {}% of predicting...".format(i / len(test_set)), end='') i = i + 1 print() print(tester.checkAnswers(answers))
def test_file_does_not_exist(self): reader = FileReader() self.assertEqual('', reader.read_file("fake_file.txt"))