From 2916686ade59a4c9b11efb2cbfdde04e80a3a2cc Mon Sep 17 00:00:00 2001 From: yusuke-takase Date: Wed, 24 Apr 2024 12:59:54 +0900 Subject: [PATCH] fix pytest, add github actions --- .github/workflows/test.yml | 27 +++++++ .gitignore | 4 + poetry.lock | 84 ++++++++++++++++---- pyproject.toml | 1 + {grasp2alm/test => test}/beam_files/test.cut | 0 {grasp2alm/test => test}/beam_files/test.grd | 0 grasp2alm/test/test.py => test/test_main.py | 17 ++-- 7 files changed, 111 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/test.yml rename {grasp2alm/test => test}/beam_files/test.cut (100%) rename {grasp2alm/test => test}/beam_files/test.grd (100%) rename grasp2alm/test/test.py => test/test_main.py (62%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..add2efe --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + types: [opened, reopened, synchronize] + +jobs: + tests: + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + python: [3.9, 3.11] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Test + run: | + python3 -m pytest diff --git a/.gitignore b/.gitignore index 43ad15f..4a7886e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ grasp2alm.egg-info/ grasp2alm/__pycache__/ dist/ build/ +docs/_build/ +docs/_templates/ +test/__pycache__ +.pytest_cache/ diff --git a/poetry.lock b/poetry.lock index d01b1a3..0a6c2d3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -20,22 +20,12 @@ test = ["pytest (>=7.0)", "pytest-doctestplus (>=0.12)", "pytest-astropy-header test_all = ["pytest (>=7.0)", "pytest-doctestplus (>=0.12)", "pytest-astropy-header (>=0.2.1)", "pytest-astropy (>=0.10)", "pytest-xdist", "objgraph", "ipython (>=4.2)", "coverage", "skyfield (>=1.20)", "sgp4 (>=2.3)"] [[package]] -name = "contourpy" -version = "1.1.1" -description = "Python library for calculating contours of 2D quadrilateral grids" +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." category = "main" optional = false -python-versions = ">=3.8" - -[package.dependencies] -numpy = {version = ">=1.16,<2.0", markers = "python_version <= \"3.11\""} - -[package.extras] -docs = ["furo", "sphinx (>=7.2)", "sphinx-copybutton"] -bokeh = ["bokeh", "selenium"] -mypy = ["contourpy", "docutils-stubs", "mypy (==1.4.1)", "types-pillow"] -test = ["contourpy", "matplotlib", "pillow"] -test-no-images = ["pytest", "pytest-cov", "wurlitzer"] +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" [[package]] name = "contourpy" @@ -67,6 +57,17 @@ python-versions = ">=3.8" docs = ["ipython", "matplotlib", "numpydoc", "sphinx"] tests = ["pytest", "pytest-cov", "pytest-xdist"] +[[package]] +name = "exceptiongroup" +version = "1.2.1" +description = "Backport of PEP 654 (exception groups)" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "fonttools" version = "4.51.0" @@ -121,6 +122,14 @@ zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} docs = ["sphinx (>=3.5)", "sphinx (<7.2.5)", "jaraco.packaging (>=9.3)", "rst.linker (>=1.9)", "furo", "sphinx-lint", "jaraco.tidelift (>=1.4)"] testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ruff (>=0.2.1)", "zipp (>=3.17)", "jaraco.test (>=5.4)", "pytest-mypy"] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +category = "main" +optional = false +python-versions = ">=3.7" + [[package]] name = "kiwisolver" version = "1.4.5" @@ -181,6 +190,18 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa typing = ["typing-extensions"] xmp = ["defusedxml"] +[[package]] +name = "pluggy" +version = "1.5.0" +description = "plugin and hook calling mechanisms for python" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pyerfa" version = "2.0.0.3" @@ -207,6 +228,25 @@ python-versions = ">=3.6.8" [package.extras] diagrams = ["railroad-diagrams", "jinja2"] +[[package]] +name = "pytest" +version = "8.1.1" +description = "pytest: simple powerful testing with Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=1.4,<2.0" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -250,6 +290,14 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +category = "main" +optional = false +python-versions = ">=3.7" + [[package]] name = "zipp" version = "3.18.1" @@ -265,24 +313,30 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-ena [metadata] lock-version = "1.1" python-versions = ">=3.9,<3.13" -content-hash = "f8a567f8b9faa7c148e0652cbd800c67390b5198d03b4ebff7b1d8993a77ccf8" +content-hash = "2d3060b16b3396c1c3b7b50463b66d00822db10606466561592623e0aeaf3201" [metadata.files] astropy = [] +colorama = [] contourpy = [] cycler = [] +exceptiongroup = [] fonttools = [] healpy = [] importlib-resources = [] +iniconfig = [] kiwisolver = [] matplotlib = [] numpy = [] packaging = [] pillow = [] +pluggy = [] pyerfa = [] pyparsing = [] +pytest = [] python-dateutil = [] pyyaml = [] scipy = [] six = [] +tomli = [] zipp = [] diff --git a/pyproject.toml b/pyproject.toml index dc4045b..0ad7cc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ numpy = "^1.23" healpy = "^1.15.0" matplotlib = "^3.1" scipy = "^1.13.0" +pytest = "^8.1.1" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/grasp2alm/test/beam_files/test.cut b/test/beam_files/test.cut similarity index 100% rename from grasp2alm/test/beam_files/test.cut rename to test/beam_files/test.cut diff --git a/grasp2alm/test/beam_files/test.grd b/test/beam_files/test.grd similarity index 100% rename from grasp2alm/test/beam_files/test.grd rename to test/beam_files/test.grd diff --git a/grasp2alm/test/test.py b/test/test_main.py similarity index 62% rename from grasp2alm/test/test.py rename to test/test_main.py index 034f40c..74d0b8b 100644 --- a/grasp2alm/test/test.py +++ b/test/test_main.py @@ -1,28 +1,31 @@ # -*- encoding: utf-8 -*- import unittest -import grasp2alm as gp +from grasp2alm import BeamGrid, BeamCut, grasp2alm import numpy as np +from pathlib import Path class TestGrasp2Alm(unittest.TestCase): def test_grasp2alm_with_gridfile(self): - file = "./beam_files/test.grd" - beam = gp.BeamGrid(file) + file = Path(__file__).parent / "beam_files" / "test.grd" + file = str(file) + beam = BeamGrid(file) polar = beam.to_polar() nside = 128 beammap = polar.to_map(nside) blm1 = beammap.to_alm() - blm2 = gp.grasp2alm(file, nside) + blm2 = grasp2alm(file, nside) self.assertTrue(np.array_equal(blm1, blm2), "blm1 and blm2 are not equal") def test_grasp2alm_with_cutfile(self): - file = "./beam_files/test.cut" - beam = gp.BeamCut(file) + file = Path(__file__).parent / "beam_files" / "test.cut" + file = str(file) + beam = BeamCut(file) polar = beam.to_polar() nside = 128 beammap = polar.to_map(nside) blm1 = beammap.to_alm() - blm2 = gp.grasp2alm(file, nside) + blm2 = grasp2alm(file, nside) self.assertTrue(np.array_equal(blm1, blm2), "blm1 and blm2 are not equal")