Skip to content

Commit 835ead7

Browse files
committed
Use assertpy in integration tests
So that when assertions fail, we get more information about how.
1 parent cb577c0 commit 835ead7

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

tests/it/awt.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
import scyjava
99

10+
from assertpy import assert_that
11+
1012
if platform.system() == "Darwin":
1113
# NB: This test would hang on macOS, due to AWT threading issues.
1214
sys.exit(0)
1315

14-
assert not scyjava.jvm_started()
16+
assert_that(scyjava.jvm_started()).is_false()
17+
1518
scyjava.start_jvm()
1619

1720
if scyjava.is_jvm_headless():
@@ -21,9 +24,9 @@
2124
# In that case, we are not able to perform this test.
2225
sys.exit(0)
2326

24-
assert not scyjava.is_awt_initialized()
27+
assert_that(scyjava.is_awt_initialized()).is_false()
2528

2629
Frame = scyjava.jimport("java.awt.Frame")
2730
f = Frame()
2831

29-
assert scyjava.is_awt_initialized()
32+
assert_that(scyjava.is_awt_initialized()).is_true()

tests/it/headless.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
import scyjava
66

7+
from assertpy import assert_that
8+
79
scyjava.config.enable_headless_mode()
810

9-
assert not scyjava.jvm_started()
11+
assert_that(scyjava.jvm_started()).is_false()
1012
scyjava.start_jvm()
11-
12-
assert scyjava.is_jvm_headless()
13+
assert_that(scyjava.is_jvm_headless()).is_true()
1314

1415
Frame = scyjava.jimport("java.awt.Frame")
15-
try:
16-
f = Frame()
17-
assert False, "HeadlessException should have occurred"
18-
except Exception as e:
19-
assert "java.awt.HeadlessException" == str(e)
16+
assert_that(Frame).raises(Exception).when_called_with().is_equal_to(
17+
"java.awt.HeadlessException"
18+
)

tests/it/java_heap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
Test scyjava JVM memory-related functions.
33
"""
44

5-
from assertpy import assert_that
6-
75
import scyjava
86

7+
from assertpy import assert_that
8+
99
mb_initial = 50 # initial MB of memory to snarf up
1010
mb_tolerance = 10 # ceiling of expected MB in use
1111

1212
scyjava.config.set_heap_min(mb=mb_initial)
1313
scyjava.config.set_heap_max(gb=1)
1414

15-
assert not scyjava.jvm_started()
15+
assert_that(scyjava.jvm_started()).is_false()
16+
1617
scyjava.start_jvm()
1718

18-
assert scyjava.available_processors() >= 1
19+
assert_that(scyjava.available_processors()).is_greater_than_or_equal_to(1)
1920

2021
mb_max = scyjava.memory_max() // 1024 // 1024
2122
mb_total = scyjava.memory_total() // 1024 // 1024

tests/it/jvm_version.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
import scyjava
66

7-
assert not scyjava.jvm_started()
7+
from assertpy import assert_that
8+
9+
assert_that(scyjava.jvm_started()).is_false()
810

911
before_version = scyjava.jvm_version()
10-
assert before_version is not None
11-
assert len(before_version) >= 3
12-
assert before_version[0] > 0
12+
assert_that(before_version).is_not_none()
13+
assert_that(len(before_version)).is_greater_than_or_equal_to(3)
14+
assert_that(before_version[0]).is_greater_than(0)
1315

1416
scyjava.config.enable_headless_mode()
1517
scyjava.start_jvm()
1618

1719
after_version = scyjava.jvm_version()
18-
assert after_version is not None
19-
assert len(after_version) >= 3
20-
assert after_version[0] > 0
20+
assert_that(after_version).is_not_none()
21+
assert_that(len(after_version)).is_greater_than_or_equal_to(3)
22+
assert_that(after_version[0]).is_greater_than(0)
2123

22-
assert before_version == after_version
24+
assert_that(before_version).is_equal_to(after_version)

tests/it/script_scope.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import scyjava
88

9+
from assertpy import assert_that
10+
911
scyjava.config.endpoints.extend(
1012
["org.scijava:scijava-common:2.94.2", "org.scijava:scripting-python:MANAGED"]
1113
)
@@ -23,7 +25,8 @@
2325
# Assert that the Python script language is available.
2426
ss = ctx.service("org.scijava.script.ScriptService")
2527
lang = ss.getLanguageByName("Python")
26-
assert lang is not None and "Python" in lang.getNames()
28+
assert_that(lang).is_not_none()
29+
assert_that(lang.getNames()).contains("Python")
2730

2831
# Construct a script.
2932
script = """
@@ -58,5 +61,5 @@ def calculate_cbrt(age):
5861
sys.stderr.write(f"{trace}\n")
5962
raise e
6063

61-
assert statement == "2"
62-
assert return_value == "The rounded cube root of my age is 2"
64+
assert_that(statement).is_equal_to("2")
65+
assert_that(return_value).is_equal_to("The rounded cube root of my age is 2")

tests/it/scripting.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import scyjava
1111

12+
from assertpy import assert_that
13+
1214
scyjava.config.endpoints.extend(
1315
["org.scijava:scijava-common:2.94.2", "org.scijava:scripting-python:MANAGED"]
1416
)
@@ -26,7 +28,8 @@
2628
# Assert that the Python script language is available.
2729
ss = ctx.service("org.scijava.script.ScriptService")
2830
lang = ss.getLanguageByName("Python")
29-
assert lang is not None and "Python" in lang.getNames()
31+
assert_that(lang).is_not_none()
32+
assert_that(lang.getNames()).contains("Python")
3033

3134
# Construct a script.
3235
script = """
@@ -55,5 +58,7 @@
5558
sys.stderr.write(f"{trace}\n")
5659
raise e
5760

58-
assert statement == "Hello, Chuckles! In one year you will be 14 years old."
59-
assert return_value == "A wild return value appears!"
61+
assert_that(statement).is_equal_to(
62+
"Hello, Chuckles! In one year you will be 14 years old."
63+
)
64+
assert_that(return_value).is_equal_to("A wild return value appears!")

0 commit comments

Comments
 (0)