Skip to content

Commit

Permalink
Change to pytest (#111)
Browse files Browse the repository at this point in the history
* use pytest: unittest -> pytest translation

* use pytest: CI update & dependencies, including coverage

* pytest in dev dependencies

* empty tests/__init__.py

* Update .github/workflows/ci.yml
  • Loading branch information
stenczelt authored Jun 12, 2024
1 parent d00f0b8 commit a25a5c2
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 279 deletions.
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/codecov-action@v4.4.1
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

0 comments on commit a25a5c2

Please sign in to comment.