python-diamond / Diamond

Diamond is a python daemon that collects system metrics and publishes them to Graphite (and others). It is capable of collecting cpu, memory, network, i/o, load and disk metrics. Additionally, it features an API for implementing custom collectors for gathering metrics from almost any source.
http://diamond.readthedocs.org/
MIT License
1.74k stars 601 forks source link

dict generator does not work for python 2.6 #629

Closed williamjoy closed 7 years ago

williamjoy commented 7 years ago

duplicated with pull request #626

https://www.python.org/dev/peps/pep-0274/#semantics

The semantics of dict comprehensions can actually be demonstrated in stock Python 2.2, by passing a list comprehension to the built-in dictionary constructor:

>>> dict([(i, chr(65+i)) for i in range(4)])
is semantically equivalent to:

>>> {i : chr(65+i) for i in range(4)}
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 24.811% when pulling bf8c28ab928e3ed8ad1c6575f35748aa2c862578 on williamjoy:patch-2 into a6ba91ce79ef02e86f5b57434c4dd05f93545d22 on python-diamond:master.

shortdudey123 commented 7 years ago

Since the bug was not causing tests to fail, can you add a test to cover the _sum_statistics method? That will keep it from getting broken in the future

williamjoy commented 7 years ago

hi @shortdudey123 , I tried to add a test case which might cover it

test against old mesos.py

$ python2.7 ./test.py -c mesos -v
test_http (testmesos.TestMesosCollector) ... ok
test_https (testmesos.TestMesosCollector) ... ok
test_import (testmesos.TestMesosCollector) ... ok
test_should_compute_cpus_percent (testmesos.TestMesosCollector) ... ok
test_should_compute_cpus_utilisation (testmesos.TestMesosCollector) ... ok
test_should_fail_gracefully (testmesos.TestMesosCollector) ... ok
test_should_work_for_master_with_real_data (testmesos.TestMesosCollector) ... ok
test_should_work_for_slave_with_real_data (testmesos.TestMesosCollector) ... ok
test_sum_statistics (testmesos.TestMesosCollector) ... ok

----------------------------------------------------------------------
Ran 9 tests in 0.014s

OK
$  python2.6 ./test.py -c mesos -v
Failed to import module: testmesos. Traceback (most recent call last):
  File "./test.py", line 246, in getCollectorTests
    ['*'])
  File "/home/william.wei/Diamond/src/collectors/mesos/test/testmesos.py", line 14, in <module>
    from mesos import MesosCollector
  File "/home/william.wei/Diamond/src/collectors/mesos/mesos.py", line 177
    for key in stats
      ^
SyntaxError: invalid syntax

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
shortdudey123 commented 7 years ago

awesome! thanks for showing the output of the new test with the old code :)

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 24.766% when pulling 68a5cf9abf403eecb5512fce96dcd279ce7e7aab on williamjoy:patch-2 into ce5a2b87bb2a0b21feb814f139054067c16f96d6 on python-diamond:master.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 24.766% when pulling 40b9e2d591d0ad8f3d49cbabe2c5e9410eff3fa0 on williamjoy:patch-2 into ce5a2b87bb2a0b21feb814f139054067c16f96d6 on python-diamond:master.