-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Test CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
# Run every Monday at 8am to check latest versions of dependencies | ||
- cron: "0 8 * * WED" | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=edge,branch=main | ||
type=ref,event=branch | ||
type=semver,pattern={{version}} | ||
type=sha,prefix= | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
push: false | ||
tags: test | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Test | ||
run: | | ||
docker exec test bash -c "pytest" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pymca_zocalo.internals import find_cut_off_energy | ||
import tempfile | ||
from pytest import raises | ||
from unittest.mock import patch, mock_open | ||
|
||
|
||
@patch("pymca_zocalo.internals.open") | ||
def test_GIVEN_input_file_not_found_WHEN_find_cut_off_energy_called_THEN_raises_exception(mock_open): | ||
mock_open.side_effect = FileNotFoundError() | ||
with raises(FileNotFoundError): | ||
find_cut_off_energy("test_file_name", 0) | ||
|
||
|
||
@patch("pymca_zocalo.internals.open", new_callable=mock_open, read_data="1 0") | ||
def test_GIVEN_energy_of_1_and_cutoff_of_0_WHEN_find_cut_off_energy_called_THEN_returns_1(mock_file): | ||
line_of_greater_energy = find_cut_off_energy("test_file_name", 0) | ||
assert line_of_greater_energy == 0 | ||
|
||
@patch("pymca_zocalo.internals.open") | ||
def test_different_energies(mock_file): | ||
test_data = "0 1\n5 10\n" | ||
mock_open(mock_file, read_data=test_data) | ||
line_of_greater_energy = find_cut_off_energy("test_file_name", 2) | ||
assert line_of_greater_energy == 1 | ||
|
||
|
||
@patch("pymca_zocalo.internals.open") | ||
def test_file_has_non_floats_different_energies(mock_file): | ||
test_data = "hyadasd 1\n5 10\n" | ||
mock_open(mock_file, read_data=test_data) | ||
line_of_greater_energy = find_cut_off_energy("test_file_name", 2) | ||
assert line_of_greater_energy == 1 | ||
|
||
@patch("pymca_zocalo.internals.open") | ||
def test_file_nothing_in_then_gives_none(mock_file): | ||
test_data = "" | ||
mock_open(mock_file, read_data=test_data) | ||
line_of_greater_energy = find_cut_off_energy("test_file_name", 2) | ||
assert line_of_greater_energy == None |