code: def test_generator():
      tmpdir = tempfile.mkdtemp()
      tmps = []
  
      num_of_images = 10
      width = 800
      height = 800
  
      for i in range(num_of_images):
          tmps.append(
              tempfile.NamedTemporaryFile(
                  dir=tmpdir, suffix=".JPEG", delete=False
              )
          )
  
          bytestream = io.BytesIO()
  
          im = Image.new("RGB", (width, height))
          im.save(bytestream, "JPEG")
  
          tmps[i].file.write(bytestream.getvalue())
          tmps[i].flush()
  
      p = Augmentor.Pipeline(tmpdir)
  
      # Test a generator on the same number of images in the folder.
      batch_size = len(p.augmentor_images)
      g = p.keras_generator(batch_size=batch_size)
  
      batch = next(g)
      # A tuple should be returned, containing the augmented images and their labels
      assert len(batch) == 2
  
      X = batch[0]
      y = batch[1]
  
      # They should be the same size/length e.g. 100 images and 100 labels
      assert len(X) == len(y)
  
      assert len(X) == batch_size
      assert len(y) == batch_size
  
      # Because we have in this case one class, y should be of shape (batch_size, 1)
      assert np.shape(y)[0] == batch_size
      assert np.shape(y)[1] == 1
  
      assert np.shape(X)[0] == batch_size
      assert np.shape(X)[1] == width
      assert np.shape(X)[2] == height
      assert np.shape(X)[3] == 3  # For RGB we should have 3 layers
  
      # All labels in y should = 0 because we only have one class.
      for label in y:
          assert label == 0
  
      # Close all temporary files which will also delete them automatically
      for i in range(len(tmps)):
          tmps[i].close()
  
      # Finally remove the directory (and everything in it) as mkdtemp does
      # not delete itself after closing automatically
      shutil.rmtree(tmpdir)
  
file_path: Augmentor/tests/test_generators.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from builtins import *
  import os
  import sys
  import Augmentor
  import tempfile
  import io
  import shutil
  import glob
  import random
  import numpy
  from PIL import Image
  from Augmentor import ImageUtilities
label_desc: Use image node_id 4 for calling a global function with example usage: test_generator() without return types