Ejemplo n.º 1
0
    def test_AnnotateVideo_with_side_input_context(self):
        videos_to_annotate = [
            'gs://cloud-samples-data/video/cat.mp4',
            'gs://some-other-video/sample.mp4',
            'gs://some-other-video/sample_2.mp4'
        ]
        video_contexts = [
            ('gs://cloud-samples-data/video/cat.mp4', self.video_ctx),
            ('gs://some-other-video/sample.mp4', self.video_ctx),
        ]

        expected_counter = len(videos_to_annotate)
        with mock.patch.object(videointelligenceml,
                               'get_videointelligence_client',
                               return_value=self._mock_client):
            p = beam.Pipeline()
            context_side_input = (
                p | "Video contexts" >> beam.Create(video_contexts))

            _ = (
                p
                | "Create data" >> beam.Create(videos_to_annotate)
                | "Annotate video" >> videointelligenceml.AnnotateVideo(
                    self.features,
                    context_side_input=beam.pvalue.AsDict(context_side_input)))
            result = p.run()
            result.wait_until_finish()

            read_filter = MetricsFilter().with_name('API Calls')
            query_result = result.metrics().query(read_filter)
            if query_result['counters']:
                read_counter = query_result['counters'][0]
                self.assertTrue(read_counter.committed == expected_counter)
Ejemplo n.º 2
0
    def test_AnnotateVideo_b64_content(self):
        base_64_encoded_video = \
          b'YmVnaW4gNjQ0IGNhdC12aWRlby5tcDRNICAgICgmOVQ+NyFNPCMwUi4uZmFrZV92aWRlb'
        videos_to_annotate = [
            base_64_encoded_video,
            base_64_encoded_video,
            base_64_encoded_video,
        ]
        expected_counter = len(videos_to_annotate)
        with mock.patch.object(videointelligenceml,
                               'get_videointelligence_client',
                               return_value=self._mock_client):
            p = beam.Pipeline()
            _ = (p
                 | "Create data" >> beam.Create(videos_to_annotate)
                 | "Annotate video" >> videointelligenceml.AnnotateVideo(
                     self.features))
            result = p.run()
            result.wait_until_finish()

            read_filter = MetricsFilter().with_name('API Calls')
            query_result = result.metrics().query(read_filter)
            if query_result['counters']:
                read_counter = query_result['counters'][0]
                self.assertTrue(read_counter.committed == expected_counter)
Ejemplo n.º 3
0
 def test_AnnotateVideo_bad_input(self):
     videos_to_annotate = [123456789, 123456789, 123456789]
     with mock.patch.object(videointelligenceml,
                            'get_videointelligence_client',
                            return_value=self._mock_client):
         with self.assertRaises(TypeCheckError):
             p = beam.Pipeline()
             _ = (p
                  | "Create data" >> beam.Create(videos_to_annotate)
                  | "Annotate video" >> videointelligenceml.AnnotateVideo(
                      self.features))
             result = p.run()
             result.wait_until_finish()
Ejemplo n.º 4
0
    def test_AnnotateVideo_URIs(self):
        videos_to_annotate = [
            'gs://cloud-samples-data/video/cat.mp4',
            'gs://cloud-samples-data/video/cat.mp4'
        ]
        expected_counter = len(videos_to_annotate)
        with mock.patch.object(videointelligenceml,
                               'get_videointelligence_client',
                               return_value=self._mock_client):
            p = beam.Pipeline()
            _ = (p
                 | "Create data" >> beam.Create(videos_to_annotate)
                 | "Annotate video" >> videointelligenceml.AnnotateVideo(
                     self.features))
            result = p.run()
            result.wait_until_finish()

            read_filter = MetricsFilter().with_name('API Calls')
            query_result = result.metrics().query(read_filter)
            if query_result['counters']:
                read_counter = query_result['counters'][0]
                self.assertTrue(read_counter.committed == expected_counter)