Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhang committed Oct 6, 2024
1 parent 5aafca0 commit b87305d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
22 changes: 14 additions & 8 deletions .github/actions/build-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,38 @@ runs:
using: "composite"
steps:
- name: Install dependency
shell: bash
run: |
sudo apt-get install -y pandoc jq
pip install --user sphinx==7.* pydata-sphinx-theme==0.15.* pandoc nbsphinx \
Pygments==2.16.* sphinx-autodoc-typehints myst-parser \
markupsafe==2.1.* sphinx-plotly-directive
- name: Build doc
shell: bash
run: sphinx-build ${GITHUB_WORKSPACE}/docs _build/html

- name: Get SnapATAC2 version
id: get_version
shell: bash
run: |
VERSION_NUMBER=$(python -c "import snapatac2;print('.'.join(snapatac2.__version__.split('.')[:2]))")
echo $VERSION_NUMBER
echo "VERSION=$VERSION_NUMBER" >> $GITHUB_ENV
IS_DEV=$(python -c "import snapatac2;print('dev' in snapatac2.__version__)")
echo $IS_DEV
BRANCH_NAME=${{ github.event.workflow_run.head_branch }}
if [[ $IS_DEV == "True" && $BRANCH_NAME == "main" ]]; then
echo "DEPLOY_DEV=true" >> $GITHUB_ENV
elif [[ $BRANCH_NAME =~ ^v[0-9]+ || $BRANCH_NAME == "main" ]]; then
echo "DEPLOY_VERSION=true" >> $GITHUB_ENV
if [[ $IS_DEV == "True" ]]; then
echo "DEPLOYMENT=dev" >> $GITHUB_ENV
else
echo "DEPLOYMENT=stable" >> $GITHUB_ENV
fi
echo "============================== Info ================================"
echo "DEPLOYMENT=${{ env.DEPLOYMENT }}"
echo "VERSION=${{ env.VERSION }}"
echo "===================================================================="
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
if: ${{ env.DEPLOY_DEV == 'true' }}
if: ${{ env.DEPLOYMENT == 'dev' }}
with:
single-commit: true
branch: gh-pages
Expand All @@ -46,7 +51,7 @@ runs:

- name: Deploy (version) 🚀
uses: JamesIves/github-pages-deploy-action@v4
if: ${{ env.DEPLOY_VERSION == 'true' }}
if: ${{ env.DEPLOYMENT == 'stable' }}
with:
single-commit: true
branch: gh-pages
Expand All @@ -55,6 +60,7 @@ runs:
target-folder: /version/${{ env.VERSION }}/

- name: Fetch JSON and Get Preferred Version
shell: bash
run: |
#JSON=$(cat ${GITHUB_WORKSPACE}/docs/_static/versions.json)
JSON=$(curl -s "https://raw.githubusercontent.com/kaizhang/SnapATAC2/main/docs/_static/versions.json")
Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ jobs:
- name: Install dependencies
run: |
pip install --user --upgrade pip
pip install --user coverage pytest hypothesis==6.72.4 wheel
pip install --user pytest hypothesis==6.72.4 wheel
- name: Build wheel files
- name: Build Python package
run: |
cd ${GITHUB_WORKSPACE}/snapatac2-python
mkdir ${GITHUB_WORKSPACE}/wheel_files
pip wheel . --wheel-dir ${GITHUB_WORKSPACE}/wheel_files
- name: Test Python package
run: |
pip install --user ${GITHUB_WORKSPACE}/wheel_files/*.whl
coverage run -m pytest ${GITHUB_WORKSPACE}/snapatac2-python/tests
pip install --user .
pytest tests
- uses: ./.github/actions/build-docs

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

build-wheel:
needs: build-and-test
Expand Down
2 changes: 0 additions & 2 deletions codecov.yml

This file was deleted.

20 changes: 20 additions & 0 deletions snapatac2-python/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,23 @@ def test_import(datadir):
outputs = snap.ex.export_fragments(data, groupby="group", out_dir=str(datadir), suffix='.bed.gz')

assert read_bed(list(outputs.values())[0]) == read_bed(fl)

def test_tile_matrix(datadir):
def total_count(adata, bin_size):
return snap.pp.add_tile_matrix(
adata,
bin_size=bin_size,
inplace=False,
counting_strategy='insertion',
).X.sum()

data = snap.pp.import_data(
snap.datasets.pbmc500(downsample=True),
chrom_sizes=snap.genome.hg38,
min_num_fragments=0,
sorted_by_barcode=False,
)

counts = [total_count(data, i) for i in [500, 1000, 5000, 10000]]
for i in range(1, len(counts)):
assert counts[i] == counts[i - 1], f"Bin size {i} failed"

0 comments on commit b87305d

Please sign in to comment.