#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
test_pipeline

to see if data flows through app.pipeline module as expected.
"""

import os
import sys
project_folder = os.path.realpath('..')
sys.path.append(project_folder)
import tensorflow as tf
import numpy as np

from PIL import Image
from app.pipeline import generate_data_skeleton, data_pipe, multithreading
from app.settings import IMAGE_PATH, BATCH_SIZE, IMAGE_SHAPE


train_file_array, train_label_array, valid_file_array, valid_label_array =\
    generate_data_skeleton(root_dir=os.path.join(project_folder,
                                                 IMAGE_PATH,
                                                 'train'),
                           valid_size=.15,
                           ext=('.png', '.csv'))
train_image_batch, train_label_batch = data_pipe(
                                        train_file_array,
                                        train_label_array,
                                        num_epochs=None,
                                        shape=IMAGE_SHAPE,
                                        batch_size=BATCH_SIZE,
                                        shuffle=True)
valid_image_batch, valid_label_batch = data_pipe(
                                        valid_file_array,
                                        valid_label_array,
                                        num_epochs=None,
                                        shape=IMAGE_SHAPE,
                                        batch_size=BATCH_SIZE,
                                        shuffle=True)
sess = tf.Session()
init_op = tf.group(tf.local_variables_initializer(),
                   tf.global_variables_initializer())
sess.run(init_op)


@multithreading
def test_queue():
    whole_test_images = list()
    for _ in range(3):
        image_batch = valid_image_batch.eval(session=sess)
        whole_test_images.append(image_batch)
    return [piece for blk in whole_test_images for piece in blk]


with sess:
    total = test_queue()
    n = int(input('choose a image to test'))
    print(total[n])
    Image.fromarray(np.array(total[n], dtype=np.uint8)).show()

@@ -1577,16 +1577,716 @@
 e=True)%0A
+test_file_array, _ = generate_data_skeleton(%0A                                    root_dir=os.path.join(project_folder,%0A                                                          IMAGE_PATH + 'test'),%0A                                    valid_size=None,%0A                                    ext=('.png', '.csv'))%0A# !!! no shuffling and only 1 epoch of test set.%0Atest_image_batch, _ = data_pipe(%0A                                    test_file_array,%0A                                    _,%0A                                    num_epochs=1,%0A                                    shape=IMAGE_SHAPE,%0A                                    batch_size=BATCH_SIZE,%0A                                    shuffle=False)%0A%0A
 sess = t
@@ -2445,24 +2445,32 @@
 ng%0Adef test_
+shuffle_
 queue():%0A   
@@ -2469,35 +2469,36 @@
 e():%0A    whole_t
-est
+rain
 _images = list()
@@ -2570,67 +2570,430 @@
 val(
-session=sess)%0A        whole_test_images.append(image_batch)
+)%0A        whole_train_images.append(image_batch)%0A    return %5Bpiece for blk in whole_train_images for piece in blk%5D%0A%0A%0A@multithreading%0Adef test_unshuffle_queue():%0A    whole_test_images = list()%0A    while True:%0A        try:%0A            test_image = sess.run(test_image_batch)%0A            whole_test_images.append(test_image)%0A            print(test_image.shape)%0A        except tf.errors.OutOfRangeError as e:%0A            break
 %0A   
@@ -3084,16 +3084,26 @@
  = test_
+unshuffle_
 queue()%0A
@@ -3105,16 +3105,18 @@
 ue()%0A   
+ #
  n = int
@@ -3152,16 +3152,18 @@
 t'))%0A   
+ #
  print(t
@@ -3174,16 +3174,18 @@
 %5Bn%5D)%0A   
+ #
  Image.f

update test_pipeline