How to use summary method in pytest-cov

Best Python code snippet using pytest-cov

summary_test.py

Source:summary_test.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15from __future__ import absolute_import16from __future__ import division17from __future__ import print_function18from six.moves import xrange # pylint: disable=redefined-builtin19from tensorflow.core.framework import summary_pb220from tensorflow.python.framework import constant_op21from tensorflow.python.framework import meta_graph22from tensorflow.python.framework import ops23from tensorflow.python.ops import array_ops24from tensorflow.python.ops import variables25from tensorflow.python.platform import test26from tensorflow.python.summary import summary as summary_lib27class ScalarSummaryTest(test.TestCase):28 def testScalarSummary(self):29 with self.test_session() as s:30 i = constant_op.constant(3)31 with ops.name_scope('outer'):32 im = summary_lib.scalar('inner', i)33 summary_str = s.run(im)34 summary = summary_pb2.Summary()35 summary.ParseFromString(summary_str)36 values = summary.value37 self.assertEqual(len(values), 1)38 self.assertEqual(values[0].tag, 'outer/inner')39 self.assertEqual(values[0].simple_value, 3.0)40 def testScalarSummaryWithFamily(self):41 with self.test_session() as s:42 i = constant_op.constant(7)43 with ops.name_scope('outer'):44 im1 = summary_lib.scalar('inner', i, family='family')45 self.assertEquals(im1.op.name, 'outer/family/inner')46 im2 = summary_lib.scalar('inner', i, family='family')47 self.assertEquals(im2.op.name, 'outer/family/inner_1')48 sm1, sm2 = s.run([im1, im2])49 summary = summary_pb2.Summary()50 summary.ParseFromString(sm1)51 values = summary.value52 self.assertEqual(len(values), 1)53 self.assertEqual(values[0].tag, 'family/outer/family/inner')54 self.assertEqual(values[0].simple_value, 7.0)55 summary.ParseFromString(sm2)56 values = summary.value57 self.assertEqual(len(values), 1)58 self.assertEqual(values[0].tag, 'family/outer/family/inner_1')59 self.assertEqual(values[0].simple_value, 7.0)60 def testSummarizingVariable(self):61 with self.test_session() as s:62 c = constant_op.constant(42.0)63 v = variables.Variable(c)64 ss = summary_lib.scalar('summary', v)65 init = variables.global_variables_initializer()66 s.run(init)67 summ_str = s.run(ss)68 summary = summary_pb2.Summary()69 summary.ParseFromString(summ_str)70 self.assertEqual(len(summary.value), 1)71 value = summary.value[0]72 self.assertEqual(value.tag, 'summary')73 self.assertEqual(value.simple_value, 42.0)74 def testImageSummary(self):75 with self.test_session() as s:76 i = array_ops.ones((5, 4, 4, 3))77 with ops.name_scope('outer'):78 im = summary_lib.image('inner', i, max_outputs=3)79 summary_str = s.run(im)80 summary = summary_pb2.Summary()81 summary.ParseFromString(summary_str)82 values = summary.value83 self.assertEqual(len(values), 3)84 tags = sorted(v.tag for v in values)85 expected = sorted('outer/inner/image/{}'.format(i) for i in xrange(3))86 self.assertEqual(tags, expected)87 def testImageSummaryWithFamily(self):88 with self.test_session() as s:89 i = array_ops.ones((5, 2, 3, 1))90 with ops.name_scope('outer'):91 im = summary_lib.image('inner', i, max_outputs=3, family='family')92 self.assertEquals(im.op.name, 'outer/family/inner')93 summary_str = s.run(im)94 summary = summary_pb2.Summary()95 summary.ParseFromString(summary_str)96 values = summary.value97 self.assertEqual(len(values), 3)98 tags = sorted(v.tag for v in values)99 expected = sorted('family/outer/family/inner/image/{}'.format(i)100 for i in xrange(3))101 self.assertEqual(tags, expected)102 def testHistogramSummary(self):103 with self.test_session() as s:104 i = array_ops.ones((5, 4, 4, 3))105 with ops.name_scope('outer'):106 summ_op = summary_lib.histogram('inner', i)107 summary_str = s.run(summ_op)108 summary = summary_pb2.Summary()109 summary.ParseFromString(summary_str)110 self.assertEqual(len(summary.value), 1)111 self.assertEqual(summary.value[0].tag, 'outer/inner')112 def testHistogramSummaryWithFamily(self):113 with self.test_session() as s:114 i = array_ops.ones((5, 4, 4, 3))115 with ops.name_scope('outer'):116 summ_op = summary_lib.histogram('inner', i, family='family')117 self.assertEquals(summ_op.op.name, 'outer/family/inner')118 summary_str = s.run(summ_op)119 summary = summary_pb2.Summary()120 summary.ParseFromString(summary_str)121 self.assertEqual(len(summary.value), 1)122 self.assertEqual(summary.value[0].tag, 'family/outer/family/inner')123 def testAudioSummary(self):124 with self.test_session() as s:125 i = array_ops.ones((5, 3, 4))126 with ops.name_scope('outer'):127 aud = summary_lib.audio('inner', i, 0.2, max_outputs=3)128 summary_str = s.run(aud)129 summary = summary_pb2.Summary()130 summary.ParseFromString(summary_str)131 values = summary.value132 self.assertEqual(len(values), 3)133 tags = sorted(v.tag for v in values)134 expected = sorted('outer/inner/audio/{}'.format(i) for i in xrange(3))135 self.assertEqual(tags, expected)136 def testAudioSummaryWithFamily(self):137 with self.test_session() as s:138 i = array_ops.ones((5, 3, 4))139 with ops.name_scope('outer'):140 aud = summary_lib.audio('inner', i, 0.2, max_outputs=3, family='family')141 self.assertEquals(aud.op.name, 'outer/family/inner')142 summary_str = s.run(aud)143 summary = summary_pb2.Summary()144 summary.ParseFromString(summary_str)145 values = summary.value146 self.assertEqual(len(values), 3)147 tags = sorted(v.tag for v in values)148 expected = sorted('family/outer/family/inner/audio/{}'.format(i)149 for i in xrange(3))150 self.assertEqual(tags, expected)151 def testSummaryNameConversion(self):152 c = constant_op.constant(3)153 s = summary_lib.scalar('name with spaces', c)154 self.assertEqual(s.op.name, 'name_with_spaces')155 s2 = summary_lib.scalar('name with many $#illegal^: characters!', c)156 self.assertEqual(s2.op.name, 'name_with_many___illegal___characters_')157 s3 = summary_lib.scalar('/name/with/leading/slash', c)158 self.assertEqual(s3.op.name, 'name/with/leading/slash')159 def testSummaryWithFamilyMetaGraphExport(self):160 with ops.name_scope('outer'):161 i = constant_op.constant(11)162 summ = summary_lib.scalar('inner', i)163 self.assertEquals(summ.op.name, 'outer/inner')164 summ_f = summary_lib.scalar('inner', i, family='family')165 self.assertEquals(summ_f.op.name, 'outer/family/inner')166 metagraph_def, _ = meta_graph.export_scoped_meta_graph(export_scope='outer')167 with ops.Graph().as_default() as g:168 meta_graph.import_scoped_meta_graph(metagraph_def, graph=g,169 import_scope='new_outer')170 # The summaries should exist, but with outer scope renamed.171 new_summ = g.get_tensor_by_name('new_outer/inner:0')172 new_summ_f = g.get_tensor_by_name('new_outer/family/inner:0')173 # However, the tags are unaffected.174 with self.test_session() as s:175 new_summ_str, new_summ_f_str = s.run([new_summ, new_summ_f])176 new_summ_pb = summary_pb2.Summary()177 new_summ_pb.ParseFromString(new_summ_str)178 self.assertEquals('outer/inner', new_summ_pb.value[0].tag)179 new_summ_f_pb = summary_pb2.Summary()180 new_summ_f_pb.ParseFromString(new_summ_f_str)181 self.assertEquals('family/outer/family/inner',182 new_summ_f_pb.value[0].tag)183if __name__ == '__main__':...

Full Screen

Full Screen

summaries.py

Source:summaries.py Github

copy

Full Screen

...19Example usage:20 import tensorflow as tf21 slim = tf.contrib.slim22 slim.summaries.add_histogram_summaries(slim.variables.get_model_variables())23 slim.summaries.add_scalar_summary(total_loss, 'Total Loss')24 slim.summaries.add_scalar_summary(learning_rate, 'Learning Rate')25 slim.summaries.add_histogram_summaries(my_tensors)26 slim.summaries.add_zero_fraction_summaries(my_tensors)27"""28from __future__ import absolute_import29from __future__ import division30from __future__ import print_function31from tensorflow.python.framework import ops32from tensorflow.python.ops import logging_ops33from tensorflow.python.ops import nn_impl as nn34from tensorflow.python.summary import summary35def _get_summary_name(tensor, name=None, prefix=None, postfix=None):36 """Produces the summary name given.37 Args:38 tensor: A variable or op `Tensor`.39 name: The optional name for the summary.40 prefix: An optional prefix for the summary name.41 postfix: An optional postfix for the summary name.42 Returns:43 a summary name.44 """45 if not name:46 name = tensor.op.name47 if prefix:48 name = prefix + '/' + name49 if postfix:50 name = name + '/' + postfix51 return name52def add_histogram_summary(tensor, name=None, prefix=None):53 """Adds a histogram summary for the given tensor.54 Args:55 tensor: A variable or op tensor.56 name: The optional name for the summary.57 prefix: An optional prefix for the summary names.58 Returns:59 A scalar `Tensor` of type `string` whose contents are the serialized60 `Summary` protocol buffer.61 """62 return summary.histogram(63 _get_summary_name(tensor, name, prefix), tensor)64def add_image_summary(tensor, name=None, prefix=None, print_summary=False):65 """Adds an image summary for the given tensor.66 Args:67 tensor: a variable or op tensor with shape [batch,height,width,channels]68 name: the optional name for the summary.69 prefix: An optional prefix for the summary names.70 print_summary: If `True`, the summary is printed to stdout when the summary71 is computed.72 Returns:73 An image `Tensor` of type `string` whose contents are the serialized74 `Summary` protocol buffer.75 """76 summary_name = _get_summary_name(tensor, name, prefix)77 # If print_summary, then we need to make sure that this call doesn't add the78 # non-printing op to the collection. We'll add it to the collection later.79 collections = [] if print_summary else None80 op = summary.image(81 name=summary_name, tensor=tensor, collections=collections)82 if print_summary:83 op = logging_ops.Print(op, [tensor], summary_name)84 ops.add_to_collection(ops.GraphKeys.SUMMARIES, op)85 return op86def add_scalar_summary(tensor, name=None, prefix=None, print_summary=False):87 """Adds a scalar summary for the given tensor.88 Args:89 tensor: a variable or op tensor.90 name: the optional name for the summary.91 prefix: An optional prefix for the summary names.92 print_summary: If `True`, the summary is printed to stdout when the summary93 is computed.94 Returns:95 A scalar `Tensor` of type `string` whose contents are the serialized96 `Summary` protocol buffer.97 """98 collections = [] if print_summary else None99 summary_name = _get_summary_name(tensor, name, prefix)100 # If print_summary, then we need to make sure that this call doesn't add the101 # non-printing op to the collection. We'll add it to the collection later.102 op = summary.scalar(103 name=summary_name, tensor=tensor, collections=collections)104 if print_summary:105 op = logging_ops.Print(op, [tensor], summary_name)106 ops.add_to_collection(ops.GraphKeys.SUMMARIES, op)107 return op108def add_zero_fraction_summary(tensor, name=None, prefix=None,109 print_summary=False):110 """Adds a summary for the percentage of zero values in the given tensor.111 Args:112 tensor: a variable or op tensor.113 name: the optional name for the summary.114 prefix: An optional prefix for the summary names.115 print_summary: If `True`, the summary is printed to stdout when the summary116 is computed.117 Returns:118 A scalar `Tensor` of type `string` whose contents are the serialized119 `Summary` protocol buffer.120 """121 name = _get_summary_name(tensor, name, prefix, 'Fraction of Zero Values')122 tensor = nn.zero_fraction(tensor)123 return add_scalar_summary(tensor, name, print_summary=print_summary)124def add_histogram_summaries(tensors, prefix=None):125 """Adds a histogram summary for each of the given tensors.126 Args:127 tensors: A list of variable or op tensors.128 prefix: An optional prefix for the summary names.129 Returns:130 A list of scalar `Tensors` of type `string` whose contents are the131 serialized `Summary` protocol buffer.132 """133 summary_ops = []134 for tensor in tensors:135 summary_ops.append(add_histogram_summary(tensor, prefix=prefix))136 return summary_ops137def add_image_summaries(tensors, prefix=None):138 """Adds an image summary for each of the given tensors.139 Args:140 tensors: A list of variable or op tensors.141 prefix: An optional prefix for the summary names.142 Returns:143 A list of scalar `Tensors` of type `string` whose contents are the144 serialized `Summary` protocol buffer.145 """146 summary_ops = []147 for tensor in tensors:148 summary_ops.append(add_image_summary(tensor, prefix=prefix))149 return summary_ops150def add_scalar_summaries(tensors, prefix=None, print_summary=False):151 """Adds a scalar summary for each of the given tensors.152 Args:153 tensors: a list of variable or op tensors.154 prefix: An optional prefix for the summary names.155 print_summary: If `True`, the summary is printed to stdout when the summary156 is computed.157 Returns:158 A list of scalar `Tensors` of type `string` whose contents are the159 serialized `Summary` protocol buffer.160 """161 summary_ops = []162 for tensor in tensors:163 summary_ops.append(add_scalar_summary(tensor, prefix=prefix,164 print_summary=print_summary))165 return summary_ops166def add_zero_fraction_summaries(tensors, prefix=None):167 """Adds a scalar zero-fraction summary for each of the given tensors.168 Args:169 tensors: a list of variable or op tensors.170 prefix: An optional prefix for the summary names.171 Returns:172 A list of scalar `Tensors` of type `string` whose contents are the173 serialized `Summary` protocol buffer.174 """175 summary_ops = []176 for tensor in tensors:177 summary_ops.append(add_zero_fraction_summary(tensor, prefix=prefix))...

Full Screen

Full Screen

summary.py

Source:summary.py Github

copy

Full Screen

...20 '<!-- PELICAN_BEGIN_SUMMARY -->')21 pelican.settings.setdefault('SUMMARY_END_MARKER',22 '<!-- PELICAN_END_SUMMARY -->')23 pelican.settings.setdefault('SUMMARY_USE_FIRST_PARAGRAPH', False)24def extract_summary(instance):25 # if summary is already specified, use it26 # if there is no content, there's nothing to do27 if hasattr(instance, '_summary'):28 instance.has_summary = True29 return30 if not instance._content:31 instance.has_summary = False32 return33 begin_marker = instance.settings['SUMMARY_BEGIN_MARKER']34 end_marker = instance.settings['SUMMARY_END_MARKER']35 use_first_paragraph = instance.settings['SUMMARY_USE_FIRST_PARAGRAPH']36 remove_markers = True37 content = instance._content38 begin_summary = -139 end_summary = -140 if begin_marker:41 begin_summary = content.find(begin_marker)42 if end_marker:43 end_summary = content.find(end_marker)44 if begin_summary == -1 and end_summary == -1 and use_first_paragraph:45 begin_marker, end_marker = '<p>', '</p>'46 remove_markers = False47 begin_summary = content.find(begin_marker)48 end_summary = content.find(end_marker)49 if begin_summary == -1 and end_summary == -1:50 instance.has_summary = False51 return52 # skip over the begin marker, if present53 if begin_summary == -1:54 begin_summary = 055 else:56 begin_summary = begin_summary + len(begin_marker)57 if end_summary == -1:58 end_summary = None59 summary = content[begin_summary:end_summary]60 if remove_markers:61 # remove the markers from the content62 if begin_summary:63 content = content.replace(begin_marker, '', 1)64 if end_summary:65 content = content.replace(end_marker, '', 1)66 summary = re.sub(r"<div.*>", "", summary)67 summary = re.sub(r"</div>", "", summary)68 instance._content = content69 instance._summary = summary70 instance.has_summary = True71def run_plugin(generators):72 for generator in generators:73 if isinstance(generator, ArticlesGenerator):74 for article in generator.articles:75 extract_summary(article)76 elif isinstance(generator, PagesGenerator):77 for page in generator.pages:78 extract_summary(page)79def register():80 signals.initialized.connect(initialized)81 try:82 signals.all_generators_finalized.connect(run_plugin)83 except AttributeError:84 # NOTE: This results in #314 so shouldn't really be relied on85 # https://github.com/getpelican/pelican-plugins/issues/314...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-cov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful