コード例 #1
0
 def testExactlyEnoughInstances(self):
     test_instances = b'\n'.join([b'{"images": [0, 1], "key": 3}'] * 100)
     instance_file = io.BytesIO(test_instances)
     instances = predict_utilities.ReadInstances(instance_file,
                                                 JSON_FORMAT,
                                                 limit=100)
     self.assertEqual(100, len(instances))
コード例 #2
0
 def testEmptyLineJson(self):
     test_instances = (b'{"images": [0, 1], "key": 3}\n\n'
                       b'{"images": [0, 1], "key": 3}')
     instance_file = io.BytesIO(test_instances)
     with self.assertRaisesRegex(core_exceptions.Error,
                                 'Empty line is not allowed'):
         predict_utilities.ReadInstances(instance_file, JSON_FORMAT)
コード例 #3
0
 def testTooManyInstances(self):
     test_instances = b'\n'.join([b'{"images": [0, 1], "key": 3}'] * 101)
     instance_file = io.BytesIO(test_instances)
     with self.assertRaisesRegex(core_exceptions.Error, 'no more than 100'):
         predict_utilities.ReadInstances(instance_file,
                                         JSON_FORMAT,
                                         limit=100)
コード例 #4
0
    def testTooManyInstancesNoLimit(self):
        test_instances = b'\n'.join([b'{"images": [0, 1], "key": 3}'] * 100)
        instance_file = io.BytesIO(test_instances)
        instance_file = io.BytesIO(test_instances)

        instances = predict_utilities.ReadInstances(instance_file,
                                                    JSON_FORMAT,
                                                    limit=None)
        self.assertEqual(100, len(instances))
コード例 #5
0
 def testMultipleJsonInstances(self):
     test_instances = (b'{"images": [0, 1], "key": 3}\n'
                       b'{"images": [3, 2], "key": 2}\n'
                       b'{"images": [2, 1], "key": 1}')
     instance_file = io.BytesIO(test_instances)
     instances = predict_utilities.ReadInstances(instance_file, JSON_FORMAT)
     expected_instances = [{
         'images': [0, 1],
         'key': 3
     }, {
         'images': [3, 2],
         'key': 2
     }, {
         'images': [2, 1],
         'key': 1
     }]
     self.assertEqual(expected_instances, instances)
コード例 #6
0
 def testEmptyFile(self):
     instance_file = io.BytesIO(b'')
     with self.assertRaisesRegex(core_exceptions.Error,
                                 'No valid instance was found.'):
         predict_utilities.ReadInstances(instance_file, JSON_FORMAT)
コード例 #7
0
 def testMultipleTextInstances(self):
     instance_file = io.BytesIO(b'2, 3\n4, 5')
     instances = predict_utilities.ReadInstances(instance_file, TEXT_FORMAT)
     expected_instances = ['2, 3', '4, 5']
     self.assertEqual(expected_instances, instances)
コード例 #8
0
 def testTextInstancesTrailingNewline(self):
     instance_file = io.BytesIO(b'abcd\n')
     instances = predict_utilities.ReadInstances(instance_file, TEXT_FORMAT)
     expected_instances = ['abcd']
     self.assertEqual(expected_instances, instances)
コード例 #9
0
 def testTextInstancesUTF8BOM(self):
     instance_file = io.BytesIO(b'\xef\xbb\xbfabcd')
     instances = predict_utilities.ReadInstances(instance_file, TEXT_FORMAT)
     expected_instances = ['abcd']
     self.assertEqual(expected_instances, instances)
コード例 #10
0
 def testJsonInstancesTrailingNewline(self):
     instance_file = io.BytesIO(b'{"images": [0, 1], "key": 3}\n')
     instances = predict_utilities.ReadInstances(instance_file, JSON_FORMAT)
     expected_instances = [{'images': [0, 1], 'key': 3}]
     self.assertEqual(expected_instances, instances)
コード例 #11
0
 def testEmptyLineText(self):
     instance_file = io.BytesIO(b'2, 3\n\n2, 3')
     with self.assertRaisesRegex(core_exceptions.Error,
                                 'Empty line is not allowed'):
         predict_utilities.ReadInstances(instance_file, TEXT_FORMAT)
コード例 #12
0
 def testNewlineOnlyTEXT(self):
     instance_file = io.BytesIO(b'\n')
     with self.assertRaisesRegex(core_exceptions.Error,
                                 'Empty line is not allowed'):
         predict_utilities.ReadInstances(instance_file, TEXT_FORMAT)