def test_save(self): preprocessor = WordPreprocessor() filepath = os.path.join(os.path.dirname(__file__), 'data/preprocessor.pkl') preprocessor.save(filepath) self.assertTrue(os.path.exists(filepath)) if os.path.exists(filepath): os.remove(filepath)
def test_load(self): X, y = reader.load_data_and_labels(self.filename) p = WordPreprocessor() p.fit(X, y) filepath = os.path.join(os.path.dirname(__file__), 'data/preprocessor.pkl') p.save(filepath) self.assertTrue(os.path.exists(filepath)) loaded_p = WordPreprocessor.load(filepath) x_test1, y_test1 = p.transform(X, y) x_test2, y_test2 = loaded_p.transform(X, y) np.testing.assert_array_equal(x_test1[0], x_test2[0]) # word np.testing.assert_array_equal(x_test1[1], x_test2[1]) # char np.testing.assert_array_equal(y_test1, y_test2) if os.path.exists(filepath): os.remove(filepath)