def test_valid_url(self): """ Tests for valid data URL """ file = 'listing.csv.gz' with self.assertRaises(ValueError): gd.download_dataset(c.DATASET_PROPERTIES, file)
def test_input_dictionary(self): """ Tests input dictionary has required keys """ dataset_properties = {'d': '2019-04-15', 'c': 'Seattle', 's': 'WA'} file = c.LISTINGS_DATA with self.assertRaises(ValueError): gd.download_dataset(dataset_properties, file)
def test_gd_output_shape(self): """ Tests output dataframe has both rows and columns """ data = gd.download_dataset(c.DATASET_PROPERTIES, c.REVIEWS_DATA) rows, cols = list(data.shape) self.assertTrue(rows > 0 and cols > 0)
""" This module runs unit test for training the machine learning model. """ import unittest import zillowbnb.test.submodule_path import constants as co import convert_to_matrix as cm import get_data as gd import get_cleaned_listings as gcl import train_model as tm DATA = gd.download_dataset(co.DATASET_PROPERTIES, co.LISTINGS_DATA) DATAFRAME = gcl.get_listings_dataframe(DATA, co.LISTING_COLUMNS) X_VAR, Y_VAR = cm.to_matrix(DATAFRAME, co.LISTING_COLUMNS) class TrainModelTest(unittest.TestCase): """ This class runs unit tests for the train_model module. """ def test_input_size(self): """ Tests that train_model will not run if sizes of x_var and y_var do not match. :params self: :returns boolean:
""" This module runs unit tests for ZillowBnb """ import unittest import zillowbnb.test.submodule_path import constants import get_data import sentiment DATA = get_data.download_dataset(constants.DATASET_PROPERTIES, constants.REVIEWS_DATA) class SentimentTest(unittest.TestCase): """ This class runs unit tests for the sentiment submodule """ def test_polarity_check_dtype(self): """ Tests that polarity will not run if datatypes are incorrect :param self: :return boolean: """ with self.assertRaises(ValueError): sentiment.polarity(DATA, 1) def test_polarity_check_column(self): """ Tests that polarity will not run if column isnt in dataframe
""" This module runs unit tests for ZillowBnb """ import unittest import zillowbnb.test.submodule_path import constants import get_data import get_cleaned_listings DATA = get_data.download_dataset(constants.DATASET_PROPERTIES, constants.LISTINGS_DATA) class ListingsTest(unittest.TestCase): """ This class runs unit tests for the get_cleaned_listings submodule """ def test_clean_listings_row(self): """ Tests cleaned_listings data for more than one row :param self: :return boolean: """ listings = get_cleaned_listings.get_listings_dataframe(DATA, constants.LISTING_COLUMNS) self.assertTrue(listings.shape[0] >= 1) def test_listings_col(self): """ Test cleaned_listings data has all 40 columns
import os import pandas as pd import constants as c import get_data as gd import price_prediction as pp # Uncomment below if regenerating all datasets # from submodule import convert_to_matrix as ctm, get_calendar_summary as gcs # from submodule import get_cleaned_listings as gcl, sentiment as s, train_model as tml # Set data folder path DATA_FOLDER = os.path.abspath('../../data') + '/' # Import the datafiles CALENDAR = gd.download_dataset(c.DATASET_PROPERTIES, c.CALENDAR_DATA) LISTINGS = gd.download_dataset(c.DATASET_PROPERTIES, c.LISTINGS_DATA) REVIEWS = gd.download_dataset(c.DATASET_PROPERTIES, c.REVIEWS_DATA) # Clean the calendar dataset # Run: # 1. CALENDAR_DF = gcs.create_calendar_price_averages(CALENDAR) CALENDAR_DF = c.CALENDAR_CSV # Run sentiment analysis on review datasets # Run: (Can take a few hours) # 1. SENTIMENT_SCORES = s.polarity(REVIEWS, 'comments') # 2. SENTIMENT_DF = s.summarize_sentiment(SENTIMENT_SCORES, ['listing_id'], 'compound') SENTIMENT_DF = c.SENTIMENT_CSV # Clean the listings datasets
""" This module runs unit tests for get_calendar_summary """ import unittest import datetime import zillowbnb.test.submodule_path import get_data import get_calendar_summary import constants DATA = get_data.download_dataset(constants.DATASET_PROPERTIES, constants.CALENDAR_DATA) TEST = get_calendar_summary.create_calendar_price_averages(DATA) # used to test error throwing (can not be a string or datetime.datetime) INCORRCT_DATA_TYPE = 9 TEST_DATE = datetime.date(2019, 4, 23) TEST_CURRENCY_STRING = "$1,000.00" class CalendarTest(unittest.TestCase): """ This class runs unit tests for ZillowBnb """ def test_calendar_no_na(self): """ Tests imported calendar data has no empty values :param self: :return boolean: