The following issues were found
java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
173 issues
Line: 425
private void assertImmutable(LongList list) {
if (list.contains(1L)) {
throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
}
try {
list.add(1L);
assertWithMessage("expected exception").fail();
Reported by PMD.
Line: 48
/** Tests for {@link LongArrayList}. */
@RunWith(JUnit4.class)
public class LongArrayListTest {
private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1);
private static final LongArrayList TERTIARY_LIST = newImmutableLongArrayList(1, 2, 3);
private LongArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link LongArrayList}. */
@RunWith(JUnit4.class)
public class LongArrayListTest {
private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1);
private static final LongArrayList TERTIARY_LIST = newImmutableLongArrayList(1, 2, 3);
private LongArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link LongArrayList}. */
@RunWith(JUnit4.class)
public class LongArrayListTest {
private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1);
private static final LongArrayList TERTIARY_LIST = newImmutableLongArrayList(1, 2, 3);
private LongArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link LongArrayList}. */
@RunWith(JUnit4.class)
public class LongArrayListTest {
private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1);
private static final LongArrayList TERTIARY_LIST = newImmutableLongArrayList(1, 2, 3);
private LongArrayList list;
Reported by PMD.
Line: 53
private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1);
private static final LongArrayList TERTIARY_LIST = newImmutableLongArrayList(1, 2, 3);
private LongArrayList list;
@Before
public void setUp() throws Exception {
list = new LongArrayList();
}
Reported by PMD.
Line: 62
@Test
public void testEmptyListReturnsSameInstance() {
assertThat(LongArrayList.emptyList()).isSameInstanceAs(LongArrayList.emptyList());
}
@Test
public void testEmptyListIsImmutable() {
assertImmutable(LongArrayList.emptyList());
Reported by PMD.
Line: 81
}
@Test
public void testModificationWithIteration() {
list.addAll(asList(1L, 2L, 3L, 4L));
Iterator<Long> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((long) list.get(0)).isEqualTo(1L);
assertThat((long) iterator.next()).isEqualTo(1L);
Reported by PMD.
Line: 84
public void testModificationWithIteration() {
list.addAll(asList(1L, 2L, 3L, 4L));
Iterator<Long> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((long) list.get(0)).isEqualTo(1L);
assertThat((long) iterator.next()).isEqualTo(1L);
list.set(0, 1L);
assertThat((long) iterator.next()).isEqualTo(2L);
Reported by PMD.
Line: 93
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.
java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
173 issues
Line: 427
private void assertImmutable(FloatList list) {
if (list.contains(1F)) {
throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
}
try {
list.add(1F);
assertWithMessage("expected exception").fail();
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 53
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
@Before
public void setUp() throws Exception {
list = new FloatArrayList();
}
Reported by PMD.
Line: 62
@Test
public void testEmptyListReturnsSameInstance() {
assertThat(FloatArrayList.emptyList()).isSameInstanceAs(FloatArrayList.emptyList());
}
@Test
public void testEmptyListIsImmutable() {
assertImmutable(FloatArrayList.emptyList());
Reported by PMD.
Line: 81
}
@Test
public void testModificationWithIteration() {
list.addAll(asList(1F, 2F, 3F, 4F));
Iterator<Float> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((float) list.get(0)).isEqualTo(1F);
assertThat((float) iterator.next()).isEqualTo(1F);
Reported by PMD.
Line: 84
public void testModificationWithIteration() {
list.addAll(asList(1F, 2F, 3F, 4F));
Iterator<Float> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((float) list.get(0)).isEqualTo(1F);
assertThat((float) iterator.next()).isEqualTo(1F);
list.set(0, 1F);
assertThat((float) iterator.next()).isEqualTo(2F);
Reported by PMD.
Line: 93
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.
java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
172 issues
Line: 48
/** Tests for {@link BooleanArrayList}. */
@RunWith(JUnit4.class)
public class BooleanArrayListTest {
private static final BooleanArrayList UNARY_LIST = newImmutableBooleanArrayList(true);
private static final BooleanArrayList TERTIARY_LIST =
newImmutableBooleanArrayList(true, false, true);
Reported by PMD.
Line: 48
/** Tests for {@link BooleanArrayList}. */
@RunWith(JUnit4.class)
public class BooleanArrayListTest {
private static final BooleanArrayList UNARY_LIST = newImmutableBooleanArrayList(true);
private static final BooleanArrayList TERTIARY_LIST =
newImmutableBooleanArrayList(true, false, true);
Reported by PMD.
Line: 48
/** Tests for {@link BooleanArrayList}. */
@RunWith(JUnit4.class)
public class BooleanArrayListTest {
private static final BooleanArrayList UNARY_LIST = newImmutableBooleanArrayList(true);
private static final BooleanArrayList TERTIARY_LIST =
newImmutableBooleanArrayList(true, false, true);
Reported by PMD.
Line: 48
/** Tests for {@link BooleanArrayList}. */
@RunWith(JUnit4.class)
public class BooleanArrayListTest {
private static final BooleanArrayList UNARY_LIST = newImmutableBooleanArrayList(true);
private static final BooleanArrayList TERTIARY_LIST =
newImmutableBooleanArrayList(true, false, true);
Reported by PMD.
Line: 54
private static final BooleanArrayList TERTIARY_LIST =
newImmutableBooleanArrayList(true, false, true);
private BooleanArrayList list;
@Before
public void setUp() throws Exception {
list = new BooleanArrayList();
}
Reported by PMD.
Line: 63
@Test
public void testEmptyListReturnsSameInstance() {
assertThat(BooleanArrayList.emptyList()).isSameInstanceAs(BooleanArrayList.emptyList());
}
@Test
public void testEmptyListIsImmutable() {
assertImmutable(BooleanArrayList.emptyList());
Reported by PMD.
Line: 82
}
@Test
public void testModificationWithIteration() {
list.addAll(asList(true, false, true, false));
Iterator<Boolean> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((boolean) list.get(0)).isEqualTo(true);
assertThat((boolean) iterator.next()).isEqualTo(true);
Reported by PMD.
Line: 85
public void testModificationWithIteration() {
list.addAll(asList(true, false, true, false));
Iterator<Boolean> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((boolean) list.get(0)).isEqualTo(true);
assertThat((boolean) iterator.next()).isEqualTo(true);
list.set(0, true);
assertThat((boolean) iterator.next()).isEqualTo(false);
Reported by PMD.
Line: 94
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.
Line: 94
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.
python/google/protobuf/internal/type_checkers.py
164 issues
Line: 167
Column: 48
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), six.integer_types))
raise TypeError(message)
if not self._MIN <= int(proposed_value) <= self._MAX:
raise ValueError('Value out of range: %d' % proposed_value)
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
# (e.g. the C++ implementation) simpler.
proposed_value = self._TYPE(proposed_value)
Reported by Pylint.
Line: 167
Column: 12
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), six.integer_types))
raise TypeError(message)
if not self._MIN <= int(proposed_value) <= self._MAX:
raise ValueError('Value out of range: %d' % proposed_value)
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
# (e.g. the C++ implementation) simpler.
proposed_value = self._TYPE(proposed_value)
Reported by Pylint.
Line: 172
Column: 22
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
# (e.g. the C++ implementation) simpler.
proposed_value = self._TYPE(proposed_value)
return proposed_value
def DefaultValue(self):
return 0
Reported by Pylint.
Line: 59
Column: 1
if six.PY3:
long = int
from google.protobuf.internal import api_implementation
from google.protobuf.internal import decoder
from google.protobuf.internal import encoder
from google.protobuf.internal import wire_format
from google.protobuf import descriptor
Reported by Pylint.
Line: 217
Column: 9
try:
proposed_value = proposed_value.decode('utf-8')
except UnicodeDecodeError:
raise ValueError('%.1024r has type bytes, but isn\'t valid UTF-8 '
'encoding. Non-UTF-8 strings must be converted to '
'unicode objects before being added.' %
(proposed_value))
else:
try:
Reported by Pylint.
Line: 225
Column: 9
try:
proposed_value.encode('utf8')
except UnicodeEncodeError:
raise ValueError('%.1024r isn\'t a valid unicode string and '
'can\'t be encoded in UTF-8.'%
(proposed_value))
return proposed_value
Reported by Pylint.
Line: 49
Column: 1
__author__ = 'robinson@google.com (Will Robinson)'
try:
import ctypes
except Exception: # pylint: disable=broad-except
ctypes = None
import struct
import numbers
import six
Reported by Pylint.
Line: 51
Column: 3
try:
import ctypes
except Exception: # pylint: disable=broad-except
ctypes = None
import struct
import numbers
import six
if six.PY3:
Reported by Pylint.
Line: 51
Column: 1
try:
import ctypes
except Exception: # pylint: disable=broad-except
ctypes = None
import struct
import numbers
import six
if six.PY3:
Reported by Pylint.
Line: 52
Column: 1
import ctypes
except Exception: # pylint: disable=broad-except
ctypes = None
import struct
import numbers
import six
if six.PY3:
long = int
Reported by Pylint.
python/google/protobuf/internal/message_factory_test.py
159 issues
Line: 42
Column: 1
except ImportError:
import unittest
from google.protobuf import descriptor_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import factory_test1_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
Reported by Pylint.
Line: 44
Column: 1
from google.protobuf import descriptor_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import factory_test1_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
from google.protobuf import descriptor_pool
from google.protobuf import message_factory
Reported by Pylint.
Line: 45
Column: 1
from google.protobuf import descriptor_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import factory_test1_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
from google.protobuf import descriptor_pool
from google.protobuf import message_factory
Reported by Pylint.
Line: 154
Column: 14
for ext in factory_msg1.DESCRIPTOR.file.pool.FindAllExtensions(
factory_msg1.DESCRIPTOR))))
msg1 = messages['google.protobuf.python.internal.Factory1Message']()
ext1 = msg1.Extensions._FindExtensionByName(
'google.protobuf.python.internal.Factory2Message.one_more_field')
ext2 = msg1.Extensions._FindExtensionByName(
'google.protobuf.python.internal.another_field')
self.assertEqual(0, len(msg1.Extensions))
msg1.Extensions[ext1] = 'test1'
Reported by Pylint.
Line: 156
Column: 14
msg1 = messages['google.protobuf.python.internal.Factory1Message']()
ext1 = msg1.Extensions._FindExtensionByName(
'google.protobuf.python.internal.Factory2Message.one_more_field')
ext2 = msg1.Extensions._FindExtensionByName(
'google.protobuf.python.internal.another_field')
self.assertEqual(0, len(msg1.Extensions))
msg1.Extensions[ext1] = 'test1'
msg1.Extensions[ext2] = 'test2'
self.assertEqual('test1', msg1.Extensions[ext1])
Reported by Pylint.
Line: 164
Column: 24
self.assertEqual('test1', msg1.Extensions[ext1])
self.assertEqual('test2', msg1.Extensions[ext2])
self.assertEqual(None,
msg1.Extensions._FindExtensionByNumber(12321))
self.assertEqual(2, len(msg1.Extensions))
if api_implementation.Type() == 'cpp':
self.assertRaises(TypeError,
msg1.Extensions._FindExtensionByName, 0)
self.assertRaises(TypeError,
Reported by Pylint.
Line: 168
Column: 27
self.assertEqual(2, len(msg1.Extensions))
if api_implementation.Type() == 'cpp':
self.assertRaises(TypeError,
msg1.Extensions._FindExtensionByName, 0)
self.assertRaises(TypeError,
msg1.Extensions._FindExtensionByNumber, '')
else:
self.assertEqual(None,
msg1.Extensions._FindExtensionByName(0))
Reported by Pylint.
Line: 170
Column: 27
self.assertRaises(TypeError,
msg1.Extensions._FindExtensionByName, 0)
self.assertRaises(TypeError,
msg1.Extensions._FindExtensionByNumber, '')
else:
self.assertEqual(None,
msg1.Extensions._FindExtensionByName(0))
self.assertEqual(None,
msg1.Extensions._FindExtensionByNumber(''))
Reported by Pylint.
Line: 173
Column: 26
msg1.Extensions._FindExtensionByNumber, '')
else:
self.assertEqual(None,
msg1.Extensions._FindExtensionByName(0))
self.assertEqual(None,
msg1.Extensions._FindExtensionByNumber(''))
def testDuplicateExtensionNumber(self):
pool = descriptor_pool.DescriptorPool()
Reported by Pylint.
Line: 175
Column: 26
self.assertEqual(None,
msg1.Extensions._FindExtensionByName(0))
self.assertEqual(None,
msg1.Extensions._FindExtensionByNumber(''))
def testDuplicateExtensionNumber(self):
pool = descriptor_pool.DescriptorPool()
factory = message_factory.MessageFactory(pool=pool)
Reported by Pylint.
java/core/src/test/java/com/google/protobuf/WireFormatTest.java
157 issues
Line: 57
/** Tests related to parsing and serialization. */
@RunWith(JUnit4.class)
public class WireFormatTest {
private static final int TYPE_ID_1 =
TestMessageSetExtension1.getDescriptor().getExtensions().get(0).getNumber();
private static final int TYPE_ID_2 =
TestMessageSetExtension2.getDescriptor().getExtensions().get(0).getNumber();
Reported by PMD.
Line: 69
public void testSerialization() throws Exception {
TestAllTypes message = TestUtil.getAllSet();
ByteString rawBytes = message.toByteString();
assertThat(rawBytes.size()).isEqualTo(message.getSerializedSize());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
Reported by PMD.
Line: 70
TestAllTypes message = TestUtil.getAllSet();
ByteString rawBytes = message.toByteString();
assertThat(rawBytes.size()).isEqualTo(message.getSerializedSize());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 70
TestAllTypes message = TestUtil.getAllSet();
ByteString rawBytes = message.toByteString();
assertThat(rawBytes.size()).isEqualTo(message.getSerializedSize());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 70
TestAllTypes message = TestUtil.getAllSet();
ByteString rawBytes = message.toByteString();
assertThat(rawBytes.size()).isEqualTo(message.getSerializedSize());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 81
public void testSerializationPacked() throws Exception {
TestPackedTypes message = TestUtil.getPackedSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
TestUtil.assertPackedFieldsSet(message2);
Reported by PMD.
Line: 82
TestPackedTypes message = TestUtil.getPackedSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
TestUtil.assertPackedFieldsSet(message2);
}
Reported by PMD.
Line: 82
TestPackedTypes message = TestUtil.getPackedSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
TestUtil.assertPackedFieldsSet(message2);
}
Reported by PMD.
Line: 82
TestPackedTypes message = TestUtil.getPackedSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
TestUtil.assertPackedFieldsSet(message2);
}
Reported by PMD.
Line: 96
// it should work.
TestAllExtensions message = TestUtil.getAllExtensionsSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
Reported by PMD.
benchmarks/python/py_benchmark.py
151 issues
Line: 30
Column: 3
# for the descriptor can be found in the pool
if args.cpp_generated != "no":
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )
import libbenchmark_messages
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )
# END CPP GENERATED MESSAGE
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
Reported by Pylint.
Line: 35
Column: 1
# END CPP GENERATED MESSAGE
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
Reported by Pylint.
Line: 36
Column: 1
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
Reported by Pylint.
Line: 37
Column: 1
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
Reported by Pylint.
Line: 38
Column: 1
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
def run_one_test(filename):
Reported by Pylint.
Line: 39
Column: 1
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
def run_one_test(filename):
data = open(filename, "rb").read()
Reported by Pylint.
Line: 40
Column: 1
import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks_pb2 as benchmarks_pb2
def run_one_test(filename):
data = open(filename, "rb").read()
benchmark_dataset = benchmarks_pb2.BenchmarkDataset()
Reported by Pylint.
Line: 7
Column: 1
import timeit
import math
import argparse
import fnmatch
import json
parser = argparse.ArgumentParser(description="Python protobuf benchmark")
parser.add_argument("data_files", metavar="dataFile", nargs="+",
help="testing data files.")
Reported by Pylint.
Line: 30
Column: 3
# for the descriptor can be found in the pool
if args.cpp_generated != "no":
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )
import libbenchmark_messages
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )
# END CPP GENERATED MESSAGE
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
Reported by Pylint.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
if args.cpp_generated != "no":
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )
import libbenchmark_messages
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )
# END CPP GENERATED MESSAGE
import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
Reported by Bandit.
benchmarks/util/result_parser.py
151 issues
Line: 11
Column: 1
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
# END OPENSOURCE
import tmp.benchmarks_pb2 as benchmarks_pb2
__file_size_map = {}
def __get_data_size(filename):
if filename[0] != '/':
Reported by Pylint.
Line: 65
Column: 5
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename, "rb") as f:
results = json.loads(f.read())
for benchmark in results["benchmarks"]:
data_filename = "".join(
re.split("(_parse_|_serialize)", benchmark["name"])[0])
behavior = benchmark["name"][len(data_filename) + 1:]
if data_filename[:2] == "BM":
Reported by Pylint.
Line: 100
Column: 5
if filename[0] != "/":
filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename
with open(filename, "rb") as f:
results = json.loads(f.read())
for benchmark in results["benchmarks"]:
__results.append({
"language": "cpp",
"dataFilename": "",
"behavior": "synthetic",
Reported by Pylint.
Line: 131
Column: 9
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename, "rb") as f:
results_list = json.loads(f.read())
for results in results_list:
for result in results:
_, avg_size = __get_data_size(result["filename"])
for behavior in result["benchmarks"]:
__results.append({
"language": "python",
Reported by Pylint.
Line: 133
Column: 12
results_list = json.loads(f.read())
for results in results_list:
for result in results:
_, avg_size = __get_data_size(result["filename"])
for behavior in result["benchmarks"]:
__results.append({
"language": "python",
"dataFilename": __extract_file_name(result["filename"]),
"behavior": behavior,
Reported by Pylint.
Line: 180
Column: 5
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename, "rb") as f:
results = json.loads(f.read())
for result in results:
total_weight = 0
total_value = 0
for measurement in result["measurements"]:
total_weight += measurement["weight"]
Reported by Pylint.
Line: 256
Column: 5
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename, "rb") as f:
results = json.loads(f.read())
for result in results:
_, avg_size = __get_data_size(result["filename"])
for behavior in result["benchmarks"]:
__results.append({
"language": language,
Reported by Pylint.
Line: 258
Column: 10
with open(filename, "rb") as f:
results = json.loads(f.read())
for result in results:
_, avg_size = __get_data_size(result["filename"])
for behavior in result["benchmarks"]:
__results.append({
"language": language,
"dataFilename": __extract_file_name(result["filename"]),
"behavior": behavior,
Reported by Pylint.
Line: 283
Column: 3
node_file="",
php_c_file="",
php_file=""):
results = {}
if cpp_file != "":
__parse_cpp_result(cpp_file)
if java_file != "":
__parse_java_result(java_file)
if python_file != "":
Reported by Pylint.
Line: 283
Column: 3
node_file="",
php_c_file="",
php_file=""):
results = {}
if cpp_file != "":
__parse_cpp_result(cpp_file)
if java_file != "":
__parse_java_result(java_file)
if python_file != "":
Reported by Pylint.
python/google/protobuf/message.py
142 issues
Line: 411
Column: 1
def _InternalConstructMessage(full_name):
"""Constructs a nested message."""
from google.protobuf import symbol_database # pylint:disable=g-import-not-at-top
return symbol_database.Default().GetSymbol(full_name)()
Reported by Pylint.
Line: 31
Column: 3
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# TODO(robinson): We should just make these methods all "pure-virtual" and move
# all implementation out, into reflection.py for now.
"""Contains an abstract base class for protocol messages."""
Reported by Pylint.
Line: 41
Column: 3
class Error(Exception):
"""Base error type for this module."""
pass
class DecodeError(Error):
"""Exception raised when deserializing messages."""
pass
Reported by Pylint.
Line: 46
Column: 3
class DecodeError(Error):
"""Exception raised when deserializing messages."""
pass
class EncodeError(Error):
"""Exception raised when serializing messages."""
pass
Reported by Pylint.
Line: 51
Column: 3
class EncodeError(Error):
"""Exception raised when serializing messages."""
pass
class Message(object):
"""Abstract base class for protocol messages.
Reported by Pylint.
Line: 63
Column: 3
shown below.
"""
# TODO(robinson): Link to an HTML document here.
# TODO(robinson): Document that instances of this class will also
# have an Extensions attribute with __getitem__ and __setitem__.
# Again, not sure how to best convey this.
Reported by Pylint.
Line: 65
Column: 3
# TODO(robinson): Link to an HTML document here.
# TODO(robinson): Document that instances of this class will also
# have an Extensions attribute with __getitem__ and __setitem__.
# Again, not sure how to best convey this.
# TODO(robinson): Document that the class must also have a static
# RegisterExtension(extension_field) method.
Reported by Pylint.
Line: 69
Column: 3
# have an Extensions attribute with __getitem__ and __setitem__.
# Again, not sure how to best convey this.
# TODO(robinson): Document that the class must also have a static
# RegisterExtension(extension_field) method.
# Not sure how to best express at this point.
# TODO(robinson): Document these fields and methods.
Reported by Pylint.
Line: 73
Column: 3
# RegisterExtension(extension_field) method.
# Not sure how to best express at this point.
# TODO(robinson): Document these fields and methods.
__slots__ = []
#: The :class:`google.protobuf.descriptor.Descriptor` for this message type.
DESCRIPTOR = None
Reported by Pylint.
Line: 154
Column: 3
"""
raise NotImplementedError
# TODO(robinson): MergeFromString() should probably return None and be
# implemented in terms of a helper that returns the # of bytes read. Our
# deserialization routines would use the helper when recursively
# deserializing, but the end user would almost always just want the no-return
# MergeFromString().
Reported by Pylint.
java/core/src/main/java/com/google/protobuf/BinaryWriter.java
138 issues
Line: 953
private void nextBuffer(AllocatedBuffer allocatedBuffer) {
if (!allocatedBuffer.hasArray()) {
throw new RuntimeException("Allocator returned non-heap buffer");
}
finishCurrentBuffer();
buffers.addFirst(allocatedBuffer);
Reported by PMD.
Line: 1055
value.writeToReverse(this);
} catch (IOException e) {
// Should never happen since the writer does not throw.
throw new RuntimeException(e);
}
requireSpace(MAX_VARINT32_SIZE * 2);
writeVarint32(value.size());
writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED);
Reported by PMD.
Line: 1491
private void nextBuffer(AllocatedBuffer allocatedBuffer) {
if (!allocatedBuffer.hasArray()) {
throw new RuntimeException("Allocator returned non-heap buffer");
}
finishCurrentBuffer();
buffers.addFirst(allocatedBuffer);
Reported by PMD.
Line: 1592
value.writeToReverse(this);
} catch (IOException e) {
// Should never happen since the writer does not throw.
throw new RuntimeException(e);
}
requireSpace(MAX_VARINT32_SIZE * 2);
writeVarint32(value.size());
writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED);
Reported by PMD.
Line: 2006
private void nextBuffer(AllocatedBuffer allocatedBuffer) {
if (!allocatedBuffer.hasNioBuffer()) {
throw new RuntimeException("Allocated buffer does not have NIO buffer");
}
ByteBuffer nioBuffer = allocatedBuffer.nioBuffer();
if (!nioBuffer.isDirect()) {
throw new RuntimeException("Allocator returned non-direct buffer");
}
Reported by PMD.
Line: 2010
}
ByteBuffer nioBuffer = allocatedBuffer.nioBuffer();
if (!nioBuffer.isDirect()) {
throw new RuntimeException("Allocator returned non-direct buffer");
}
finishCurrentBuffer();
buffers.addFirst(allocatedBuffer);
Reported by PMD.
Line: 2123
value.writeToReverse(this);
} catch (IOException e) {
// Should never happen since the writer does not throw.
throw new RuntimeException(e);
}
requireSpace(MAX_VARINT32_SIZE * 2);
writeVarint32(value.size());
writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED);
Reported by PMD.
Line: 2560
private void nextBuffer(AllocatedBuffer allocatedBuffer) {
if (!allocatedBuffer.hasNioBuffer()) {
throw new RuntimeException("Allocated buffer does not have NIO buffer");
}
ByteBuffer nioBuffer = allocatedBuffer.nioBuffer();
if (!nioBuffer.isDirect()) {
throw new RuntimeException("Allocator returned non-direct buffer");
}
Reported by PMD.
Line: 2564
}
ByteBuffer nioBuffer = allocatedBuffer.nioBuffer();
if (!nioBuffer.isDirect()) {
throw new RuntimeException("Allocator returned non-direct buffer");
}
finishCurrentBuffer();
buffers.addFirst(allocatedBuffer);
Reported by PMD.
Line: 2680
value.writeToReverse(this);
} catch (IOException e) {
// Should never happen since the writer does not throw.
throw new RuntimeException(e);
}
requireSpace(MAX_VARINT32_SIZE * 2);
writeVarint32(value.size());
writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED);
Reported by PMD.