def test_multiple_append(self): ''' Tests if the multiple append is successful or not :return: ''' csvr = CSVReader('test_data.csv') properties = csvr.get_properties_from_csv() dbm = DatabaseManagement('unittest.db', verbose=False) dbm.create_db() dbm.create_table() dbm.append_multiple_rows(properties) conn = dbm.create_connection() c = dbm.create_cursor(conn) c.execute('''SELECT * FROM material_properties''') table = c.fetchall() dbm.close_connection(conn) self.assertEqual(len(table), 100)
def CSVReader_tests(): def callback(msg, fail): return print "+-----------------------------+" print "| CSVReader Tests |" print "+-----------------------------+" csv = CSVReader('testdevice.csv', callback) assert (csv.getColumn('Not existing') == None) print "[+] Successfully handled unexisting column name for getColumn" assert (csv.getColumn('Name')) print "[+] Successfully fetches column" assert (type(csv.getColumn('Name')) == list) print "[+] Correct return type for getColumn" assert (csv.getColumns(['Not existing']) == None) print "[+] Successfully handled unexisting column for getColumns" assert (csv.getColumns(['Name', 'IP'])) print "[+] Successfully fetches columns" assert (type(csv.getColumns(['Name', 'IP'])) == dict) print "[+] Correct return type for getColumns" assert (type(csv.getRows()) == list) print "[+] Correct return type for getRows" for row in csv.getRows(): assert (type(row[1]) == pd.core.series.Series) print "[+] Successfully found Series object in row"
def main(): csv_data = CSVReader() location_controller = LocationController(csv_data.read_locations()) package_controller = PackageController(csv_data.read_packages(), location_controller.locations) print(package_controller.deadlines) print(package_controller.delay_times) print(package_controller.linked_package_graph)
def test_number_of_materials(self): ''' Tests if the number of material is correct ''' csvr = CSVReader('data.csv') properties = csvr.get_properties_from_csv() self.assertEqual(len(properties), 100)
def test_property_tuple(self): ''' Tests is the tuple returned correctly ''' assert_tuple = ('Cd1I2', 3.19, 'White') csvr = CSVReader('data.csv') properties = csvr.get_properties_from_csv() self.assertEqual(properties[0], assert_tuple)
def process_args(): args = get_args() if args.read and args.store: csvr = CSVReader(args.read) properties = csvr.get_properties_from_csv() dbm = DatabaseManagement(db_name=args.store) dbm.create_db() dbm.create_table() dbm.append_multiple_rows(properties) elif args.database and (args.print_rows is not None): dbm = DatabaseManagement(db_name=args.database) dbm.print_info(num_rows=args.print_rows) elif args.database and args.material: dbm = DatabaseManagement(db_name=args.database) dbm.search_by_material(material_name=args.material) elif args.database and args.color: dbm = DatabaseManagement(db_name=args.database) dbm.search_by_color(color=args.color) elif args.database and args.band_gap: dbm = DatabaseManagement(db_name=args.database) dbm.search_by_band_gap(band_gap=args.band_gap, tol_perc=args.tol) elif (args.bg_min is not None) and (args.bg_max is not None): dbm = DatabaseManagement(db_name=args.database) dbm.search_by_band_gap_range(band_gap_min=args.bg_min, band_gap_max=args.bg_max) else: print('\n The arguemnts provided are not valid.')
def test_division_calculator(self): test_data = CSVReader("src/Tests/Division.csv").data for row in test_data: result = round(float(row['Result']), 7) self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_subtraction(self): files = CSVReader("/src/Subtraction.csv").csv_data for row in files: self.assertEqual( self.calc.subtract(row['Value 1'], row['Value 2']), row['Result']) self.assertEqual(self.calc.ans, row['Result'])
def test_division_method_calculator(self): test_data = CSVReader('/src/UnitTestDivision.csv').data for row in test_data: self.assertEqual( self.calculator.divide(row['Value 2'], row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_multiplication_method_calculator(self): test_data = CSVReader('/src/UnitTestMultiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_subtract_method_calculator(self): test_data = CSVReader('/src/UnitTestSubtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 2'], row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_multiplication(self): files = CSVReader("/src/Multiplication.csv").csv_data for row in files: self.assertEqual( self.calc.multiple(row['Value 1'], row['Value 2']), row['Result']) self.assertEqual(self.calc.ans, row['Result'])
def writeToCSV(numOfTeams): # header list headerList = [key.name for key in CSVReader.DataColumnsFromCSV] appendedColumnForTeamName = ["TeamName"] headerList = appendedColumnForTeamName + headerList headerList = dataCustomizer(headerList) dataListToCSV = [] for team in TeamSorter.finalTeamsDictionary: for names in TeamSorter.finalTeamsDictionary[team]: playerInformation = [ team ] + CSVReader.getDictionaryAllPlayerInformation()[names] dataListToCSV.append(dataCustomizer(playerInformation)) dataListToCSV.append([]) print(dataListToCSV) preprocessedDataToWrite = pd.DataFrame(dataListToCSV, columns=headerList) preprocessedDataToWrite.to_csv('generatedTeams.csv', index=False) preprocessedDataToWrite.to_csv('generatedTeamsBACKUP.csv', index=False)
def start(self, export): if not self.user_input: if not self.address: self.address = BAMClient.default_address if not self.username: self.username = BAMClient.default_username if not self.password: self.password = BAMClient.default_password else: self.address = raw_input("IP Address: ") self.username = raw_input("Username: "******"Password: "******"Active configuration to use on BAMClient server: ") else: # TODO: Change this to perhaps accepting the first available configuration in the confirmed list. # This would future-proof the script in the event that configuration names change such that "Ontera Management" no longer exists/is renamed self.configuration = BAMClient.default_configuration self.bam_client.setConfiguration(self.configuration) # TODO: This section is ridiculously messy. Clean this up ASAP self.csv = CSVReader(self.filename, self.errorCallback) self.id_list = self.populateDeviceTypes(self.csv) self.devices, error = self.populateDevices(self.csv) for i in self.devices: self.bam_client.addDevice(i) self.dumpMemory()
def test_addition_calculator(self): test_data = CSVReader("src/Tests/Addition.csv").data for row in test_data: result = int(row['Result']) self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_squ_method_calculator(self): test_data_squ = CSVReader("./src/UnitTest_Square.csv").data for row in test_data_squ: result = int(row['Result']) self.assertEqual(self.calculator.squ(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_squareroot_method_calculator(self): test_data_squareroot = CSVReader("./src/UnitTest _SquareRoot.csv").data for row in test_data_squareroot: result = float(row['Result']) self.assertEqual(self.calculator.squareroot(row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_add_method_calculator(self): test_data_add = CSVReader("./src/UnitTest_Addition.csv").data for row in test_data_add: result = int(row['Result']) self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_sub_method_calculator(self): test_data_sub = CSVReader("./src/UnitTest_Subtraction.csv").data for row in test_data_sub: result = int(row['Result']) self.assertEqual( self.calculator.sub(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_div_method_calculator(self): test_data_div = CSVReader("./src/UnitTest_Division.csv").data for row in test_data_div: result = float(row['Result']) self.assertEqual( self.calculator.div(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_mul_method_calculator(self): test_data_mul = CSVReader("./src/UnitTest_Multiplication.csv").data for row in test_data_mul: result = int(row['Result']) self.assertEqual( self.calculator.mul(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def __getDictionaryOfPlayersSortBySkill(optionToSort, isRandom): try: if optionToSort == 'experience': dictionaryBeforeSorting = CSVReader.getDictionaryAllPlayerSkillLevel( 'experience', isRandom) # Sort the players into decending skill levels sortedDictionary = dict( sorted(dictionaryBeforeSorting.items(), key=operator.itemgetter(1), reverse=True)) return sortedDictionary if optionToSort == 'throwing skills': print('undefined') if optionToSort == 'speed skills': print('undefined') if optionToSort == 'experience and throwing skills': dictionaryBeforeSorting = CSVReader.getDictionaryAllPlayerSkillLevel( 'experience and throwing skills', isRandom) # Sort the players into decending skill levels sortedDictionary = dict( sorted(dictionaryBeforeSorting.items(), key=operator.itemgetter(1), reverse=True)) return sortedDictionary if optionToSort == 'experience and speed skills': print('undefined') if optionToSort == 'experience, throwing skills, and speed skills': print('undefined') except Exception as e: print( "Invalid option to sort/ Option to sort is not defined/ Error in reading saved dictionary" ) print(e.__class__, ' occured')
def test_band_gap_search(self): ''' Tests if band gap search is successful or not :return: ''' csvr = CSVReader('test_data.csv') properties = csvr.get_properties_from_csv() dbm = DatabaseManagement('unittest.db', verbose=False) dbm.create_db() dbm.create_table() dbm.append_multiple_rows(properties) table = dbm.search_by_band_gap(band_gap=2) self.assertEqual(len(table), 8)
def __init__(self, packages, locations) -> None: super().__init__() self.packages = HashTable() self.csvData = CSVReader() now = datetime.now() self.end_of_day = datetime(now.year, now.month, now.day, 17) for row in packages: for location in locations: if location.street == row[Package.addressCol]: package = Package(int(row[Package.idCol]), location, row[Package.DeadlineCol], row[Package.specialNotesCol], row[Package.mass]) self.packages.insert(package) self.duplicate_address_dict = {} for package in self.packages: if package is not None: list_of_duplicate_street_packages = [] for second_package in self.packages: if second_package is not None: if package.destination == second_package.destination: list_of_duplicate_street_packages.append( second_package.destination) self.duplicate_address_dict[ package. destination] = list_of_duplicate_street_packages self.linked_package_graph = Graph( len(self.packages) + 1, len(self.packages) + 1, self.packages) self.__link_packages() self.packages_with_wrong_address = [package for package in self.packages\ if package is not None\ and package.has_wrong_address == True] self.wrong_address_update_times = [ package.will_be_address_updated_at for package in self.packages_with_wrong_address ] self.wrong_address_update_times = self.__remove_duplicates( self.wrong_address_update_times) self.deadlines = self.__get_deadlines() self.deadlines = self.__remove_duplicates(self.deadlines) self.deadlines = sorted(self.deadlines) self.delay_times = self.__get_delay_times() self.delay_times = self.__remove_duplicates(self.delay_times) self.delay_times = sorted(self.delay_times)
class MyTestCase(unittest.TestCase): def setUp(self): self.csv_reader = CSVReader('/src/Unit Test Addition.csv') def test_return_data_as_object(self): num = self.csv_reader.return_data_as_object('number') self.assertIsInstance(num, list) test_class = class_factory('number', self.csv_reader.data[0]) for number in num: self.assertEqual(number.__name__, test_class.__name__)
def singleExecute(groups_dir, group_nr, input_dir, zoom, use_profile): path_provider = PathProvider(str(group_nr) + "\\") data = CSVReader.read_group(groups_dir, group_nr) ps = ProcessService(path_provider, data) if use_profile: ps.profileMerge(input_dir) else: ps.basicMerge(input_dir) ps.basicTile(not use_profile, zoom) return path_provider
def __sortPlayersByGender(optionToSort, isRandom): unsortedGenderDictionaryWithSortedSkills = TeamSorter.__getDictionaryOfPlayersSortBySkill( optionToSort, isRandom) informationDictionary = CSVReader.getDictionaryAllPlayerInformation() for player in unsortedGenderDictionaryWithSortedSkills: # Assigns males if informationDictionary[player][ CSVReader.DataColumnsFromCSV.gender.value - 1].lower() == 'male': TeamSorter.malePlayersArraySortedBySkills.append(player) # Assigns females else: TeamSorter.femalePlayersArraySortedBySkills.append(player)
def App_tests(address, username, password, configuration): print "+-----------------------------+" print "| App Tests |" print "+-----------------------------+" csv_path = "./test.csv" app = App(filename=csv_path, verbose=False, user_input=False, address=address, username=username, password=password, configuration=configuration, upload=False) app.bam_client = BAMClient(app.address, app.username, app.password, app.errorCallback) csv = CSVReader(csv_path, app.errorCallback) # Completely pointless test.... assert (isinstance(app, App)) print "[+] App type is correct" # Verify that formatCell works as intended assert (app.formatCell(" Words go here ") == "Words go here") print "[+] Format cell works on strings" assert (app.formatCell(float('nan')) == "Not Listed") print "[+] Format cell works on 'nan'" assert (app.formatCell(None) == "Not Listed") print "[+] Format cell works on null object" # Test out populating device types. Verify no type confusion occurs, etc. device_types = app.populateDeviceTypes(csv) app.id_list = device_types # Test out populating devices. Verify no type confusion occurs, etc. devices = app.populateDevices(csv) assert (isinstance(devices, list)) print "[+] Devices are correct type" for i in devices[0]: assert (isinstance(i, Device)) print "[+] Device {} is correct type".format(i.name())
def __get_data_loader(self): return {"CSV": CSVReader()}[self.__file_type]
def setUp(self): self.csv_reader = CSVReader('/src/Unit Test Addition.csv')
def testFirstLineOfFile(self): lines = CSVReader.read(csvFile) self.assertEqual("5601 REXLEIGH DR", lines[0]["street"])
def testFourthLineOfFile(self): lines = CSVReader.read(csvFile) self.assertEqual("6932 RUSKUT WAY", lines[3]["street"])
def testThirdLineOfFile(self): lines = CSVReader.read(csvFile) self.assertEqual("9169 GARLINGTON CT", lines[2]["street"])
def testSecondLineOfFile(self): lines = CSVReader.read(csvFile) self.assertEqual("1909 YARNELL WAY", lines[1]["street"])