def testDoesPDFAlreadyExist(self): remove_data('plot_x_vs_y.pdf') plot_x_vs_y(get_trips_and_weather(),'Annual Member','Min_TemperatureF', 'plot_x_vs_y') result = plot_x_vs_y(get_trips_and_weather(),'Annual Member', 'Min_TemperatureF','plot_x_vs_y') self.assertTrue(result)
def test_invalid_plot_no_file(self): """ Here we check that the pdf file is NOT generated when a valid data frame, but an invalid column are supplied to the function. """ data = get_trips_and_weather() fileName = 'Temp_and_Membership_invalid' plot_x_vs_y(data,'Mean_Temperaturezzzz_F','Annual Member', fileName) filePath = os.getcwd() + '\\' + fileName + '.pdf' self.assertFalse(os.path.exists(filePath))
def test_invalid_plot_exception_trhown(self): """ Here we check that a TypeError exception is thrown when a valid data frame, but an invalid column are supplied to the function. """ data = get_trips_and_weather() fileName = 'Temp_and_Membership_invalid' plot_x_vs_y(data,'Mean_Temperaturezzzz_F','Annual Member', fileName) filePath = os.getcwd() + '\\' + fileName + '.pdf' #self.assertFalse(os.path.exists(filePath)) self.assertRaises(KeyError)
def test_valid_plot(self): """ Here we check that the pdf file is properly generated when a valid data frame and columns are supplied as arguments to the function. """ # download the trip and weather data # NOTE: we turn off alerts about whether or not data # has already been downloaded within the pronto_utils.py # code in order to make unit test output cleaner data = get_trips_and_weather() fileName = 'Temp_and_Membership' plot_x_vs_y(data,'Mean_Temperature_F','Annual Member', fileName) filePath = os.getcwd() + '\\' + fileName + '.pdf' self.assertTrue(os.path.exists(filePath))
def testWasPDFCreated(self): remove_data('plot_x_vs_y.pdf') plot_x_vs_y(get_trips_and_weather(),'Annual Member','Min_TemperatureF', 'plot_x_vs_y') self.assertTrue(os.path.exists('plot_x_vs_y.pdf'))
def testAlreadyExists(self): # 1 data = pd.read_csv("fake_data.csv") data = pd.read_csv("fake_data.csv") result = plot_x_vs_y(data, "fakex", "fakey", "fakeplot.png") self.assertTrue(result[2])
def testNewPlot(self): # 1 remove_data("fakeplot.png") data = pd.read_csv("fake_data.csv") result = plot_x_vs_y(data, "fakex", "fakey", "fakeplot.png") self.assertFalse(result[2])
def testGoodFileName(self): # 1 data = pd.read_csv("fake_data.csv") result = plot_x_vs_y(data, "fakex", "fakey", "fakeplot.png") self.assertTrue(result[1])
def testPlotSuccessful(self): # 1 remove_data("fakeplot.png") data = pd.read_csv("fake_data.csv") result = plot_x_vs_y(data, "fakex", "fakey", "fakeplot.png") self.assertTrue(result[0])
def testEmptyDataFrame(self): #Make fake data frame to test code data = [] result = plot_x_vs_y(data, 'A', 'B', 'a_vs_b') expected_result = 'Please enter valid data frame.' self.assertEqual(result, expected_result)
def testColumnNames(self): #Make fake data frame to test code data = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']) result = plot_x_vs_y(data, 'Apple', 'B', 'a_vs_b') expected_result = 'Please verify column names are correct.' self.assertEqual(result, expected_result)
def testPlotSaves(self): #Make fake data frame to test code data = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']) result = plot_x_vs_y(data, 'A', 'B', 'a_vs_b') expected_result = 'Figure a_vs_b successfully saved.' self.assertEqual(result, expected_result)