Metadata-Version: 2.1
Name: pytest-yls
Version: 1.2.4
Summary: Pytest plugin to test the YLS as a whole.
License: MIT
Author: Matej Kastak
Author-email: matej.kastak@avast.com
Maintainer: Matej Kašťák
Maintainer-email: matej.kastak@avast.com
Requires-Python: >=3.8,<3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: pytest (>=7.1.2,<8.0.0)
Requires-Dist: tenacity (>=8.0.1,<9.0.0)
Requires-Dist: yls (>=1,<2)
Description-Content-Type: text/markdown

# pytest-yls

![PyPI](https://img.shields.io/pypi/v/pytest-yls)

Pytest plugin adding primitives for E2E/integration tests.

Public fixtures:
- `yls_prepare`
- `yls_prepare_with_settings`

To interact with the tested YLS use `Context` obtained by calling the fixture.
For more information about the `Context` class checkout
[plugin.py](https://github.com/avast/yls/blob/master/pytest-yls/pytest_yls/plugin.py).

### Example test

```python

# Add yls_prepare fixture
def test_completion_basic(yls_prepare):
    # Prepare the tested file
    # <$> marks the cursor position
    contents = """rule test {
    condition:
        <$>
}"""
    
    # Initialize the testing context by calling the fixture
    context = yls_prepare(contents)

    # You can now simulate requests on the context
    # In this case we trigger the code completion
    response = context.send_request(
        methods.COMPLETION,
        types.CompletionParams(
            textDocument=types.TextDocumentIdentifier(uri=context.opened_file.as_uri()),
            position=context.get_cursor_position(),
        ),
    )

    # Assert the response how you want
    assert response
    for module in ["cuckoo", "elf", "pe", "time"]:
        assert any(
            module in item["label"] for item in response["items"]
        ), f"{module=} is not in response"
```

For more inspiration check out
[yls/tests](https://github.com/avast/yls/tree/master/tests).

## License

Copyright (c) 2022 Avast Software, licensed under the MIT license. See the
[`LICENSE`](https://github.com/avast/yls/blob/master/pytest-yls/LICENSE) file
for more details.

