def test_add_furniture_append(): inventory.add_furniture("test_invoices.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) inventory.add_furniture("test_invoices.csv", "Edward Data", "KT78", "Kitchen Table", 10) with open('test_invoices.csv', 'r') as file: lines = file.readlines() assert len(lines) == 2 assert lines[0] == "Elisa Miles,LR04,Leather Sofa,25\n" assert lines[1] == "Edward Data,KT78,Kitchen Table,10\n"
def test_add_furniture(test_input, expected, expectation): with expectation: add_furniture(*test_input) with open(test_input[0], 'rb') as file: lines = file.readlines() if lines: last_line = lines[-1] assert expected == last_line
def test_add_furniture(self): """Test add_furniture function.""" open(self.test_invoice_file, 'w').close() inventory.add_furniture(self.test_invoice_file, "Elisa Miles", "LR04", "Leather Sofa", 25) inventory.add_furniture(self.test_invoice_file, "Edward Data", "KT78", "Kitchen Table", 10) with open(self.test_invoice_file, 'r') as file: contents = csv.reader(file) check_row = next(contents) self.assertEqual(self.test_furniture_list, check_row)
def test_add_furniture(tmpdir): ''' tests add_furniture function from inventory.py ''' invoice_file = tmpdir.join("test_invoice_file.csv") add_furniture('LR04', 'Leather Sofa', 25.00, invoice_file.strpath, 'Elisa Miles') assert os.path.isfile(invoice_file) == True with open(invoice_file.strpath, 'r') as i_file: results = i_file.read() #print(results) assert results == 'Elisa Miles, LR04, Leather Sofa, 25.0\n'
def test_add_furniture(self): """ Unit test for the add_furniture function """ inventory_list = [["Elisa Miles", "LR04", "Leather Sofa", "25"], ["Edward Data", "KT78", "Kitchen Table", "10"], ["Alex Gonzales", "BR02", "Queen Mattress", "17"]] for item in inventory_list: inventory.add_furniture("data/rental_data.csv", item[0], item[1], item[2], item[3]) with open("data/rental_data.csv", 'r') as rental_file: reader = csv.reader(rental_file) self.assertListEqual(list(reader), inventory_list)
def test_add_furniture(self): """Test add_furniture()""" self.assertEqual( 'done', add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25)) self.assertEqual( 'done', add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10)) self.assertEqual( 'done', add_furniture("rented_items.csv", "Alex Gonzales", "BR02", "Queen Mattress", 17))
def test_add_furniture(self): ''' Method to test add_furniture method ''' for item in self.furniture_lines: add_furniture(self.test_add_furnture_file, *item) # Read csv file to confirm correct write with open(self.test_add_furnture_file, 'r') as csv_file: csv_reader = csv.reader(csv_file) for i, row in enumerate(csv_reader): # Convert final column (price) to int row[-1] = int(float(row[-1])) # Ensure row is equal to input data self.assertEqual(self.furniture_lines[i], row)
def test_add_furniture(self): """ Tests function to add rental data to csv file """ rental_data = [['Elisa Miles', 'LC04', 'Leather Chair', '12.0'], ['Edward Data', 'CT78', 'Coffee Table', '10.0'], ['Alex Gonzales', 'BR01', 'Bed Frame', '80.0']] invoice_file = "rental_data.csv" for record in rental_data: add_furniture(invoice_file, record[0], record[1], record[2], record[3]) with open(invoice_file, 'r') as csvfile: reader = csv.reader(csvfile) data = list(reader) self.assertEqual(data, rental_data)
def test_add_furniture(self): '''Tests add furniture class''' inventory.add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) self.assertTrue(os.path.exists('rented_items.csv')) inventory.add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10) with open('rented_items.csv', 'r') as file: data_reader = csv.reader(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) new_list = [] for row in data_reader: new_list.append(row) final_list = [["Elisa Miles", "LR04", "Leather Sofa", '25'], ["Edward Data", "KT78", "Kitchen Table", '10']] self.assertEqual(new_list, final_list)
def test_single_customer(self): '''Tests single customer class''' inventory.add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) create_invoice = inventory.single_customer("Susan Wong", "rented_items.csv") create_invoice("test_items.csv") with open('rented_items.csv', 'r') as file: data_reader = csv.reader(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) new_list = [] for row in data_reader: new_list.append(row) final_list = [["Elisa Miles", "LR04", "Leather Sofa", '25'], ["Susan Wong", "LR04", "Leather Sofa", '25'], ["Susan Wong", "KT78", "Kitchen Table", '10'], ["Susan Wong", "BR02", "Queen Mattress", '17']] self.assertEqual(new_list, final_list)
def test_add_furniture_unit(self): """Unit test of the add_furniture function.""" test_file = 'add_furniture_test.csv' add_furniture(test_file, 'Bob Bobbo', 'LT02', 'Cloth Couch', 17.00) add_furniture(test_file, 'Jane Jano', 'TT339', 'Dining Room Table', 25.32) test_result = [] with open(test_file, 'r') as read_file: for line in reader(read_file): test_result.append(line) self.assertListEqual(test_result[-2], ['Bob Bobbo', 'LT02', 'Cloth Couch', '17.0']) self.assertListEqual( test_result[-1], ['Jane Jano', 'TT339', 'Dining Room Table', '25.32'])
def setup_invoice_file(request): add_furniture(INVOICE_FILE, "Elisa Miles", "LR04", "Leather Sofa", 25.00) add_furniture(INVOICE_FILE, "Edward Data", "KT78", "Kitchen Table", 10) add_furniture(INVOICE_FILE, "Alex Gonzales", "Queen Matress", 17) add_furniture(INVOICE_FILE, "Elisa Miles", "Queen Matress", 17.00) def teardown(): remove_file(INVOICE_FILE) request.addfinalizer(teardown)
def test_add_furniture(): ''' Testing adding furniture ''' invoice_file = Path.cwd().with_name('data') / 'invoice_file.csv' remove_file(invoice_file) l.add_furniture(invoice_file, 'Emilia', 'LR04', 'Sofa', 50.0) l.add_furniture(invoice_file, 'John', 'PS60', 'Chair', 150.0) assert os.path.isfile(invoice_file) with open(invoice_file, 'r') as csv_invoice: rows = csv_invoice.readlines() assert rows[0] == 'Emilia,LR04,Sofa,50.0\n' assert rows[1] == 'John,PS60,Chair,150.0\n' assert len(rows) == 2 remove_file(invoice_file)
def test_add_furniture(invoice_file, customer_name, item_code, item_description, item_monthly_price): ''' Testing adding furniture ''' remove_file(invoice_file) l.add_furniture(invoice_file, 'Emilia', 'LR04', 'Sofa', 50.00) l.add_furniture(invoice_file, 'John', 'PS60', 'Chair', 150.00) assert os.path.isfile(invoice_file) with open(invoice_file, 'r') as csv_invoice: rows = csv_invoice.readlines() assert rows[0] == "Emilia, LR04, Sofa, 50.00\n" assert rows[1] == "John, PS60, Chair, 150.00\n" assert len(rows) == 2 remove_file(invoice_file)
def test_add_furniture(): my_path = Path('test.txt') logger.debug('If the test.txt file already exists, remove it.') if my_path.is_file(): os.remove(my_path) logger.debug('Make sure the file is gone.') assert not my_path.is_file() logger.debug('Test file creation on first addition') l.add_furniture('test.txt', 'Jim', '001', 'spaceship', 2000) assert my_path.is_file() logger.debug('Test subsequent additions.') l.add_furniture('test.txt', 'Naomi', '002', 'antimatter', 12000) l.add_furniture('test.txt', 'Amos', '003', 'wrench', 11) test_data = [] with open(my_path) as f: reader = csv.reader(f) for line in reader: test_data.append(line) assert test_data[0] == ['Jim', '001', 'spaceship', '2000'] assert test_data[1] == ['Naomi', '002', 'antimatter', '12000'] assert test_data[2] == ['Amos', '003', 'wrench', '11'] logger.debug('Cleaning up test.txt') if my_path.is_file(): os.remove(my_path)
def test_single_customer(self): """Test single_customer()""" # Test creating new file and adding 1 item inventory.add_furniture('test_rented_items.csv', 'John Adams', 'LK25', 'Leather Chair', 25) # Test adding multiple items into existing file inventory.add_furniture('test_rented_items.csv', 'Ivan Ramen', 'ST68', 'Bar Stool', 15) inventory.add_furniture('test_rented_items.csv', 'Irene Jules', 'SF22', 'Sofa', 150) # Test adding multiple items with single_customer bulk_add = inventory.single_customer('Susan', 'test_rented_items.csv') bulk_add('all_rentals.csv') # Check for added items with open('test_rented_items.csv', 'r') as file: reader = csv.reader(file) data = [] for row in reader: data.append(row) test_list = [[ 'customer_name', 'item_code', 'item_description', 'item_monthly_price' ], ['John Adams', 'LK25', 'Leather Chair', '25'], ['Ivan Ramen', 'ST68', 'Bar Stool', '15'], ['Irene Jules', 'SF22', 'Sofa', '150'], ['Susan', 'HM25', 'Mattress', '150'], ['Susan', 'JK10', 'Grill', '20'], ['Susan', 'YG36', 'Rug', '300']] self.assertEqual(test_list, data)
def test_add_furniture(self): """tests add_furniture""" add_furniture('test_invoice.csv', 'Dorothy Zbornak', 'C100', 'couch', 25) add_furniture('test_invoice.csv', 'Rose Nylund', 'DT100', 'dining table', 20) add_furniture('test_invoice.csv', 'Blanche Devereaux', 'AC100', 'arm chair', 20) add_furniture('test_invoice.csv', 'Sophia Petrillo', 'R100', 'recliner', 30) with open('test_invoice.csv', 'r') as test_invoice: test_csv_reader = csv.reader(test_invoice) test_row = next(test_csv_reader) self.assertEqual(test_row, ['Dorothy Zbornak', 'C100', 'couch', '25'])
def main(): add_furniture("invoice01.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("invoice01.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("invoice01.csv", "Alex Gonzales", "BR02", "Queen Mattress", 17) add_items = single_customer('Susan Wong', 'sw_invoice.csv') add_items('test_items.csv')
def test_add_furniture(self): os.remove('space_items.csv') """tests add_furniture function""" add_furniture('space_items.csv', 'Star Lord', 'C100', 'saber', 25) add_furniture('space_items.csv', 'Thanos', 'DT100', 'infinity stone', 20) add_furniture('space_items.csv', 'Root Tree', 'AC100', 'fertilizer', 20) add_furniture('space_items.csv', 'Iron Man', 'R100', 'fuel', 30) with open('space_items.csv', 'r') as space_items: csv_reader = csv.reader(space_items) next(csv_reader) thanos_row = next(csv_reader) self.assertEqual(thanos_row, ['Thanos', 'DT100', 'infinity stone', '20'])
def test_add_furniture(self): """imports a csv from a file path and makes a json""" scrub_test_file("rented_items.csv") add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("rented_items.csv", "Alex Gonzales", "BR02", "Queen Mattress", 17) test_list = [] with open("rented_items.csv", newline="") as file: for row in file: test_list.append(row) self.assertEqual(test_list[0], ('Elisa Miles,LR04,Leather Sofa,25.0\r\n')) self.assertEqual(test_list[1], ('Edward Data,KT78,Kitchen Table,10.0\r\n')) self.assertEqual(test_list[2], ('Alex Gonzales,BR02,Queen Mattress,17.0\r\n'))
def test_add_furniture(self): """ Test add_furniture function """ inv.LOGGER.info('--- Start Test add_furniture() ---') # remove the existing 'rented_items.csv' file if os.path.exists('rented_items.csv'): os.remove('rented_items.csv') inv.add_furniture('rented_items.csv', 'Elisa Miles', 'LR04', 'Leather Sofa', 25.00) inv.add_furniture('rented_items.csv', 'Edward Data', 'KT78', 'Kitchen Table', 10.00) inv.add_furniture('rented_items.csv', 'Alex Gonzales', 'QM22', 'Queen Matress', 17.00) self.assertEqual(os.path.exists('rented_items.csv'), True) inv.LOGGER.info('--- End Test add_furniture() ---')
def test_add_furniture(_show_all_furniture): # Remove any old furniture listing in the spreadsheet’s data with open('data/rented_items.csv', mode='w') as invoice: invoice.close() l.add_furniture('data/rented_items.csv', 'Elisa Miles', 'LR04', 'Leather Sofa', 25) l.add_furniture('data/rented_items.csv', 'Edward Data', 'KT78', 'Kitchen Table', 10) l.add_furniture('data/rented_items.csv', 'Alex Gonzales', 'BR02', 'Queen Mattress', 17) with open('data/rented_items.csv', mode='r') as invoice: reader = csv.reader(invoice, delimiter=',') for read_furniture, acutal_furniture in zip(reader, _show_all_furniture): assert read_furniture == acutal_furniture
def test_add_furniture(self): """ Tests adding furniture to the CSV file """ expected_content = [ 'Elisa Miles,LR04,Leather Sofa,25\n', 'Edward Data,KT78,Kitchen Table,10\n', 'Alex Gonzales,BR02,Queen Mattress,17\n' ] add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("rented_items.csv", "Alex Gonzales", "BR02", "Queen Mattress", 17) with open("rented_items.csv", "r") as csv_file: content = csv_file.readlines() self.assertEqual(expected_content, content)
def test_add_furniture(self): """Tests inventory.add_furniture""" try: with open(TEST_CSV) as f: lines_pre = f.readlines() except FileNotFoundError: lines_pre = [] # Add single furniture item inventory.add_furniture(TEST_CSV, "Elisa Miles", "LR04", "Leather Sofa", 25) with open(TEST_CSV) as f: lines = f.readlines() new_lines = lines[len(lines_pre):] self.assertEqual(1, len(new_lines)) self.assertEqual("Elisa Miles,LR04,Leather Sofa,25.00", new_lines[0].strip()) # Add another item inventory.add_furniture(TEST_CSV, "Edward Data", "KT78", "Kitchen Table", 10) with open(TEST_CSV) as f: lines = f.readlines() new_lines = lines[len(lines_pre):] self.assertEqual(2, len(new_lines)) self.assertEqual("Elisa Miles,LR04,Leather Sofa,25.00", new_lines[0].strip()) self.assertEqual("Edward Data,KT78,Kitchen Table,10.00", new_lines[1].strip()) # Remove file and assert that it will be created os.remove(TEST_CSV) inventory.add_furniture(TEST_CSV, "Edward Data", "KT78", "Kitchen Table", 10) with open(TEST_CSV) as f: lines = f.readlines() self.assertEqual(1, len(lines)) self.assertEqual("Edward Data,KT78,Kitchen Table,10.00", lines[0].strip())
def test_add_furniture(self): """ testing add_furniture """ add_furniture('invoice_file.csv', 'Elisa Miles', 'LR04', 'Leather Sofa', 25.00) add_furniture('invoice_file.csv', 'Edward Data', 'KT78', 'Kitchen Table', 10.00) add_furniture('invoice_file.csv', 'Alex Gonzales', 'BR02', 'Queen Mattress', 17.00) with open('invoice_file.csv', 'r') as file: csv_contents = [] for row in file: csv_contents.append(row) print(csv_contents) self.assertEqual(csv_contents[0], ('Elisa Miles,LR04,Leather Sofa,25.0\n')) self.assertEqual(csv_contents[1], ('Edward Data,KT78,Kitchen Table,10.0\n')) self.assertEqual(csv_contents[2], ('Alex Gonzales,BR02,Queen Mattress,17.0\n'))
"""UnitTest Module for inventory.py""" from inventory import add_furniture, single_customer add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("rented_items.csv", "Alex Gonzales", "BR01", "Queen Mattress", 17) create_invoice = single_customer("Susan Wong", "rented_items.csv") create_invoice("test_items.csv")
from inventory import add_furniture, single_customer add_furniture('butt', 'y69', '123w', 420) add_furniture('ccat', 'y23', 'aasd32', 22) add_furniture('qqgg', 'sdf2', 'sdsv33', 33) testy = single_customer('dude') testy('rental_file.csv') # cd C:\Users\v-ollock\github\SP_Python220B_2019\students\ScotchWSplenda\lesson08\assignment\ # python -m pylint ./inventory.py
# -*- coding: utf-8 -*- """ Created on Mon May 13 19:07:53 2019 @author: Laura.Fiorentino """ import csv from inventory import add_furniture add_furniture('test_invoice.csv', 'Dorothy Zbornak', 'C100', 'couch', 25) add_furniture('test_invoice.csv', 'Rose Nylund', 'DT100', 'dining table', 20) add_furniture('test_invoice.csv', 'Blanche Devereaux', 'AC100', 'arm chair', 20) add_furniture('test_invoice.csv', 'Sophia Petrillo', 'R100', 'recliner', 30) with open('Dorothy_Zbornak.csv', 'a', newline='') as invoice: invoice_write = csv.writer(invoice, delimiter=',') invoice_write.writerow(['T100', 'television', 50]) invoice_write.writerow(['CT100', 'coffee table', 10]) invoice_write.writerow(['QB100', 'queen bed', 40])
def test_add_furniture(): """Tests file is created in local directory from add_furniture(). Test removes file after check""" add_furniture("invoice01.csv", "Edward Data", "KT78", "Kitchen Table", 10) assert os.path.isfile("invoice01.csv") os.remove("invoice01.csv")
def test_add_furniture(): inventory.add_furniture("test_invoices.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) with open('test_invoices.csv', 'r') as file: lines = file.readlines() assert len(lines) == 1 assert lines[0] == "Elisa Miles,LR04,Leather Sofa,25\n"