Skip to content

Commit

Permalink
Use black as a linter
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianCzoch committed Nov 1, 2022
1 parent 992db6e commit ca380ad
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 72 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [2.7, 3.5, 3.6, 3.7]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v1
Expand All @@ -20,13 +20,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Lint with flake8
- name: Lint with black
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install black
black . --check
- name: Test with pytest
run: |
pip install pytest
Expand Down
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion influx_line_protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .metric import Metric
from .metric_collection import MetricCollection

__all__ = ['Metric', 'MetricCollection']
__all__ = ["Metric", "MetricCollection"]
17 changes: 8 additions & 9 deletions influx_line_protocol/metric.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Metric(object):

def __init__(self, measurement):
self.measurement = measurement
self.values = {}
Expand All @@ -17,8 +16,8 @@ def add_value(self, name, value):

def __str__(self):
# Escape measurement manually
escaped_measurement = self.measurement.replace(',', '\\,')
escaped_measurement = escaped_measurement.replace(' ', '\\ ')
escaped_measurement = self.measurement.replace(",", "\\,")
escaped_measurement = escaped_measurement.replace(" ", "\\ ")
protocol = escaped_measurement

# Create tag strings
Expand Down Expand Up @@ -51,16 +50,16 @@ def __str__(self):
def __escape(self, value):
# Escape backslashes first since the other characters are escaped with
# backslashes
new_value = value.replace('\\', '\\\\')
new_value = value.replace("\\", "\\\\")

new_value = new_value.replace(' ', '\\ ')
new_value = new_value.replace('=', '\\=')
new_value = new_value.replace(',', '\\,')
new_value = new_value.replace(" ", "\\ ")
new_value = new_value.replace("=", "\\=")
new_value = new_value.replace(",", "\\,")

return new_value

def __escape_value(self, value):
new_value = value.replace('\\', '\\\\')
new_value = value.replace("\\", "\\\\")
new_value = new_value.replace('"', '\\"')

return new_value
Expand All @@ -75,4 +74,4 @@ def __parse_value(self, value):
if type(value) is bool:
return value and "t" or "f"

return "\"%s\"" % self.__escape_value(value)
return '"%s"' % self.__escape_value(value)
1 change: 0 additions & 1 deletion influx_line_protocol/metric_collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class MetricCollection(object):

def __init__(self):
self.metrics = []

Expand Down
34 changes: 16 additions & 18 deletions influx_line_protocol/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class TestMetric(unittest.TestCase):

def test_metric_without_tags_values_and_timestamp(self):
metric = Metric("test")

Expand All @@ -19,13 +18,13 @@ def test_metric_escape_measurement_spaces(self):
metric = Metric("test test")
metric.add_value("a", "b")

self.assertEqual("test\\ test a=\"b\"", str(metric))
self.assertEqual('test\\ test a="b"', str(metric))

def test_metric_escape_measurement_commas(self):
metric = Metric("test,test")
metric.add_value("a", "b")

self.assertEqual("test\\,test a=\"b\"", str(metric))
self.assertEqual('test\\,test a="b"', str(metric))

def test_metric_with_tag_string_space_without_values_and_timestamp(self):
metric = Metric("test")
Expand All @@ -38,55 +37,54 @@ def test_metric_escape_tag_and_field_commas(self):
metric.add_tag("a,b", "c,d")
metric.add_value("x,y", "z")

self.assertEqual("test,a\\,b=c\\,d x\\,y=\"z\"", str(metric))
self.assertEqual('test,a\\,b=c\\,d x\\,y="z"', str(metric))

def test_metric_escape_tag_and_field_equals(self):
metric = Metric("test")
metric.add_tag("a=b", "c=d")
metric.add_value("x=y", "z")

self.assertEqual("test,a\\=b=c\\=d x\\=y=\"z\"", str(metric))
self.assertEqual('test,a\\=b=c\\=d x\\=y="z"', str(metric))

def test_metric_escape_field_double_quotes(self):
metric = Metric("test")
metric.add_tag("a\"b", "c\"d")
metric.add_value("x\"y", "z\"")
metric.add_tag('a"b', 'c"d')
metric.add_value('x"y', 'z"')

self.assertEqual("test,a\"b=c\"d x\"y=\"z\\\"\"", str(metric))
self.assertEqual('test,a"b=c"d x"y="z\\""', str(metric))

def test_metric_escape_tag_and_field_backslash(self):
metric = Metric("test")
metric.add_tag("a\\b", "c\\d")
metric.add_value("x\\y", "z\\a")

self.assertEqual("test,a\\\\b=c\\\\d x\\\\y=\"z\\\\a\"", str(metric))
self.assertEqual('test,a\\\\b=c\\\\d x\\\\y="z\\\\a"', str(metric))

def test_metric_escape_field_double_quotes_and_backslash(self):
metric = Metric("test")
metric.add_value("x", "z\\\"")
metric.add_value("x", 'z\\"')

self.assertEqual("test x=\"z\\\\\\\"\"", str(metric))
self.assertEqual('test x="z\\\\\\""', str(metric))

def test_metric_escape_field_double_quotes_and_space(self):
metric = Metric("test")
metric.add_value("x", "foo bar")

self.assertEqual("test x=\"foo bar\"", str(metric))
self.assertEqual('test x="foo bar"', str(metric))

def test_metric_escape_field_double_quotes_with_equal_sign_and_comma(self):
metric = Metric("test")
metric.add_value("x", "a=b,c=d,e=f")

self.assertEqual("test x=\"a=b,c=d,e=f\"", str(metric))
self.assertEqual('test x="a=b,c=d,e=f"', str(metric))

def test_metric_with_tag_value_and_timestamp(self):
metric = Metric("test")
metric.add_tag("tag", "string")
metric.add_value("value", "string")
metric.with_timestamp(687744000)

self.assertEqual(
"test,tag=string value=\"string\" 687744000", str(metric))
self.assertEqual('test,tag=string value="string" 687744000', str(metric))

def test_metric_multiple_tags_without_values_and_timestamp(self):
metric = Metric("test")
Expand All @@ -103,7 +101,7 @@ def test_metric_without_tags_and_timestamp(self):
metric = Metric("test")
metric.add_value("foo", "bar")

self.assertEqual("test foo=\"bar\"", str(metric))
self.assertEqual('test foo="bar"', str(metric))

def test_metric_multiple_values_without_tags_and_timestamp(self):
metric = Metric("test")
Expand All @@ -113,7 +111,7 @@ def test_metric_multiple_values_without_tags_and_timestamp(self):
metric.add_value("value4", True)
metric.add_value("value5", False)

self.assertIn("value1=\"string1\"", str(metric))
self.assertIn('value1="string1"', str(metric))
self.assertIn("value2=1", str(metric))
self.assertIn("value3=0.25", str(metric))
self.assertIn("value4=t", str(metric))
Expand All @@ -135,7 +133,7 @@ def test_metric_multiple_values_tags_and_timestamp(self):
self.assertIn("tag1=string1", str(metric))
self.assertIn("tag2=1", str(metric))
self.assertIn("tag3=0.25", str(metric))
self.assertIn("value1=\"string1\"", str(metric))
self.assertIn('value1="string1"', str(metric))
self.assertIn("value2=1", str(metric))
self.assertIn("value3=0.25", str(metric))
self.assertIn("value4=t", str(metric))
Expand Down
4 changes: 2 additions & 2 deletions influx_line_protocol/test_metric_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TestMetricCollection(unittest.TestCase):

def test_empty_collection(self):
collection = MetricCollection()

Expand Down Expand Up @@ -37,4 +36,5 @@ def test_collection_with_multiple_metrics(self):

self.assertEqual(
"test,a=1 b=2i\ntest2,c=3 d=4i\ntest,a=1 b=2i\ntest2,c=3 d=4i",
str(collection))
str(collection),
)
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

31 changes: 14 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@


def read_file(file_name):
with open(file_name, 'r') as f:
with open(file_name, "r") as f:
return f.read()


setuptools.setup(
name='influx-line-protocol',
description='Implementation of influxdata line protocol format in python',
name="influx-line-protocol",
description="Implementation of influxdata line protocol format in python",
long_description=long_description,
long_description_content_type='text/markdown',
version='0.1.4',
url='https://github.com/SebastianCzoch/influx-line-protocol',
author='Sebastian Czoch',
author_email='[email protected]',
license='MIT',
long_description_content_type="text/markdown",
version="0.1.5",
url="https://github.com/SebastianCzoch/influx-line-protocol",
author="Sebastian Czoch",
author_email="[email protected]",
license="MIT",
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Operating System :: OS Independent',
"Development Status :: 4 - Beta",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Operating System :: OS Independent",
],
packages=setuptools.find_packages(),
setup_requires=[
"flake8"
]
)

0 comments on commit ca380ad

Please sign in to comment.