mirror of https://github.com/McSinyx/palace
Nitpick test_source, implement test_context. (#70)
Implement test_context Tests that have implemented: * async wake interval * default resampler index * doppler factor * speed of sound * distance model
This commit is contained in:
parent
a9d743ae87
commit
a25c93bbb1
|
@ -1,6 +1,7 @@
|
||||||
# Source pytest module
|
# Source pytest module
|
||||||
# Copyright (C) 2020 Ngô Ngọc Đức Huy
|
# Copyright (C) 2020 Ngô Ngọc Đức Huy
|
||||||
# Copyright (C) 2020 Nguyễn Gia Phong
|
# Copyright (C) 2020 Nguyễn Gia Phong
|
||||||
|
# Copyright (C) 2020 Ngô Xuân Minh
|
||||||
#
|
#
|
||||||
# This file is part of palace.
|
# This file is part of palace.
|
||||||
#
|
#
|
||||||
|
@ -19,7 +20,10 @@
|
||||||
|
|
||||||
"""This pytest module tries to test the correctness of the class Context."""
|
"""This pytest module tries to test the correctness of the class Context."""
|
||||||
|
|
||||||
from palace import current_context, Context, MessageHandler
|
from palace import current_context, distance_models, Context, MessageHandler
|
||||||
|
from pytest import raises
|
||||||
|
|
||||||
|
from math import inf
|
||||||
|
|
||||||
|
|
||||||
def test_with_context(device):
|
def test_with_context(device):
|
||||||
|
@ -48,3 +52,45 @@ def test_message_handler(device):
|
||||||
assert context.message_handler is message_handler_test
|
assert context.message_handler is message_handler_test
|
||||||
with context:
|
with context:
|
||||||
assert current_context().message_handler is context.message_handler
|
assert current_context().message_handler is context.message_handler
|
||||||
|
|
||||||
|
|
||||||
|
def test_async_wake_interval(device):
|
||||||
|
"""Test read-write property async_wake_interval."""
|
||||||
|
with Context(device) as context:
|
||||||
|
context.async_wake_interval = 42
|
||||||
|
assert context.async_wake_interval == 42
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_resampler_index(device):
|
||||||
|
"""Test return values default_resampler_index."""
|
||||||
|
with Context(device) as context:
|
||||||
|
index = context.default_resampler_index
|
||||||
|
assert index >= 0
|
||||||
|
assert len(context.available_resamplers) > index
|
||||||
|
|
||||||
|
|
||||||
|
def test_doppler_factor(device):
|
||||||
|
"""Test write property doppler_factor."""
|
||||||
|
with Context(device) as context:
|
||||||
|
context.doppler_factor = 4/9
|
||||||
|
context.doppler_factor = 9/4
|
||||||
|
context.doppler_factor = 0
|
||||||
|
context.doppler_factor = inf
|
||||||
|
with raises(ValueError): context.doppler_factor = -1
|
||||||
|
|
||||||
|
|
||||||
|
def test_speed_of_sound(device):
|
||||||
|
"""Test write property speed_of_sound."""
|
||||||
|
with Context(device) as context:
|
||||||
|
context.speed_of_sound = 5/7
|
||||||
|
context.speed_of_sound = 7/5
|
||||||
|
with raises(ValueError): context.speed_of_sound = 0
|
||||||
|
context.speed_of_sound = inf
|
||||||
|
with raises(ValueError): context.speed_of_sound = -1
|
||||||
|
|
||||||
|
|
||||||
|
def test_distance_model(device):
|
||||||
|
"""Test preset values distance_model."""
|
||||||
|
with Context(device) as context:
|
||||||
|
for model in distance_models: context.distance_model = model
|
||||||
|
with raises(ValueError): context.distance_model = 'EYYYYLMAO'
|
||||||
|
|
|
@ -40,7 +40,7 @@ def test_group(context):
|
||||||
|
|
||||||
|
|
||||||
def test_priority(context):
|
def test_priority(context):
|
||||||
"""Test read-write property group."""
|
"""Test read-write property priority."""
|
||||||
with Source(context) as source:
|
with Source(context) as source:
|
||||||
assert source.priority == 0
|
assert source.priority == 0
|
||||||
source.priority = 42
|
source.priority = 42
|
||||||
|
|
Loading…
Reference in New Issue