class_docstr: Tests `TrainSampleHook` class.
    
class_docstr_tok: ["Tests","`","TrainSampleHook","`","class","."]
code: def test_sampling(self):
      hook = hooks.TrainSampleHook(
          params={"every_n_steps": 10},
          model_dir=self.model_dir,
          run_config=tf.contrib.learn.RunConfig(),
      )
  
      global_step = tf.contrib.framework.get_or_create_global_step()
      no_op = tf.no_op()
      hook.begin()
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          sess.run(tf.local_variables_initializer())
          sess.run(tf.tables_initializer())
  
          # pylint: disable=W0212
          mon_sess = monitored_session._HookedSession(sess, [hook])
          # Should trigger for step 0
          sess.run(tf.assign(global_step, 0))
          mon_sess.run(no_op)
  
          outfile = os.path.join(self.sample_dir, "samples_000000.txt")
          with open(outfile, "rb") as readfile:
              self.assertIn(
                  "Prediction followed by Target @ Step 0",
                  readfile.read().decode("utf-8"),
              )
  
          # Should not trigger for step 9
          sess.run(tf.assign(global_step, 9))
          mon_sess.run(no_op)
          outfile = os.path.join(self.sample_dir, "samples_000009.txt")
          self.assertFalse(os.path.exists(outfile))
  
          # Should trigger for step 10
          sess.run(tf.assign(global_step, 10))
          mon_sess.run(no_op)
          outfile = os.path.join(self.sample_dir, "samples_000010.txt")
          with open(outfile, "rb") as readfile:
              self.assertIn(
                  "Prediction followed by Target @ Step 10",
                  readfile.read().decode("utf-8"),
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import os
  import tempfile
  import shutil
  import time
  import tensorflow
  from tensorflow.python.training import monitored_session
  from tensorflow import gfile
  from seq2seq import graph_utils
  from seq2seq.training import hooks
label_desc: Use image node_id 3 for calling the TestTrainSampleHook obj's underlying member method code with example usage: obj.test_sampling() without return types