|
| 1 | +import pytest |
| 2 | +import mock |
| 3 | + |
| 4 | +from openpathsampling.experimental.storage.collective_variables import \ |
| 5 | + CoordinateFunctionCV |
| 6 | + |
| 7 | +from paths_cli.wizard.core import * |
| 8 | + |
| 9 | +from paths_cli.tests.wizard.mock_wizard import ( |
| 10 | + make_mock_wizard, make_mock_retry_wizard |
| 11 | +) |
| 12 | + |
| 13 | +def test_name(): |
| 14 | + wizard = make_mock_wizard('foo') |
| 15 | + cv = CoordinateFunctionCV(lambda s: s.xyz[0][0]) |
| 16 | + assert not cv.is_named |
| 17 | + result = name(wizard, cv, obj_type="CV", store_name="cvs") |
| 18 | + assert result is cv |
| 19 | + assert result.is_named |
| 20 | + assert result.name == 'foo' |
| 21 | + |
| 22 | +def test_name_exists(): |
| 23 | + wizard = make_mock_retry_wizard(['foo', 'bar']) |
| 24 | + wizard.cvs['foo'] = 'placeholder' |
| 25 | + cv = CoordinateFunctionCV(lambda s: s.xyz[0][0]) |
| 26 | + assert not cv.is_named |
| 27 | + result = name(wizard, cv, obj_type="CV", store_name="cvs") |
| 28 | + assert result is cv |
| 29 | + assert result.is_named |
| 30 | + assert result.name == 'bar' |
| 31 | + assert wizard.console.input.call_count == 2 |
| 32 | + |
| 33 | +@pytest.mark.parametrize('req,expected', [ |
| 34 | + (('foo', 2, 2), '2'), (('foo', 2, float('inf')), 'at least 2'), |
| 35 | + (('foo', 0, 2), 'at most 2'), |
| 36 | + (('foo', 1, 3), 'at least 1 and at most 3') |
| 37 | +]) |
| 38 | +def test_interpret_req(req, expected): |
| 39 | + assert interpret_req(req) == expected |
| 40 | + |
| 41 | +@pytest.mark.parametrize('length,expected', [ |
| 42 | + (0, 'foo'), (1, 'baz'), (2, 'quux'), |
| 43 | +]) |
| 44 | +def test_get_missing_object(length, expected): |
| 45 | + dct = dict([('bar', 'baz'), ('qux', 'quux')][:length]) |
| 46 | + fallback = lambda x: 'foo' |
| 47 | + wizard = make_mock_wizard('2') |
| 48 | + result = get_missing_object(wizard, dct, display_name='string', |
| 49 | + fallback_func=fallback) |
| 50 | + assert result == expected |
| 51 | + pass |
0 commit comments