class TestSystemDataManager(unittest.TestCase):
    def setUp(self):
        self.manager = SystemDataManager("test")

        self.generate_original_image()
        self.generate_patch()

    def generate_original_image(self):
        # save lena as the original image
        lena = data.lena()
        self.lena_path = os.path.join(root_system_data, "test",
                                      original_image_dirname, lena_filename)
        imsave(self.lena_path, lena)

    def generate_patch(self):
        # create patch
        patch = crop(data.lena(), (15, 15))
        self.lena_patch_path = os.path.join(root_system_data, "test",
                                            patch_dirname, lena_filename)
        imsave(self.lena_patch_path, patch)

    def test_patches(self):
        for patch in self.manager.patches():
            self.assertEqual(patch.shape, (20, 20, 3))

    def test_original_images(self):
        images = self.manager.original_images()
        n_images = sum(1 for _ in images)
        self.assertEqual(n_images, 1)

        lena = data.lena()
        for image in images:
            self.assertEqual(image.shape, lena.shape)

    def test_situations(self):
        situations = np.array([5.0,0,0,0,1,0,0])
        self.assertTrue((self.manager.situations() == situations).all())

    def test_has_valid_format(self):
        self.assertTrue(self.manager.has_valid_format())

        os.remove(self.lena_patch_path)

        self.assertFalse(self.manager.has_valid_format())

        self.generate_patch()
    def train_situation_feature_map(self):
        manager = SystemDataManager(dataset_system_male)
        situations = manager.situations()
        patches = manager.patches()
        system_features = patches_to_features(patches)

        manager = UserDataManager(self.username)
        patches = manager.patches()
        user_features = patches_to_features(patches)

        features, split_point = concatenate(user_features, system_features)

        features = scale(features)
        #features = decompose(features, 10)

        user_features, system_features = split(features, split_point)

        self.regressor.fit(situations, system_features)
        self.knn.fit(user_features)
    def setUp(self):
        self.manager = SystemDataManager("test")

        self.generate_original_image()
        self.generate_patch()