Skip to content

Commit

Permalink
test(various): Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeyer committed Apr 3, 2023
1 parent a923e25 commit cba3cfb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
25 changes: 24 additions & 1 deletion tests/test_Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path

import kalasiris as isis
from kalasiris.version import version_info
from .utils import (
resource_check as rc,
real_files as run_real_files,
Expand Down Expand Up @@ -182,6 +183,28 @@ def test_contains(self):
def test_len(self):
self.assertEqual(107, len(self.h))

def test_to_str(self):
self.assertEqual(348, len(str(self.h)))

def test_repr(self):
self.assertEqual(4082, len(repr(self.h)))

def test_iter(self):
rows = 0
for x in self.h:
rows +=1

self.assertEqual(107, rows)

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

def test_keys(self):
self.assertEqual(17, len(self.h.keys()))

def test_values(self):
self.assertEqual("0", list(self.h.values())[-1])


@unittest.skipUnless(run_real_files, run_real_files_reason)
class TestHistogram_filesystem(unittest.TestCase):
Expand Down Expand Up @@ -216,7 +239,7 @@ def test_dictlike(self):
def test_listlike(self):
h = isis.Histogram(self.histfile)
cols = 6
if tuple(isis.version.version_info()[:3]) < (4, 3, 0):
if tuple(version_info()[:3]) < (4, 3, 0):
cols = 5
self.assertEqual(cols, len(h[0]))

Expand Down
31 changes: 31 additions & 0 deletions tests/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def test_parse_table(self):
{"Name": "DarkPixels", "Type": "Integer", "Size": "16"},
]

self.assertRaises(ValueError, isis.cube.parse_table, [0, 1], fields)

table = isis.cube.parse_table(table_bytes, fields)

self.assertEqual(255, table["GapFlag"][0])
Expand Down Expand Up @@ -181,6 +183,35 @@ def test_encode_table(self):
bad_fields.append({"Name": "TooLong", "Type": "Text", "Size": "1"})
self.assertRaises(KeyError, isis.cube.encode_table, table, bad_fields)

ee_tab = dict(table)
ee_tab["Long"] = ["a", "b", "c", "dd"]
ee_field = list(fields)
ee_field.append({"Name": "Long", "Type": "Text", "Size": "1"})
self.assertRaises(IndexError, isis.cube.encode_table, ee_tab, ee_field)

long_tab = dict(table)
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
)

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

seq_tab = dict(table)
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)
seq_parsed = isis.cube.parse_table(seq_data, seq_field)
# print(tab)
self.assertEqual(table["Foo"], seq_parsed["List"])

data = isis.cube.encode_table(table, fields)
# print(len(data))
# print(data)
Expand Down
46 changes: 29 additions & 17 deletions tests/test_kalasiris.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,32 @@ def test_format(self):
self.assertEqual(truth, cmd)

@unittest.skip("Fires up the gui, not sure how to test properly.")
def test_no_args(self):
def test_no_args_gui(self):
print("\n about to getkey()")
isis.getkey()
# isis.getkey('gui__') does the same thing.
print(" just got back from getkey()")

@patch("kalasiris.kalasiris.subprocess.run")
def test_no_args(self, subp):
isis.getkey()
subp.assert_called_once()

@unittest.skip("Fires up the gui, not sure how to test properly.")
def test_passthrough(self):
def test_passthrough_gui(self):
to_cube = Path("test_passthrough.cub")
isis.hi2isis(HiRISE_img, to=to_cube)
print("\n about to call qview()")
isis.qview(to_cube)
print(" just got back from qview()")
to_cube.unlink()

@patch("kalasiris.kalasiris.subprocess.run")
def test_passthrough(self, subp):
isis.qview("dummy.cub")
subp.assert_called_once()
self.assertEqual(subp.call_args[0][0], ["qview", "dummy.cub"])

def test_reserved_param(self):
t = "isisprogram"
p = {"help__": "parameter"}
Expand Down Expand Up @@ -115,21 +126,22 @@ def test_subprocess_add(self, subp):
@patch("kalasiris.kalasiris.subprocess.run")
def test_preference_set(self, subp):
s = "foo"
p = Path(s)
isis.set_persistent_preferences(p)
isis.spiceinit("foo.cub", _check=False)
self.subp_defs["check"] = False
subp.assert_called_once_with(
["spiceinit", "from=foo.cub", f"-pref={s}"], **self.subp_defs
)
subp.reset_mock()

isis.spiceinit("foo.cub", _check=False, pref__="override")
subp.assert_called_once_with(
["spiceinit", "from=foo.cub", "-pref=override"], **self.subp_defs
)

isis.set_persistent_preferences(None)
for p in (s, Path(s)):
with self.subTest(p=p):
isis.set_persistent_preferences(p)
isis.spiceinit("foo.cub", _check=False)
self.subp_defs["check"] = False
subp.assert_called_once_with(
["spiceinit", "from=foo.cub", f"-pref={s}"], **self.subp_defs
)
subp.reset_mock()

isis.spiceinit("foo.cub", _check=False, pref__="override")
subp.assert_called_once_with(
["spiceinit", "from=foo.cub", "-pref=override"], **self.subp_defs
)
subp.reset_mock()
isis.set_persistent_preferences(None)


@unittest.skipUnless(run_real_files, run_real_files_reason)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def test_get_from_string(self):
3, 5, 2, "stable", datetime.date(2018, 4, 6)
),
),
(
"""3.5.2.0
v007 # 3rd party libraries version
stable # release stage (alpha, beta, stable)""",
version.ISISversion(
3, 5, 2, "stable", None
),
),
]

for v in s:
Expand Down

0 comments on commit cba3cfb

Please sign in to comment.