def test_get_modifier_uncached(self, mocker): klass = mocker.Mock(return_value='modifier') mocker.patch.object( steps.entrypointer.eps, 'stepmaker.modifiers', {'test': klass}, ) mocker.patch.object( StepForTest, '_group_mods', None, ) addr = addresses.StepAddress('file.name', '/some/path') mod_map = { 'mod1': 'modifier1', 'mod2': 'modifier2', } StepForTest._get_modifier('test', 'value', addr, mod_map) assert mod_map == { 'mod1': 'modifier1', 'mod2': 'modifier2', 'test': 'modifier', } assert StepForTest._group_mods == {'test': klass} klass.assert_called_once_with('test', 'value', mocker.ANY) other_addr = klass.call_args[0][-1] assert isinstance(other_addr, addresses.StepAddress) assert id(other_addr) != id(addr) assert other_addr.filename == addr.filename assert other_addr.path == '/some/path/test'
def test_parse_list(self, mocker): steps = [ mocker.Mock(eager=False, return_value='step1'), mocker.Mock(eager=False, return_value='step2'), mocker.Mock(eager=True, return_value=['step3', 'step4']), mocker.Mock(eager=False, return_value='step5'), ] mock_parse = mocker.patch.object( StepForTest, 'parse', side_effect=steps[:], ) addr = addresses.StepAddress('file.name', '/some/path') description = ['conf1', 'conf2', 'conf3', 'conf5'] result = StepForTest.parse_list('ctxt', description, addr) assert result == [steps[0], steps[1], 'step3', 'step4', steps[3]] mock_parse.assert_has_calls( [mocker.call(conf, mocker.ANY) for conf in description]) assert mock_parse.call_count == len(description) for i in range(len(description)): tmp_addr = mock_parse.call_args_list[i][0][-1] assert isinstance(tmp_addr, addresses.StepAddress) assert id(tmp_addr) != id(addr) assert tmp_addr.filename == addr.filename assert tmp_addr.path == '/some/path[%d]' % i
def test_get_action_cached(self, mocker): klass = mocker.Mock(return_value='action') cached = mocker.Mock(return_value='cached') mocker.patch.object( steps.entrypointer.eps, 'stepmaker.actions', {'test': klass}, ) mocker.patch.object( StepForTest, '_group_acts', {'test': cached}, ) addr = addresses.StepAddress('file.name', '/some/path') result = StepForTest._get_action('test', 'value', addr) assert result == 'cached' assert StepForTest._group_acts == {'test': cached} klass.assert_not_called() cached.assert_called_once_with('test', 'value', mocker.ANY) other_addr = cached.call_args[0][-1] assert isinstance(other_addr, addresses.StepAddress) assert id(other_addr) != id(addr) assert other_addr.filename == addr.filename assert other_addr.path == '/some/path/test'
def test_base(self): addr = addresses.StepAddress('file.name', 'path') with utils.jsonschema_validator(addr): result = 42 assert result == 42
def test_idx(self): obj = addresses.StepAddress('filename', '/some/path') result = obj.idx(42) assert id(obj) != id(result) assert obj.path == '/some/path' assert result.filename == obj.filename assert result.path == '/some/path[42]'
def test_key(self): obj = addresses.StepAddress('filename', '/some/path') result = obj.key('spam') assert id(obj) != id(result) assert obj.path == '/some/path' assert result.filename == obj.filename assert result.path == '/some/path/spam'
def test_validation_error(self): addr = addresses.StepAddress('file.name', 'path') with pytest.raises(exceptions.StepError) as exc_info: with utils.jsonschema_validator(addr): raise ValidationException('some message', ['a', 1, 'b', 2]) assert isinstance(exc_info.value.addr, addresses.StepAddress) assert exc_info.value.addr.filename == 'file.name' assert exc_info.value.addr.path == 'path/a[1]/b[2]'
def test_get_action_set(self, mocker): klass = mocker.Mock(return_value='action') mocker.patch.object( steps.entrypointer.eps, 'stepmaker.actions', {'test': klass}, ) mocker.patch.object( StepForTest, '_group_acts', None, ) addr = addresses.StepAddress('file.name', '/some/path') action = mocker.Mock() action.name = 'spam' with pytest.raises(exceptions.StepError) as exc_info: StepForTest._get_action('test', 'value', addr, action) assert StepForTest._group_acts == {'test': klass} klass.assert_not_called() other_addr = exc_info.value.addr assert other_addr is addr
def test_init_base(self): result = addresses.StepAddress('filename') assert result.filename == 'filename' assert result.path == ''
def test_str(self): obj = addresses.StepAddress('filename', '/some/path') assert six.text_type(obj) == 'filename:/some/path'
def test_init_alt(self): result = addresses.StepAddress('filename', '/some/path') assert result.filename == 'filename' assert result.path == '/some/path'
def test_base_exception(self): addr = addresses.StepAddress('file.name', 'path') with pytest.raises(ExceptionForTest): with utils.jsonschema_validator(addr): raise ExceptionForTest('test')