Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to pytest #111

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
name: ci

on: [push, pull_request]
on: [ push, pull_request ]

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: pipx install poetry
- name: Install poetry
run: pipx install poetry

- name: Install python dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --with dev
- name: Install python dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --with dev

- name: Run unit tests
run: |
poetry run python -m unittest -v tests
- name: Run unit tests
run: |
poetry run pytest --cov=abcd --cov-report xml --cov-report term:skip-covered

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "abcd"
version = "0.6.0"
description = "This is a package which helps to store and share atomistic data."
authors = ["Adam Fekete", "Gabor Csanyi"]
keywords=["ase", "database", "mongo", "flask", "opensearch"]
keywords = ["ase", "database", "mongo", "flask", "opensearch"]
readme = "README.md"
homepage = "https://libatoms.github.io/abcd/"
repository = "https://github.com/libatoms/abcd"
Expand All @@ -21,9 +21,11 @@ lark = "^1.1.9"

[tool.poetry.group.dev.dependencies]
mongomock = "^4.1.2"
pytest = "^8.2.2"
pytest-cov = "^5.0.0"

[tool.poetry.extras]
tests = ["mongomock"]
tests = ["mongomock", "pytest", "pytest-cov"]
mongo = ["pymongo"]
http = ["requests"]
server-api = ["flask"]
Expand Down
9 changes: 0 additions & 9 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
import unittest
from tests.parsers import ParsingQueries, ParsingExtras
from tests.database import Mongo

import logging

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
unittest.main(verbosity=1, exit=False)
48 changes: 0 additions & 48 deletions tests/database.py

This file was deleted.

204 changes: 0 additions & 204 deletions tests/parsers.py

This file was deleted.

38 changes: 38 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
import mongomock

from abcd import ABCD

from io import StringIO
from ase.io import read


@pytest.fixture
@mongomock.patch(servers=(('localhost', 27017),))
def abcd_mongodb():
url = 'mongodb://localhost'
abcd = ABCD.from_url(url)
abcd.print_info()

return abcd


def test_thing(abcd_mongodb):
print(abcd_mongodb.info())


def test_push(abcd_mongodb):
xyz = StringIO("""2
Properties=species:S:1:pos:R:3 s="sadf" _vtk_test="t e s t _ s t r" pbc="F F F"
Si 0.00000000 0.00000000 0.00000000
Si 0.00000000 0.00000000 0.00000000
""")

atoms = read(xyz, format='extxyz')
atoms.set_cell([1, 1, 1])

abcd_mongodb.destroy()
abcd_mongodb.push(atoms)
new = list(abcd_mongodb.get_atoms())[0]

assert atoms == new
Loading