Skip to content

Commit e154e19

Browse files
committed
fix(test) Update the last merge.
1 parent bf523c4 commit e154e19

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

justfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ prelude:
33
pip3 install virtualenv
44
virtualenv -p $(which python3) .env
55
source .env/bin/activate
6-
76
pip3 install pyo3-pack pytest pytest-benchmark
87

98
# Setup the environment to develop the extension.
@@ -26,7 +25,7 @@ python-run file='': wakeup
2625

2726
# Run the tests.
2827
test: wakeup
29-
py.test tests
28+
@py.test tests
3029

3130
# Inspect the `python-ext-wasm` extension.
3231
inspect: wakeup

tests/test_benchmarks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
def test_sum_benchmark(benchmark):
1010
instance = Instance(TEST_BYTES)
11-
sum_func = instance.exports['sum']
11+
sum = instance.exports.sum
1212

1313
def bench():
14-
return sum_func(1, 2)
14+
return sum(1, 2)
1515

1616
assert benchmark(bench) == 3

tests/test_instance.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,40 @@ def test_failed_to_instantiate():
2323
)
2424

2525
def test_function_does_not_exist():
26-
with pytest.raises(KeyError) as context_manager:
27-
Instance(TEST_BYTES).exports['foo']
26+
with pytest.raises(LookupError) as context_manager:
27+
Instance(TEST_BYTES).exports.foo
2828

2929
exception = context_manager.value
30-
assert str(exception) == "'foo'"
30+
assert str(exception) == 'Function `foo` does not exist.'
3131

3232
def test_basic_sum():
33-
assert Instance(TEST_BYTES).exports['sum'](1, 2) == 3
33+
assert Instance(TEST_BYTES).exports.sum(1, 2) == 3
3434

3535
def test_call_arity_0():
36-
assert Instance(TEST_BYTES).exports['arity_0']() == 42
36+
assert Instance(TEST_BYTES).exports.arity_0() == 42
3737

3838
def test_call_i32_i32():
39-
assert Instance(TEST_BYTES).exports['i32_i32'](7) == 7
39+
assert Instance(TEST_BYTES).exports.i32_i32(7) == 7
4040

4141
def test_call_i64_i64():
42-
assert Instance(TEST_BYTES).exports['i64_i64'](7) == 7
42+
assert Instance(TEST_BYTES).exports.i64_i64(7) == 7
4343

4444
def test_call_f32_f32():
45-
assert Instance(TEST_BYTES).exports['f32_f32'](7.) == 7.
45+
assert Instance(TEST_BYTES).exports.f32_f32(7.) == 7.
4646

4747
def test_call_f64_f64():
48-
assert Instance(TEST_BYTES).exports['f64_f64'](7.) == 7.
48+
assert Instance(TEST_BYTES).exports.f64_f64(7.) == 7.
4949

5050
def test_call_i32_i64_f32_f64_f64():
51-
assert round(Instance(TEST_BYTES).exports['i32_i64_f32_f64_f64'](1, 2, 3.4, 5.6), 6) == (
51+
assert round(Instance(TEST_BYTES).exports.i32_i64_f32_f64_f64(1, 2, 3.4, 5.6), 6) == (
5252
1 + 2 + 3.4 + 5.6
5353
)
5454

5555
def test_call_bool_casted_to_i32():
56-
assert Instance(TEST_BYTES).exports['bool_casted_to_i32']() == 1
56+
assert Instance(TEST_BYTES).exports.bool_casted_to_i32() == 1
5757

5858
def test_call_string():
59-
assert Instance(TEST_BYTES).exports['string']() == 1048576
59+
assert Instance(TEST_BYTES).exports.string() == 1048576
6060

6161
def test_validate():
6262
assert validate(TEST_BYTES)

tests/test_memory_view.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def test_length():
3131
1114112
3232
)
3333

34-
#def test_get(self):
35-
# memory = Instance(TEST_BYTES).uint8_memory_view()
36-
# index = 7
37-
# value = 42
38-
# memory[index] = value
34+
def test_get():
35+
memory = Instance(TEST_BYTES).uint8_memory_view()
36+
index = 7
37+
value = 42
38+
memory[index] = value
3939

40-
# assert memory[index] == value
40+
assert memory[index] == value
4141

4242
def test_get_out_of_range():
4343
with pytest.raises(IndexError) as context_manager:
@@ -49,19 +49,19 @@ def test_get_out_of_range():
4949
'Out of bound: Absolute index 1114113 is larger than the memory size 1114112.'
5050
)
5151

52-
#def test_set_out_of_range(self):
53-
# with self.assertRaises(IndexError) as context_manager:
54-
# memory = Instance(TEST_BYTES).uint8_memory_view()
55-
# memory[len(memory) + 1] = 42
52+
def test_set_out_of_range():
53+
with pytest.raises(IndexError) as context_manager:
54+
memory = Instance(TEST_BYTES).uint8_memory_view()
55+
memory[len(memory) + 1] = 42
5656

57-
# exception = context_manager.value
58-
# assert str(exception) == (
59-
# 'Out of bound: Absolute index 1114113 is larger than the memory size 1114112.'
60-
# )
57+
exception = context_manager.value
58+
assert str(exception) == (
59+
'Out of bound: Absolute index 1114113 is larger than the memory size 1114112.'
60+
)
6161

6262
def test_hello_world():
6363
instance = Instance(TEST_BYTES)
64-
pointer = instance.exports['string']()
64+
pointer = instance.exports.string()
6565
memory = instance.uint8_memory_view(pointer)
6666
nth = 0
6767
string = ''

0 commit comments

Comments
 (0)