def test_example_protos_from_path_get_all_in_file(self):
     cns_path = os.path.join(tf.test.get_temp_dir(), 'dummy_example')
     example = test_utils.make_fake_example()
     test_utils.write_out_examples([example], cns_path)
     dummy_examples = oss_utils.example_protos_from_path(cns_path)
     self.assertEqual(1, len(dummy_examples))
     self.assertEqual(example, dummy_examples[0])
Example #2
0
    def test_examples_from_path(self):
        examples = [self.get_fake_example(0), self.get_fake_example(1)]
        examples_path = os.path.join(self.logdir, "test_examples.rio")
        test_utils.write_out_examples(examples, examples_path)

        response = self.server.get("/data/plugin/whatif/examples_from_path?" +
                                   urllib_parse.urlencode({
                                       "examples_path": examples_path,
                                       "max_examples": 2,
                                       "sampling_odds": 1,
                                   }))
        self.assertEqual(200, response.status_code)
        example_strings = json.loads(
            response.get_data().decode("utf-8"))["examples"]
        received_examples = [json.loads(x) for x in example_strings]
        self.assertEqual(2, len(received_examples))
        self.assertEqual(
            0,
            int(received_examples[0]["features"]["feature"]["single_int"]
                ["int64List"]["value"][0]),
        )
        self.assertEqual(
            1,
            int(received_examples[1]["features"]["feature"]["single_int"]
                ["int64List"]["value"][0]),
        )
 def test_example_protos_from_path_get_two(self):
     cns_path = os.path.join(tf.test.get_temp_dir(), 'dummy_example')
     example_one = test_utils.make_fake_example(1)
     example_two = test_utils.make_fake_example(2)
     example_three = test_utils.make_fake_example(3)
     test_utils.write_out_examples(
         [example_one, example_two, example_three], cns_path)
     dummy_examples = oss_utils.example_protos_from_path(cns_path, 2)
     self.assertEqual(2, len(dummy_examples))
     self.assertEqual(example_one, dummy_examples[0])
     self.assertEqual(example_two, dummy_examples[1])
    def test_example_protos_from_path_use_wildcard(self):
        cns_path = os.path.join(tf.test.get_temp_dir(), 'wildcard_example1')
        example1 = test_utils.make_fake_example(1)
        test_utils.write_out_examples([example1], cns_path)
        cns_path = os.path.join(tf.test.get_temp_dir(), 'wildcard_example2')
        example2 = test_utils.make_fake_example(2)
        test_utils.write_out_examples([example2], cns_path)

        wildcard_path = os.path.join(tf.test.get_temp_dir(),
                                     'wildcard_example*')
        dummy_examples = oss_utils.example_protos_from_path(wildcard_path)
        self.assertEqual(2, len(dummy_examples))
    def test_example_protos_from_path_use_wildcard(self):
        cns_path = os.path.join(tf.compat.v1.test.get_temp_dir(),
                                "wildcard_example1")
        example1 = test_utils.make_fake_example(1)
        test_utils.write_out_examples([example1], cns_path)
        cns_path = os.path.join(tf.compat.v1.test.get_temp_dir(),
                                "wildcard_example2")
        example2 = test_utils.make_fake_example(2)
        test_utils.write_out_examples([example2], cns_path)

        wildcard_path = os.path.join(tf.compat.v1.test.get_temp_dir(),
                                     "wildcard_example*")
        dummy_examples = platform_utils.example_protos_from_path(wildcard_path)
        self.assertEqual(2, len(dummy_examples))
Example #6
0
    def test_examples_from_path(self):
        examples = [self.get_fake_example(0), self.get_fake_example(1)]
        examples_path = os.path.join(self.logdir, 'test_examples.rio')
        test_utils.write_out_examples(examples, examples_path)

        response = self.server.get('/data/plugin/whatif/examples_from_path?' +
                                   urllib_parse.urlencode({
                                       'examples_path': examples_path,
                                       'max_examples': 2
                                   }))
        self.assertEqual(200, response.status_code)
        example_strings = json.loads(
            response.get_data().decode('utf-8'))['examples']
        received_examples = [json.loads(x) for x in example_strings]
        self.assertEqual(2, len(received_examples))
        self.assertEqual(
            0,
            int(received_examples[0]['features']['feature']['single_int']
                ['int64List']['value'][0]))
        self.assertEqual(
            1,
            int(received_examples[1]['features']['feature']['single_int']
                ['int64List']['value'][0]))
Example #7
0
 def make_and_write_fake_example(self):
     """Make example and write it to self.examples_path."""
     example = test_utils.make_fake_example()
     test_utils.write_out_examples([example], self.examples_path)
     return example