def setUp(self):
        self.movies = CsvFileHandler("..\\data", "sample_movie_dataset.csv")
        self.movies.extract_data()
        self.movies_data_frame = self.movies.get_data_frame()

        self.valid_cb = ContentBased("Avatar", self.movies_data_frame, ["Title", "Genre", "Director", "Actors"])
        self.invalid_cb = ContentBased("Avatar", self.movies_data_frame, ["Title", "Ge", "Director", "Actors"])
class TestCollaborativeBased(unittest.TestCase):
    def setUp(self):
        self.user_profiles = CsvFileHandler("..\\data",
                                            "user_profile_logs.csv")
        self.user_profiles.extract_data()
        self.user_profiles_data_frame = self.user_profiles.get_data_frame()

        self.valid_cb = CollaborativeBased(self.user_profiles_data_frame, 3)
        self.valid_cb.generate_recommended_results()
        self.invalid_cb = CollaborativeBased(self.user_profiles_data_frame, -1)
        self.invalid_cb.generate_recommended_results()

    def test_constructor(self):
        self.assertIsInstance(self.valid_cb, CollaborativeBased)
        self.assertIsInstance(self.invalid_cb, CollaborativeBased)
        self.assertRaises(TypeError, CollaborativeBased,
                          self.user_profiles_data_frame, "")
        self.assertRaises(TypeError, CollaborativeBased,
                          self.user_profiles_data_frame, 3.14)
        self.assertRaises(TypeError, CollaborativeBased,
                          self.user_profiles_data_frame, None)
        self.assertRaises(TypeError, CollaborativeBased, [], 1)
        self.assertRaises(TypeError, CollaborativeBased, None, 2)

    def test_filter(self):
        self.assertTrue(self.valid_cb.generate_recommended_results())
        self.assertFalse(self.invalid_cb.generate_recommended_results())

    def test_get_recommended_results(self):
        self.assertIsInstance(self.valid_cb.get_recommended_results(), list)
        self.assertEquals(self.invalid_cb.get_recommended_results(), [])
    def setUp(self):
        self.user_profiles = CsvFileHandler("..\\data",
                                            "user_profile_logs.csv")
        self.user_profiles.extract_data()
        self.user_profiles_data_frame = self.user_profiles.get_data_frame()

        self.valid_cb = CollaborativeBased(self.user_profiles_data_frame, 3)
        self.valid_cb.generate_recommended_results()
        self.invalid_cb = CollaborativeBased(self.user_profiles_data_frame, -1)
        self.invalid_cb.generate_recommended_results()
 def test_constructor(self):
     self.assertIsInstance(
         CsvFileHandler("..\\data", "sample_movie_dataset.csv"),
         CsvFileHandler)  # valid path and file
     self.assertIsInstance(
         CsvFileHandler("..\\data", "user_profile_logs.csv"),
         CsvFileHandler)  # valid path and file
     self.assertRaises(ValueError, CsvFileHandler, "..\\data",
                       "non_existent_file.csv")  # valid path, invalid file
     self.assertRaises(
         ValueError, CsvFileHandler, "none\\existent\\path",
         "sample_movie_dataset.csv")  # invalid path, valid file
     self.assertRaises(ValueError, CsvFileHandler, "..\\data",
                       "text_file.txt")  # valid path and file but not a csv
     self.assertRaises(TypeError, CsvFileHandler, None,
                       "text_file.txt")  # testing null arguments
     self.assertRaises(TypeError, CsvFileHandler, "..\\data",
                       None)  # testing null arguments
     self.assertRaises(TypeError, CsvFileHandler, None,
                       None)  # testing null arguments
class TestContentBased(unittest.TestCase):

    def setUp(self):
        self.movies = CsvFileHandler("..\\data", "sample_movie_dataset.csv")
        self.movies.extract_data()
        self.movies_data_frame = self.movies.get_data_frame()

        self.valid_cb = ContentBased("Avatar", self.movies_data_frame, ["Title", "Genre", "Director", "Actors"])
        self.invalid_cb = ContentBased("Avatar", self.movies_data_frame, ["Title", "Ge", "Director", "Actors"])

    def test_constructor(self):
        self.assertIsInstance(self.valid_cb, ContentBased)
        self.assertIsInstance(self.invalid_cb, ContentBased)
        self.assertRaises(TypeError, ContentBased, "Avatar", None, None)
        self.assertRaises(TypeError, ContentBased, None, self.movies_data_frame, None)
        self.assertRaises(TypeError, ContentBased, None, None, [])
        self.assertRaises(TypeError, ContentBased, None, None, None)

    def test_filter(self):
        self.assertIsInstance(self.valid_cb.filter(), list)
        self.assertRaises(KeyError, self.invalid_cb.filter)
class TestCsvFileHandler(unittest.TestCase):
    def setUp(self):
        self.movies = CsvFileHandler("..\\data", "sample_movie_dataset.csv")
        self.user_profiles = CsvFileHandler("..\\data",
                                            "user_profile_logs.csv")

    def test_constructor(self):
        self.assertIsInstance(
            CsvFileHandler("..\\data", "sample_movie_dataset.csv"),
            CsvFileHandler)  # valid path and file
        self.assertIsInstance(
            CsvFileHandler("..\\data", "user_profile_logs.csv"),
            CsvFileHandler)  # valid path and file
        self.assertRaises(ValueError, CsvFileHandler, "..\\data",
                          "non_existent_file.csv")  # valid path, invalid file
        self.assertRaises(
            ValueError, CsvFileHandler, "none\\existent\\path",
            "sample_movie_dataset.csv")  # invalid path, valid file
        self.assertRaises(ValueError, CsvFileHandler, "..\\data",
                          "text_file.txt")  # valid path and file but not a csv
        self.assertRaises(TypeError, CsvFileHandler, None,
                          "text_file.txt")  # testing null arguments
        self.assertRaises(TypeError, CsvFileHandler, "..\\data",
                          None)  # testing null arguments
        self.assertRaises(TypeError, CsvFileHandler, None,
                          None)  # testing null arguments

    def test_get_data_frame(self):
        self.assertIsInstance(self.movies.get_data_frame(),
                              pd.core.frame.DataFrame)
        self.assertIsInstance(self.user_profiles.get_data_frame(),
                              pd.core.frame.DataFrame)

    def test_extract_data(self):
        self.assertIsNone(self.movies.extract_data())
        self.assertIsNone(self.user_profiles.extract_data())
Exemplo n.º 7
0
def get_datagram(path, file):
    data_object = CsvFileHandler(path, file)
    data_object.extract_data()
    return data_object.get_data_frame()
 def setUp(self):
     self.movies = CsvFileHandler("..\\data", "sample_movie_dataset.csv")
     self.user_profiles = CsvFileHandler("..\\data",
                                         "user_profile_logs.csv")