Skip to content

Commit

Permalink
pylint: remove 'disable-msg' and fix imports
Browse files Browse the repository at this point in the history
* Remove 'disable-msg' comments introduced in commit dfa0a89.
* Add empty "__init__.py" file to tests/ directory.
* Add 'math' and 'array' modules to extension-pkg-whitelist in pylintrc.
* test_utilities.py needs to be a relative import after hepdata_lib.
* With these changes, pylint now gives 10.00/10 on my local setup.
  • Loading branch information
GraemeWatt committed Oct 18, 2023
1 parent f11eb35 commit 0d77f11
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion hepdata_lib/c_file_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""".C file reader"""
import io
from array import array # pylint: disable-msg=E0611
from array import array
from future.utils import raise_from
from ROOT import TGraph, TGraphErrors
import hepdata_lib.root_utils as ru
Expand Down
2 changes: 1 addition & 1 deletion hepdata_lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_number_precision(value):
if value == 0 or isinstance(value, str) or np.isnan(value) or np.isinf(value):
return value

return math.ceil(math.log10(abs(value))) # pylint: disable-msg=I1101
return math.ceil(math.log10(abs(value)))


def relative_round(value, relative_digits):
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=
extension-pkg-whitelist=math,array

# Add files or directories to the blacklist. They should be base names, not
# paths.
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""hepdata_lib tests"""
2 changes: 1 addition & 1 deletion tests/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=
extension-pkg-whitelist=array

# Add files or directories to the blacklist. They should be base names, not
# paths.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cfilereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import TestCase
import os
import numpy as np
from hepdata_lib.c_file_reader import CFileReader # pylint: disable-msg=E0401
from hepdata_lib.c_file_reader import CFileReader

class TestCFileReader(TestCase):
"""Test the CFileReader class."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# !/usr/bin/env python
"""Test execute_command() function."""
from unittest import TestCase
from hepdata_lib.helpers import execute_command # pylint: disable-msg=E0401
from hepdata_lib.helpers import execute_command

class TestExecuteCommand(TestCase):
"""Test execute_command() function."""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import numpy as np

from hepdata_lib.helpers import relative_round # pylint: disable-msg=E0401
from hepdata_lib.helpers import get_number_precision # pylint: disable-msg=E0401
from hepdata_lib.helpers import get_value_precision_wrt_reference # pylint: disable-msg=E0401
from hepdata_lib.helpers import round_value_and_uncertainty # pylint: disable-msg=E0401
from hepdata_lib.helpers import relative_round
from hepdata_lib.helpers import get_number_precision
from hepdata_lib.helpers import get_value_precision_wrt_reference
from hepdata_lib.helpers import round_value_and_uncertainty


class TestHelpers(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import shutil
import os
import yaml
from test_utilities import tmp_directory_name
from hepdata_lib import Submission, Table, Variable # pylint: disable-msg=E0401
from hepdata_lib import Submission, Table, Variable
from .test_utilities import tmp_directory_name

class TestOutput(TestCase):
"""Test output"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_rootfilereader.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
"""Test RootFileReader."""
from unittest import TestCase
from array import array # pylint: disable-msg=E0611
from array import array
import os
import ctypes
import numpy as np
import ROOT
from test_utilities import float_compare, tuple_compare, histogram_compare_1d, make_tmp_root_file
from hepdata_lib.root_utils import RootFileReader # pylint: disable-msg=E0401
from hepdata_lib.root_utils import RootFileReader
from .test_utilities import float_compare, tuple_compare, histogram_compare_1d, make_tmp_root_file


class TestRootFileReader(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import string
from unittest import TestCase
import tarfile
from test_utilities import tmp_directory_name
from hepdata_lib import Submission, Table, Variable, Uncertainty # pylint: disable-msg=E0401
from hepdata_lib import Submission, Table, Variable, Uncertainty
from .test_utilities import tmp_directory_name

class TestSubmission(TestCase):
"""Test the Submission class."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import shutil
from unittest import TestCase

from test_utilities import tmp_directory_name
from hepdata_lib import Table, Variable, Uncertainty # pylint: disable-msg=E0401
from hepdata_lib import Table, Variable, Uncertainty
from .test_utilities import tmp_directory_name

class TestTable(TestCase):
"""Test the Table class."""
Expand Down
14 changes: 7 additions & 7 deletions tests/test_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""Test Uncertainty."""
import random
from unittest import TestCase
import test_utilities
from hepdata_lib import Variable, Uncertainty # pylint: disable-msg=E0401
from hepdata_lib import Variable, Uncertainty
from .test_utilities import float_compare, tuple_compare


class TestUncertainty(TestCase):
Expand Down Expand Up @@ -32,16 +32,16 @@ def test_scale_values(self):
testvar.scale_values(factor)
scaled_values = [factor * x for x in values]
scaled_uncertainty = [factor * x for x in uncertainty]
self.assertTrue(all(test_utilities.float_compare(x, y)
self.assertTrue(all(float_compare(x, y)
for x, y in zip(testvar.values, scaled_values)))
self.assertTrue(all(test_utilities.float_compare(x, y)
self.assertTrue(all(float_compare(x, y)
for x, y in zip(testunc.values, scaled_uncertainty)))

# Check that inverse also works
testvar.scale_values(1. / factor)
self.assertTrue(all(test_utilities.float_compare(x, y)
self.assertTrue(all(float_compare(x, y)
for x, y in zip(testvar.values, values)))
self.assertTrue(all(test_utilities.float_compare(x, y)
self.assertTrue(all(float_compare(x, y)
for x, y in zip(testunc.values, uncertainty)))

def test_set_values_from_intervals(self):
Expand All @@ -68,7 +68,7 @@ def test_set_values_from_intervals(self):
testunc.set_values_from_intervals(intervals, nominal=values)

# Check that both agree
self.assertTrue(all((test_utilities.tuple_compare(tup1, tup2)
self.assertTrue(all((tuple_compare(tup1, tup2)
for tup1, tup2 in zip(testunc.values, refunc.values))))

def test_mixed_uncertainties(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""Test Variable."""
import random
from unittest import TestCase
import test_utilities
from hepdata_lib import Variable, Uncertainty # pylint: disable-msg=E0401
from hepdata_lib import Variable, Uncertainty
from .test_utilities import tuple_compare


class TestVariable(TestCase):
Expand All @@ -23,12 +23,12 @@ def test_scale_values(self):
# Check that scaling works
testvar.scale_values(factor)
scaled_values = [(factor * x[0], factor * x[1]) for x in values]
assert(all(test_utilities.tuple_compare(x, y)
assert(all(tuple_compare(x, y)
for x, y in zip(testvar.values, scaled_values)))

# Check that inverse also works
testvar.scale_values(1. / factor)
self.assertTrue(all(test_utilities.tuple_compare(x, y)
self.assertTrue(all(tuple_compare(x, y)
for x, y in zip(testvar.values, values)))

def test_add_uncertainty(self):
Expand Down

0 comments on commit 0d77f11

Please sign in to comment.