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

Test suite, CLI #74

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e3dfde3
feat: add test workflow and update dependencies
cpaniaguam Jan 19, 2024
4ef1861
fix: python version to 3.9
cpaniaguam Jan 19, 2024
8d895e3
Merge branch 'main' into feat-build-test-suite
cpaniaguam Jan 21, 2024
3b8d17b
Update pytest command in run_tests.yml
cpaniaguam Jan 21, 2024
0892d15
fix: use pathlib.Path to handle paths
cpaniaguam Jan 23, 2024
b6462ed
test: extract input data files
cpaniaguam Jan 23, 2024
4bbb2d6
feat: add .gitattributes and update .gitignore
cpaniaguam Jan 24, 2024
19a66dd
test: suite working serially
cpaniaguam Jan 25, 2024
bc866ff
Remove print statements for CLI usage in color class
cpaniaguam Jan 25, 2024
b21d787
chore: clean up 2021_IceSAT2_startup_local.py
cpaniaguam Jan 25, 2024
d647473
feat: add cli B01_SL_load_single_file.py
cpaniaguam Jan 25, 2024
01ea5dc
feat: clitools and cli for B01_SL_load_single_file
cpaniaguam Jan 25, 2024
03a7322
update: clitools
cpaniaguam Jan 26, 2024
2c9f998
fix: leverege updates in clitools
cpaniaguam Jan 26, 2024
b01f076
chore: move inputs to the top
cpaniaguam Jan 26, 2024
7a59797
feat: add cli to B02_make_spectra
cpaniaguam Jan 26, 2024
fb49304
feat: cli for B03_plot_spectra_ov
cpaniaguam Jan 26, 2024
572be4a
feat: cli for A02c_IOWAGA
cpaniaguam Jan 26, 2024
2c66eb8
feat: tests running in parallel
cpaniaguam Jan 27, 2024
5dfbd32
test: add test data files for steps 2-5
cpaniaguam Jan 27, 2024
0601105
chore: refactor delete_pdf_files
cpaniaguam Jan 28, 2024
1eb2574
feat: add pre-push hook to run tests before pushing changes
cpaniaguam Jan 28, 2024
8152cda
fix: pytest command to run tests in parallel
cpaniaguam Jan 28, 2024
784c69e
feat: update dependencies and add scripts to pyproject.toml
cpaniaguam Jan 28, 2024
cc2f0ac
fix: pyproject.toml
cpaniaguam Jan 28, 2024
c9d1934
feat: Add icesat2waves CLI entry point
cpaniaguam Jan 28, 2024
4fbd76f
refactor: icesatwaves cli
cpaniaguam Jan 28, 2024
406b569
fix(ci): enable LFS in GitHub Actions workflow, rename it
cpaniaguam Jan 29, 2024
0eaaf27
fix: update test configuration
cpaniaguam Jan 29, 2024
185acae
Merge branch 'main' into feat-build-test-suite
cpaniaguam Jan 29, 2024
6272de1
fix: update pytest command in run_tests.yml
cpaniaguam Jan 29, 2024
8371980
Update pytest command in run_tests.yml
cpaniaguam Jan 29, 2024
9ca5e33
feat(ci): add durations and sugar plugins
cpaniaguam Jan 29, 2024
b307741
fix(ci): update pytest configuration
cpaniaguam Jan 29, 2024
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
1 change: 1 addition & 0 deletions .gitattributes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles the tar.gz files with lfs.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tar.gz filter=lfs diff=lfs merge=lfs -text
29 changes: 29 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test steps
on:
pull_request: {}
push:
branches: [ main ]
jobs:
python_run_scripts:
strategy:
fail-fast: false
matrix:
version: ['3.9']
runs-on: ubuntu-latest
steps:
- name: install mpi
run: sudo apt update && sudo apt-get install openmpi-bin openmpi-doc libopenmpi-dev
- uses: actions/checkout@v3
with:
lfs: true
- name: setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }} # install the python version needed
cache: "pip"
- name: install icesat2-tracks using pip
run: pip install .
- name: install pytest
run: pip install pytest pytest-xdist
- name: Run tests
run: pytest --capture=sys --verbose --showlocals --tb=long --durations=5 --numprocesses=4 tests/test_steps.py
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those new to the pytest framework, here is a breakdown of the command that runs the tests:

  • pytest: This is the command to run the pytest testing framework.

  • --capture=sys: This option tells pytest to capture stdout and stderr at the sys level. If your tests print to stdout or stderr, those prints will be captured and only displayed in the event of a test failure.

  • --verbose or -v: This option enables verbose output, which means pytest will print more information about each test that is run.

  • --showlocals or -l: This option shows local variables in tracebacks.

  • --tb=long: This option controls the format of the traceback that pytest prints when a test fails. long is the most detailed format.

  • --durations=5: This option tells pytest to record the duration of each test, and at the end of the test session, list the 5 slowest tests.

  • --numprocesses=4 or -n 4: This option, provided by the pytest-xdist plugin, tells pytest to run tests in parallel with 4 workers.

  • tests/test_steps.py: This is the path to the test file that pytest should run.

35 changes: 0 additions & 35 deletions .github/workflows/test-B01_SL_load_single_file.yml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workflow renamed.

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ analysis_db/support_files/
*.egg-info/
.installed.cfg
*.egg
/logs
localci-runner.sh
tests/test_tarballs.py

*__pycache__/
*__pycache__/*
Expand Down
127 changes: 9 additions & 118 deletions config/2021_IceSAT2_startup_local.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import os
#os.environ["DISPLAY"] = "localhost:10.0"
# 14, 16, work
#standart libraries:
import numpy as np
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pandas as pd
import sys

from matplotlib.gridspec import GridSpec
import string
from icesat2_tracks.local_modules import m_colormanager_ph3 as M_color

import xarray as xr
#xr.set_options(display_width=80, display_style='text')
xr.set_options(display_style='text')

import sys
import imp

import string

# my own libraries:
#import m_general as M

#import AA_plot_base as AA
def json_load(name, path, verbose=False):
import json
full_name= (os.path.join(path,name+ '.json'))
Expand All @@ -40,11 +24,10 @@ def json_load(name, path, verbose=False):
sys.path.append(mconfig['paths']['local_script'])
sys.path.append(mconfig['paths']['local_script'] +'/ICEsat2_SI_tools/')

import m_colormanager_ph3 as M_color
import m_tools_ph3 as MT
import m_general_ph3 as M


#load colorscheme
# The color method produces output to stdout; suppresed in the class def. CP
col=M_color.color(path=mconfig['paths']['analysis']+'../config/', name='color_def')


Expand All @@ -56,16 +39,7 @@ def json_load(name, path, verbose=False):
SMALL_SIZE = 8
MEDIUM_SIZE = 10
BIGGER_SIZE = 12
#csfont = {'fontname':'Comic Sans MS'}
legend_properties = {'weight':'bold'}
#font.family: sans-serif
#font.sans-serif: Helvetica Neue

#import matplotlib.font_manager as font_manager
#font_dirs = ['/home/mhell/HelveticaNeue/', ]
#font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
#font_list = font_manager.createFontList(font_files)
#font_manager.fontManager.ttflist.extend(font_list)

plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
#plt.rc('font', size=SMALL_SIZE, serif='DejaVu Sans', weight='light')
Expand All @@ -75,19 +49,11 @@ def json_load(name, path, verbose=False):
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE, frameon=False) # legend fontsize
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title

#figure.autolayout : False
#matplotlib.rcParams['pdf.fonttype'] = 42
#matplotlib.rcParams['ps.fonttype'] = 42

plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True)

plt.rc('path', simplify=True)

plt.rcParams['figure.figsize'] = (10, 8)#(20.0, 10.0) #inline
#plt.rcParams['pcolor.shading'] = 'auto'
#rcParams['pcolor.shading'] = 'auto'
#plt.rc('pcolor', shading = 'auto')

### TICKS
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
Expand Down Expand Up @@ -125,50 +91,13 @@ def json_load(name, path, verbose=False):
#ytick.minor.left : True # draw y axis left minor ticks
#ytick.minor.right : True # draw y axis right minor ticks


plt.rc('xtick.major', size= 4, width=1 )
plt.rc('ytick.major', size= 3.8, width=1 )

#axes.facecolor : white # axes background color
#axes.edgecolor : black # axes edge color
#axes.linewidth : 0.8 # edge linewidth
#axes.grid : False # display grid or not
#axes.titlesize : large # fontsize of the axes title
#axes.titlepad : 6.0 # pad between axes and title in points
#axes.labelsize : medium # fontsize of the x any y labels
#axes.labelpad : 4.0 # space between label and axis
#axes.labelweight : normal # weight of the x and y labels
#axes.labelcolor : black

plt.rc('axes', labelsize= MEDIUM_SIZE, labelweight='normal')




# axes.spines.left : True # display axis spines
# axes.spines.bottom : True
# axes.spines.top : True
# axes.spines.right : True
plt.rc('axes.spines', top= False, right=False )



def font_for_print():

SMALL_SIZE = 6
MEDIUM_SIZE = 8
BIGGER_SIZE = 10
#csfont = {'fontname':'Comic Sans MS'}
legend_properties = {'weight':'bold'}
#font.family: sans-serif
#font.sans-serif: Helvetica Neue

#import matplotlib.font_manager as font_manager
#font_dirs = ['/home/mhell/HelveticaNeue/', ]
#font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
#font_list = font_manager.createFontList(font_files)
#font_manager.fontManager.ttflist.extend(font_list)

def font_for_print(SMALL_SIZE = 6, MEDIUM_SIZE = 8, BIGGER_SIZE = 10):
plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
#plt.rc('font', size=SMALL_SIZE, serif='DejaVu Sans', weight='light')
plt.rc('text', usetex='false')
Expand All @@ -177,35 +106,11 @@ def font_for_print():
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE, frameon=False) # legend fontsize
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title

#figure.autolayout : False
#matplotlib.rcParams['pdf.fonttype'] = 42
#matplotlib.rcParams['ps.fonttype'] = 42


#plt.rc('xtick.major', size= 4, width=1 )
#plt.rc('ytick.major', size= 3.8, width=1 )

plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True)

plt.rc('axes', labelsize= SMALL_SIZE, labelweight='normal')

def font_for_pres():

SMALL_SIZE = 10
MEDIUM_SIZE = 12
BIGGER_SIZE = 14
#csfont = {'fontname':'Comic Sans MS'}
legend_properties = {'weight':'bold'}
#font.family: sans-serif
#font.sans-serif: Helvetica Neue

#import matplotlib.font_manager as font_manager
#font_dirs = ['/home/mhell/HelveticaNeue/', ]
#font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
#font_list = font_manager.createFontList(font_files)
#font_manager.fontManager.ttflist.extend(font_list)

def font_for_pres(SMALL_SIZE = 10, MEDIUM_SIZE = 12, BIGGER_SIZE = 14):
plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
#plt.rc('font', size=SMALL_SIZE, serif='DejaVu Sans', weight='light')
plt.rc('text', usetex='false')
Expand All @@ -214,20 +119,6 @@ def font_for_pres():
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE, frameon=False) # legend fontsize
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title

#figure.autolayout : False
#matplotlib.rcParams['pdf.fonttype'] = 42
#matplotlib.rcParams['ps.fonttype'] = 42


#plt.rc('xtick.major', size= 4, width=1 )
#plt.rc('ytick.major', size= 3.8, width=1 )

plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True)

plt.rc('axes', labelsize= SMALL_SIZE, labelweight='normal')



# add project depenent libraries
#sys.path.append(config['paths']['local_script'])
18 changes: 18 additions & 0 deletions hooks/pre-push
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to use this hook in your local development environment.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# Count the number of 'def test_' in test_steps.py
n=$(grep -c '^def test_' tests/test_steps.py)

# if n > $(nproc) then n = $(nproc)
if [ $n -gt $(nproc) ]; then
n=$(nproc)
fi

# Run your Python script
pytest -n $n tests/test_steps.py

# Check the exit status of the Python script
if [ $? -ne 0 ]; then
echo "Tests failed, aborting push."
exit 1
fi
6 changes: 5 additions & 1 deletion pyproject.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some curious highlighting happening here. Looks like a syntax error, but I can't see where it's coming from. Any ideas?
Screenshot 2024-01-22 at 08 40 05

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure as my linter is not reporting an issue for this file. I think I am using ruff.

Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ dependencies = [ # Optional
"emcee >=3.1.4, <4.0.0",
"netCDF4 >=1.6.5, <2.0.0",
"siphon >=0.9, <1.0.0",
"h5py >=3.5.0, < 4.0.0"
"h5py >=3.5.0, < 4.0.0",
"termcolor >=2.4.0, < 3.0.0",
"pytest >=7.4.4, < 8.0.0",
"pytest-xdist >=3.5.0, < 4.0.0",
"typer >=0.9.0, < 1.0.0",
]

# List additional groups of dependencies here (e.g. development
Expand Down
Loading
Loading