Skip to content

Commit

Permalink
style(many): Enforced black formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeyer committed Dec 26, 2023
1 parent a1ff61e commit 05c10d0
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 106 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ clean-test: ## remove test and coverage artifacts
rm -fr test-resources
rm -fr test-ISIS3DATA

lint: ## check style with flake8
lint/flake8: ## check style with flake8
flake8 kalasiris tests

lint/black: ## check style with black
black --check kalasiris tests

lint: lint/flake8 lint/black
twine check dist/*

test: test-resources ## run tests quickly with the default Python
python -m pytest

Expand Down
10 changes: 3 additions & 7 deletions kalasiris/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def __init__(self, histinfo):
self.histinfo = histinfo

try:
(self.dictionary, self.headers, self.hist_list) = self.parse(
histinfo
)
(self.dictionary, self.headers, self.hist_list) = self.parse(histinfo)
except StopIteration:
try:
(self.dictionary, self.headers, self.hist_list) = self.parse(
Expand Down Expand Up @@ -73,7 +71,7 @@ def __contains__(self, item):
def keys(self):
"""Gets the keys from the initial portion of the hist output file.
These will be items like 'Cube', 'Band', 'Average', etc.
These will be items like 'Cube', 'Band', 'Average', etc.
"""
return self.dictionary.keys()

Expand Down Expand Up @@ -146,9 +144,7 @@ def parse(histinfo: str) -> tuple:
# d[k.strip()] = v.strip()
d.setdefault(k.strip(), v.strip())

reader = csv.reader(
filter(lambda x: "," in x, str(histinfo).splitlines())
)
reader = csv.reader(filter(lambda x: "," in x, str(histinfo).splitlines()))
fieldnames = next(reader)

HistRow = collections.namedtuple("HistRow", fieldnames)
Expand Down
4 changes: 1 addition & 3 deletions kalasiris/PathSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def add(self, elem) -> Path:
if not isinstance(elem, Path):
raise TypeError("only accepts pathlib.Path objects")
if elem in self:
raise ValueError(
f"The {elem} object is already a member of the PathSet."
)
raise ValueError(f"The {elem} object is already a member of the PathSet.")
super().add(elem)
return elem

Expand Down
8 changes: 2 additions & 6 deletions kalasiris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def _get_start_size(d: dict) -> Tuple[int, int]:
return start, size


def get_startsize_from(
label=None, table_name=None, cube_path=None
) -> Tuple[int, int]:
def get_startsize_from(label=None, table_name=None, cube_path=None) -> Tuple[int, int]:
"""Returns a tuple of ints that represent the true start byte and size
based on the provided *label* or combination of *table_name* and
*cube_path*.
Expand Down Expand Up @@ -136,9 +134,7 @@ def get_startsize_from(

# This function is derived from this commit dated Sep 24, 2019:
# https://github.com/USGS-Astrogeology/ale/commit/add5368ba46b2c911de9515afeaccc4d1c981000
def read_table_data(
cube_path: os.PathLike, label=None, table_name=None
) -> bytes:
def read_table_data(cube_path: os.PathLike, label=None, table_name=None) -> bytes:
"""Returns a bytes object with the contents read from the file at
*cube_path* based on the elements provided in the *label* or
*table_name*.
Expand Down
8 changes: 1 addition & 7 deletions kalasiris/cubenormfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ class DictWriter(csv.DictWriter):
"""A DictWriter for ``cubenorm`` files."""

def __init__(
self,
f,
restval="",
extrasaction="raise",
dialect=Dialect,
*args,
**kwds
self, f, restval="", extrasaction="raise", dialect=Dialect, *args, **kwds
):
self.fieldnames = fieldnames
self.restval = restval
Expand Down
4 changes: 2 additions & 2 deletions kalasiris/k_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def hi2isis_k(*args, **kwargs):
if len(args) > 0 and not str(args[0]).endswith("__"):
from_path = Path(args[0])
else:
for (k, v) in kwargs.items():
for k, v in kwargs.items():
if k.startswith("f"):
from_path = Path(v)
break
Expand All @@ -70,7 +70,7 @@ def hist_k(*args, **kwargs) -> str:
create the file, and return its contents as a string
"""
to_pathlike = None
for (k, v) in kwargs.items():
for k, v in kwargs.items():
if "to" == k or "to_" == k:
to_pathlike = v

Expand Down
5 changes: 1 addition & 4 deletions kalasiris/pysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def __init__(self, returncode, cmd, stdout, stderr):
self.stdout = stdout
self.stderr = stderr

msg = (
f"Command {self.cmd} returned non-zero exit "
f"status {self.returncode}."
)
msg = f"Command {self.cmd} returned non-zero exit " f"status {self.returncode}."
super(ProcessError, self).__init__(msg)


Expand Down
4 changes: 1 addition & 3 deletions kalasiris/specialpixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
)

# 1-byte special pixel values from SpecialPixel.h
UnsignedByte = SpecialPixels(
Min=1, Null=0, Lrs=0, Lis=0, His=255, Hrs=255, Max=254
)
UnsignedByte = SpecialPixels(Min=1, Null=0, Lrs=0, Lis=0, His=255, Hrs=255, Max=254)

# 2-byte unsigned special pixel values from SpecialPixel.h
UnsignedWord = SpecialPixels(
Expand Down
16 changes: 6 additions & 10 deletions kalasiris/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class ISISversion(

version_re = re.compile(r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)")
date_re = re.compile(r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})")
date_yearlast_re = re.compile(
r"(?P<month>\d{1,2})-(?P<day>\d{1,2})-(?P<year>\d{4})"
)
date_yearlast_re = re.compile(r"(?P<month>\d{1,2})-(?P<day>\d{1,2})-(?P<year>\d{4})")
level_re = re.compile(r"^alpha|beta|stable")


Expand All @@ -57,20 +55,18 @@ def version_info() -> ISISversion:
def get_from_string(s: str) -> ISISversion:
"""Read text and parse the contents for ISIS version information.
This should parse ISIS version text as far back as ISIS 3.5.2.0,
but possibly earlier. It will return *None* values for releaselevel
and date if it cannot parse them. It will raise a :exc:`ValueError`
if it cannot parse a version number.
This should parse ISIS version text as far back as ISIS 3.5.2.0,
but possibly earlier. It will return *None* values for releaselevel
and date if it cannot parse them. It will raise a :exc:`ValueError`
if it cannot parse a version number.
"""

# Version Matching
match = version_re.search(s)
if match:
v = match.groupdict()
else:
raise ValueError(
f"{s} did not match version regex: " f"{version_re.pattern}"
)
raise ValueError(f"{s} did not match version regex: " f"{version_re.pattern}")

# Date Matching
d = None
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Black formatter sometimes puts space before the colon (E203) and
# puts a line break before binary operators (W503)
ignore = E203, W503
max_line_length = 88
max-complexity = 10
exclude = docs

Expand Down
6 changes: 3 additions & 3 deletions tests/test_Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)

# Hardcoding this, but I sure would like a better solution.
Expand Down Expand Up @@ -192,11 +192,11 @@ def test_repr(self):
def test_iter(self):
rows = 0
for x in self.h:
rows +=1
rows += 1

self.assertEqual(107, rows)

def test_contains(self):
def test_contains_false(self):
self.assertFalse("Foo" in self.h)

def test_keys(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_PathSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import kalasiris as isis
from .utils import (
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)


Expand Down
39 changes: 16 additions & 23 deletions tests/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)

# Hardcoding this, but I sure would like a better solution.
Expand Down Expand Up @@ -106,9 +106,7 @@ def test_get_table(self):
try:
import pvl # noqa F401

table = isis.cube.get_table(
self.cube, "HiRISE Calibration Ancillary"
)
table = isis.cube.get_table(self.cube, "HiRISE Calibration Ancillary")
self.assertEqual(255, table["GapFlag"][0])
self.assertEqual(9, table["LineNumber"][9])
self.assertEqual(1359, table["BufferPixels"][0][0])
Expand All @@ -124,9 +122,7 @@ def test_get_table(self):

def test_overwrite_table_data(self):
data = bytes(10)
self.assertRaises(
ValueError, isis.cube.overwrite_table_data, self.cube, data
)
self.assertRaises(ValueError, isis.cube.overwrite_table_data, self.cube, data)
self.assertRaises(
KeyError,
isis.cube.overwrite_table_data,
Expand Down Expand Up @@ -175,9 +171,7 @@ def test_encode_table(self):

bad_table = dict(table)
bad_table["TooLong"] = ["a", "b", "c", "d", "e"]
self.assertRaises(
IndexError, isis.cube.encode_table, bad_table, fields
)
self.assertRaises(IndexError, isis.cube.encode_table, bad_table, fields)

bad_fields = list(fields)
bad_fields.append({"Name": "TooLong", "Type": "Text", "Size": "1"})
Expand All @@ -193,18 +187,21 @@ def test_encode_table(self):
long_tab["List"] = [1, 2, 3, [4, 5]]
long_field = list(fields)
long_field.append({"Name": "List", "Type": "Integer", "Size": "1"})
self.assertRaises(
IndexError, isis.cube.encode_table, long_tab, long_field
)
self.assertRaises(IndexError, isis.cube.encode_table, long_tab, long_field)

two_field = list(fields[1:])
two_field.append({"Name": "Foo", "Type": "Integer", "Size": "2"})
self.assertRaises(
ValueError, isis.cube.encode_table, table, two_field
)
self.assertRaises(ValueError, isis.cube.encode_table, table, two_field)

seq_tab = dict(table)
seq_tab["List"] = [1, 2, 3, [4, ]]
seq_tab["List"] = [
1,
2,
3,
[
4,
],
]
seq_field = list(fields)
seq_field.append({"Name": "List", "Type": "Integer", "Size": "1"})
seq_data = isis.cube.encode_table(seq_tab, seq_field)
Expand Down Expand Up @@ -240,13 +237,9 @@ def test_overwrite_table(self):
try:
import pvl # noqa F401

isis.cube.overwrite_table(
self.cube, "HiRISE Calibration Ancillary", table
)
isis.cube.overwrite_table(self.cube, "HiRISE Calibration Ancillary", table)

p_tab = isis.cube.get_table(
self.cube, "HiRISE Calibration Ancillary"
)
p_tab = isis.cube.get_table(self.cube, "HiRISE Calibration Ancillary")

self.assertEqual(255, p_tab["GapFlag"][0])
self.assertEqual(27, p_tab["LineNumber"][9])
Expand Down
10 changes: 3 additions & 7 deletions tests/test_cubenormfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)


Expand Down Expand Up @@ -57,18 +57,14 @@ def setUp(self):
)

def test_Dialect(self):
reader = csv.reader(
self.stats.splitlines(), dialect=isis.cubenormfile.Dialect
)
reader = csv.reader(self.stats.splitlines(), dialect=isis.cubenormfile.Dialect)
for row in reader:
self.assertEqual(8, len(row))
break

def test_writer(self):
columns = list()
reader = csv.reader(
self.stats.splitlines(), dialect=isis.cubenormfile.Dialect
)
reader = csv.reader(self.stats.splitlines(), dialect=isis.cubenormfile.Dialect)
for row in reader:
columns.append(row)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fromlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import kalasiris as isis
from .utils import (
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)


Expand Down
10 changes: 3 additions & 7 deletions tests/test_k_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)

# Hardcoding these, but I sure would like a better solution.
Expand Down Expand Up @@ -67,9 +67,7 @@ class Test_hi2isis_k(unittest.TestCase):
@patch("kalasiris.k_funcs.isis.hi2isis")
def test_with_to(self, m_hi2i):
isis.hi2isis_k("dummy.img", to="dummy.cub")
self.assertEqual(
m_hi2i.call_args_list, [call("dummy.img", to="dummy.cub")]
)
self.assertEqual(m_hi2i.call_args_list, [call("dummy.img", to="dummy.cub")])

@patch("kalasiris.k_funcs.isis.hi2isis")
def test_without_to(self, m_hi2i):
Expand Down Expand Up @@ -190,9 +188,7 @@ class Test_cubeit_k(unittest.TestCase):
@patch("kalasiris.k_funcs.isis.cubeit")
def test_cubeit_k(self, m_cubeit):
from_name = "temp_fromlist.txt"
m_context = Mock(
__enter__=Mock(return_value=from_name), __exit__=Mock()
)
m_context = Mock(__enter__=Mock(return_value=from_name), __exit__=Mock())
m_temp = MagicMock(return_value=m_context)
with patch("kalasiris.k_funcs.isis.fromlist.temp", m_temp):
isis.cubeit_k(["a.cub", "b.cub", "c.cub"], to="stacked.cub")
Expand Down
6 changes: 2 additions & 4 deletions tests/test_pysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)


Expand Down Expand Up @@ -72,9 +72,7 @@ def tearDown(self):

def test_getkey(self):
truth = b"HIRISE\n"
key = pysis.getkey(
self.cub, grpname="Instrument", keyword="InstrumentId"
)
key = pysis.getkey(self.cub, grpname="Instrument", keyword="InstrumentId")
self.assertEqual(truth, key)

def test_getkey_fail(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sweetened.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utils import (
resource_check as rc,
real_files as run_real_files,
real_files_reason as run_real_files_reason
real_files_reason as run_real_files_reason,
)


Expand Down
Loading

0 comments on commit 05c10d0

Please sign in to comment.