Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 0ce73e3

Browse files
pravaragyurishkuro
authored andcommitted
Enable linting of tests (#227)
Changes for including flake8 in tests folder Signed-off-by: pravar <[email protected]>
1 parent 3f091d4 commit 0ce73e3

20 files changed

+353
-296
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ clean:
6666

6767
.PHONY: lint
6868
lint:
69-
$(flake8) $(projects)
69+
$(flake8) $(projects) tests
7070
./scripts/check-license.sh
7171

7272
.PHONY: shell

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[flake8]
22
ignore = D100,D101,D102,D103,D104,D105,D203,D204,D205,D400
33
max-line-length = 100
4-
exclude =
5-
tests/*,
4+
exclude =
65
jaeger_client/thrift_gen/*,
76
crossdock/thrift_gen/*
87

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ def tracer():
2525
return Tracer(
2626
service_name='test_service_1', reporter=reporter, sampler=sampler)
2727

28+
2829
AsyncHTTPClient.configure('tornado.curl_httpclient.CurlAsyncHTTPClient')
2930
print('Configured AsyncHTTPClient to use tornado.curl_httpclient.CurlAsyncHTTPClient')

tests/test_TUDPTransport.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414

1515
from __future__ import absolute_import
16-
17-
import mock
1816
import unittest
1917

2018
from jaeger_client.TUDPTransport import TUDPTransport
@@ -26,7 +24,7 @@ def setUp(self):
2624

2725
def test_constructor_blocking(self):
2826
t = TUDPTransport('127.0.0.1', 12345, blocking=True)
29-
assert t.transport_sock.gettimeout() == None
27+
assert t.transport_sock.gettimeout() is None
3028

3129
def test_constructor_nonblocking(self):
3230
t = TUDPTransport('127.0.0.1', 12345, blocking=False)
@@ -36,11 +34,11 @@ def test_write(self):
3634
self.t.write(b'hello')
3735

3836
def test_isopen_when_open(self):
39-
assert self.t.isOpen() == True
37+
assert self.t.isOpen() is True
4038

4139
def test_isopen_when_closed(self):
4240
self.t.close()
43-
assert self.t.isOpen() == False
41+
assert self.t.isOpen() is False
4442

4543
def test_close(self):
4644
self.t.close()

tests/test_codecs.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
class TestCodecs(unittest.TestCase):
3939

40-
4140
def test_abstract_codec(self):
4241
codec = Codec()
4342
with self.assertRaises(NotImplementedError):
@@ -208,7 +207,6 @@ def test_context_from_readable_headers(self):
208207
'hermes': 'LaBarbara Hermes',
209208
}
210209

211-
212210
def test_context_from_large_ids(self):
213211
codec = TextCodec(trace_id_header='Trace_ID',
214212
baggage_header_prefix='Trace-Attr-')
@@ -306,7 +304,8 @@ def test_b3_codec_inject_parent(self):
306304
span = Span(context=ctx, operation_name='x', tracer=None, start_time=1)
307305
carrier = {}
308306
codec.inject(span_context=span, carrier=carrier)
309-
assert carrier == {'X-B3-SpanId': format(127, 'x').zfill(16), 'X-B3-ParentSpanId': format(32, 'x').zfill(16),
307+
assert carrier == {'X-B3-SpanId': format(127, 'x').zfill(16),
308+
'X-B3-ParentSpanId': format(32, 'x').zfill(16),
310309
'X-B3-TraceId': format(256, 'x').zfill(16), 'X-B3-Sampled': '1'}
311310

312311
def test_b3_extract(self):
@@ -500,9 +499,9 @@ def test_baggage_as_unicode_strings_with_httplib(httpserver):
500499
span.set_baggage_item(b[0], b[1])
501500

502501
headers = {}
503-
tracer.inject(
504-
span_context=span.context, format=Format.TEXT_MAP, carrier=headers
505-
)
502+
tracer.inject(span_context=span.context,
503+
format=Format.TEXT_MAP,
504+
carrier=headers)
506505
# make sure httplib doesn't blow up
507506
request = urllib_under_test.Request(httpserver.url, None, headers)
508507
response = urllib_under_test.urlopen(request)

tests/test_config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_const_sampler(self):
6060
def test_probabilistic_sampler(self):
6161
with self.assertRaises(Exception):
6262
cfg = {'sampler': {'type': 'probabilistic', 'param': 'xx'}}
63-
_ = Config(cfg, service_name='x').sampler
63+
Config(cfg, service_name='x').sampler
6464
c = Config({'sampler': {'type': 'probabilistic', 'param': 0.5}},
6565
service_name='x')
6666
assert type(c.sampler) is ProbabilisticSampler
@@ -69,7 +69,7 @@ def test_probabilistic_sampler(self):
6969
def test_rate_limiting_sampler(self):
7070
with self.assertRaises(Exception):
7171
cfg = {'sampler': {'type': 'rate_limiting', 'param': 'xx'}}
72-
_ = Config(cfg, service_name='x').sampler
72+
Config(cfg, service_name='x').sampler
7373
c = Config({'sampler': {'type': 'rate_limiting', 'param': 1234}},
7474
service_name='x')
7575
assert type(c.sampler) is RateLimitingSampler
@@ -133,18 +133,18 @@ def test_throttler(self):
133133

134134
def test_for_unexpected_config_entries(self):
135135
with self.assertRaises(Exception):
136-
_ = Config({"unexpected":"value"}, validate=True)
136+
Config({'unexpected': 'value'}, validate=True)
137137

138138
def test_reporter_queue_size_valid(self):
139-
config = Config({"reporter_queue_size": 100}, service_name='x', validate=True)
139+
config = Config({'reporter_queue_size': 100}, service_name='x', validate=True)
140140
assert config.reporter_queue_size == 100
141141

142142
def test_missing_service_name(self):
143143
with self.assertRaises(ValueError):
144-
_ = Config({})
144+
Config({})
145145

146146
def test_disable_metrics(self):
147-
config = Config({ 'metrics': False }, service_name='x')
147+
config = Config({'metrics': False}, service_name='x')
148148
assert isinstance(config._metrics_factory, MetricsFactory)
149149

150150
def test_initialize_tracer(self):

tests/test_crossdock.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
import pytest
2222
import opentracing
2323
from mock import MagicMock
24-
if six.PY2:
25-
from crossdock.server import server
2624
from tornado.httpclient import HTTPRequest
2725
from jaeger_client import Tracer, ConstSampler
2826
from jaeger_client.reporter import InMemoryReporter
2927
from crossdock.server.endtoend import EndToEndHandler, _determine_host_port, _parse_host_port
3028

31-
tchannel_port = "9999"
29+
if six.PY2:
30+
from crossdock.server import server
31+
32+
tchannel_port = '9999'
3233

3334

3435
@pytest.fixture
@@ -54,16 +55,16 @@ def tracer():
5455

5556

5657
PERMUTATIONS = []
57-
for s2 in ["HTTP", "TCHANNEL"]:
58-
for s3 in ["HTTP", "TCHANNEL"]:
58+
for s2 in ['HTTP', 'TCHANNEL']:
59+
for s3 in ['HTTP', 'TCHANNEL']:
5960
for sampled in [True, False]:
6061
PERMUTATIONS.append((s2, s3, sampled))
6162

6263

6364
# noinspection PyShadowingNames
6465
@pytest.mark.parametrize('s2_transport,s3_transport,sampled', PERMUTATIONS)
6566
@pytest.mark.gen_test
66-
@pytest.mark.skipif(six.PY3, reason="crossdock tests need tchannel that only works with Python 2.7")
67+
@pytest.mark.skipif(six.PY3, reason='crossdock tests need tchannel that only works with Python 2.7')
6768
def test_trace_propagation(
6869
s2_transport, s3_transport, sampled, tracer,
6970
base_url, http_port, http_client):
@@ -77,32 +78,32 @@ def test_trace_propagation(
7778
)
7879

7980
level3 = dict()
80-
level3["serviceName"] = "python"
81-
level3["serverRole"] = "s3"
82-
level3["transport"] = s3_transport
83-
level3["host"] = "localhost"
84-
level3["port"] = str(http_port) if s3_transport == "HTTP" else tchannel_port
81+
level3['serviceName'] = 'python'
82+
level3['serverRole'] = 's3'
83+
level3['transport'] = s3_transport
84+
level3['host'] = 'localhost'
85+
level3['port'] = str(http_port) if s3_transport == 'HTTP' else tchannel_port
8586

8687
level2 = dict()
87-
level2["serviceName"] = "python"
88-
level2["serverRole"] = "s2"
89-
level2["transport"] = s2_transport
90-
level2["host"] = "localhost"
91-
level2["port"] = str(http_port) if s2_transport == "HTTP" else tchannel_port
92-
level2["downstream"] = level3
88+
level2['serviceName'] = 'python'
89+
level2['serverRole'] = 's2'
90+
level2['transport'] = s2_transport
91+
level2['host'] = 'localhost'
92+
level2['port'] = str(http_port) if s2_transport == 'HTTP' else tchannel_port
93+
level2['downstream'] = level3
9394

9495
level1 = dict()
95-
level1["baggage"] = "Zoidberg"
96-
level1["serverRole"] = "s1"
97-
level1["sampled"] = sampled
98-
level1["downstream"] = level2
96+
level1['baggage'] = 'Zoidberg'
97+
level1['serverRole'] = 's1'
98+
level1['sampled'] = sampled
99+
level1['downstream'] = level2
99100
body = json.dumps(level1)
100101

101102
with mock.patch('opentracing.tracer', tracer):
102-
assert opentracing.tracer == tracer # sanity check that patch worked
103+
assert opentracing.tracer == tracer # sanity check that patch worked
103104

104-
req = HTTPRequest(url="%s/start_trace" % base_url, method="POST",
105-
headers={"Content-Type": "application/json"},
105+
req = HTTPRequest(url='%s/start_trace' % base_url, method='POST',
106+
headers={'Content-Type': 'application/json'},
106107
body=body,
107108
request_timeout=2)
108109

@@ -111,40 +112,41 @@ def test_trace_propagation(
111112
tr = server.serializer.traceresponse_from_json(response.body)
112113
assert tr is not None
113114
assert tr.span is not None
114-
assert tr.span.baggage == level1.get("baggage")
115+
assert tr.span.baggage == level1.get('baggage')
115116
assert tr.span.sampled == sampled
116117
assert tr.span.traceId is not None
117118
assert tr.downstream is not None
118-
assert tr.downstream.span.baggage == level1.get("baggage")
119+
assert tr.downstream.span.baggage == level1.get('baggage')
119120
assert tr.downstream.span.sampled == sampled
120121
assert tr.downstream.span.traceId == tr.span.traceId
121122
assert tr.downstream.downstream is not None
122-
assert tr.downstream.downstream.span.baggage == level1.get("baggage")
123+
assert tr.downstream.downstream.span.baggage == level1.get('baggage')
123124
assert tr.downstream.downstream.span.sampled == sampled
124125
assert tr.downstream.downstream.span.traceId == tr.span.traceId
125126

126127

127128
# noinspection PyShadowingNames
128129
@pytest.mark.gen_test
129-
@pytest.mark.skipif(six.PY3, reason="crossdock tests need tchannel that only works with Python 2.7")
130+
@pytest.mark.skipif(six.PY3, reason='crossdock tests need tchannel that only works with Python 2.7')
130131
def test_endtoend_handler(tracer):
131132
payload = dict()
132-
payload["operation"] = "Zoidberg"
133-
payload["count"] = 2
134-
payload["tags"] = {"key":"value"}
133+
payload['operation'] = 'Zoidberg'
134+
payload['count'] = 2
135+
payload['tags'] = {'key': 'value'}
135136
body = json.dumps(payload)
136137

137138
h = EndToEndHandler()
138139
request = MagicMock(body=body)
139140
response_writer = MagicMock()
140141
response_writer.finish.return_value = None
141142

142-
h.tracers = {"remote": tracer}
143+
h.tracers = {'remote': tracer}
143144
h.generate_traces(request, response_writer)
144145

145146
spans = tracer.reporter.get_spans()
146147
assert len(spans) == 2
147148

149+
148150
def test_determine_host_port():
149151
original_value = os.environ.get('AGENT_HOST_PORT', None)
150152
os.environ['AGENT_HOST_PORT'] = 'localhost:1234'
@@ -157,6 +159,7 @@ def test_determine_host_port():
157159
assert host == 'localhost'
158160
assert port == 1234
159161

162+
160163
def test_parse_host_port():
161164
test_cases = [
162165
[('', 'localhost', 5678), ('localhost', 5678)],

tests/test_local_agent_net.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@
4141

4242
test_client_id = 12345678
4343

44+
4445
class AgentHandler(tornado.web.RequestHandler):
4546
def get(self):
4647
self.write(test_strategy)
4748

49+
4850
class CreditHandler(tornado.web.RequestHandler):
4951
def get(self):
5052
self.write(test_credits)
5153

54+
5255
application = tornado.web.Application([
53-
(r"/sampling", AgentHandler),
54-
(r"/credits", CreditHandler),
56+
(r'/sampling', AgentHandler),
57+
(r'/credits', CreditHandler),
5558
])
5659

60+
5761
@pytest.fixture
5862
def app():
5963
return application
@@ -70,6 +74,7 @@ def test_request_sampling_strategy(http_client, base_url):
7074
response = yield sender.request_sampling_strategy(service_name='svc', timeout=15)
7175
assert response.body == test_strategy.encode('utf-8')
7276

77+
7378
@pytest.mark.gen_test
7479
def test_request_throttling_credits(http_client, base_url):
7580
o = urlparse(base_url)
@@ -80,8 +85,8 @@ def test_request_throttling_credits(http_client, base_url):
8085
throttling_port=o.port,
8186
)
8287
response = yield sender.request_throttling_credits(
83-
service_name='svc',
84-
client_id=test_client_id,
85-
operations=['test-operation'],
86-
timeout=15)
88+
service_name='svc',
89+
client_id=test_client_id,
90+
operations=['test-operation'],
91+
timeout=15)
8792
assert response.body == test_credits.encode('utf-8')

tests/test_metrics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ def test_legacy_metrics_factory():
6868
tm = mock.MagicMock()
6969
gm = mock.MagicMock()
7070
mf = LegacyMetricsFactory(Metrics(count=cm, timing=tm, gauge=gm))
71-
counter = mf.create_counter(name='foo', tags={'k':'v','a':'counter'})
71+
counter = mf.create_counter(name='foo', tags={'k': 'v', 'a': 'counter'})
7272
counter(1)
7373
assert cm.call_args == (('foo.a_counter.k_v', 1),)
7474

75-
gauge = mf.create_gauge(name='bar', tags={'k':'v', 'a':'gauge'})
75+
gauge = mf.create_gauge(name='bar', tags={'k': 'v', 'a': 'gauge'})
7676
gauge(2)
7777
assert gm.call_args == (('bar.a_gauge.k_v', 2),)
7878

79-
timing = mf.create_timer(name='rawr', tags={'k':'v', 'a':'timer'})
79+
timing = mf.create_timer(name='rawr', tags={'k': 'v', 'a': 'timer'})
8080
timing(3)
8181
assert tm.call_args == (('rawr.a_timer.k_v', 0.003),)
8282

@@ -89,11 +89,11 @@ def test_legacy_metrics_factory():
8989

9090
def test_legacy_metrics_factory_noop():
9191
mf = LegacyMetricsFactory(Metrics())
92-
counter = mf.create_counter(name='foo', tags={'a':'counter'})
92+
counter = mf.create_counter(name='foo', tags={'a': 'counter'})
9393
counter(1)
9494

95-
gauge = mf.create_gauge(name='bar', tags={'a':'gauge'})
95+
gauge = mf.create_gauge(name='bar', tags={'a': 'gauge'})
9696
gauge(2)
9797

98-
timing = mf.create_timer(name='rawr', tags={'a':'timer'})
98+
timing = mf.create_timer(name='rawr', tags={'a': 'timer'})
9999
timing(3)

tests/test_noop_tracer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
from __future__ import absolute_import
1617

1718
import opentracing
@@ -32,7 +33,9 @@ def test_new_trace():
3233
assert child.get_baggage_item('Fry') is None
3334
carrier = {}
3435
tracer.inject(
35-
span_context=child.context, format=Format.TEXT_MAP, carrier=carrier)
36+
span_context=child.context,
37+
format=Format.TEXT_MAP,
38+
carrier=carrier)
3639
assert carrier == dict()
3740
child.finish()
3841

0 commit comments

Comments
 (0)