From 6b6f1344e9d29d0b3d766bfff829b9de77b92634 Mon Sep 17 00:00:00 2001 From: ryansurf Date: Sat, 25 May 2024 14:19:59 -0700 Subject: [PATCH] github actions pytest --- .github/workflows/pytest.yml | 24 ++++++++++++++++++++++++ src/tests/test_code.py | 33 ++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..7bc30ed --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,24 @@ +name: Pytest + +on: [push, pull-request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest + - name: Test with pytest + run: | + cd src/tests + pytest \ No newline at end of file diff --git a/src/tests/test_code.py b/src/tests/test_code.py index ef4934c..20b32dc 100644 --- a/src/tests/test_code.py +++ b/src/tests/test_code.py @@ -22,33 +22,36 @@ def test_invalid_input(): - with patch("sys.stdout", new=io.StringIO()) as fake_stdout: - extract_decimal(["decimal=NotADecimal"]) - printed_output = fake_stdout.getvalue().strip() - assert( - printed_output == "Invalid value for decimal. Please provide an integer." - ) + with patch("sys.stdout", new=io.StringIO()) as fake_stdout: + extract_decimal(["decimal=NotADecimal"]) + printed_output = fake_stdout.getvalue().strip() + assert printed_output == "Invalid value for decimal. Please provide an integer." + def test_default_input(): - decimal = extract_decimal([]) - assert 1 == decimal + decimal = extract_decimal([]) + assert 1 == decimal + def test_get_coordinates(): coordinates = get_coordinates(["loc=santa_cruz"]) lat = coordinates[0] long = coordinates[1] - assert(isinstance(lat, (int, float))) - assert(isinstance(long, (int, float))) + assert isinstance(lat, (int, float)) + assert isinstance(long, (int, float)) + def test_get_uv(): uv = get_uv(37, 122, 2) - assert(isinstance(uv, (int, float))) + assert isinstance(uv, (int, float)) + def test_ocean_information(): ocean = ocean_information(37, 122, 2) - assert(isinstance(ocean[0], (int, float))) - assert(isinstance(ocean[1], (int, float))) - assert(isinstance(ocean[2], (int, float))) + assert isinstance(ocean[0], (int, float)) + assert isinstance(ocean[1], (int, float)) + assert isinstance(ocean[2], (int, float)) + def test_main(): """ @@ -57,4 +60,4 @@ def test_main(): """ data_dict = main() time.sleep(5) - assert(len(data_dict) >= 5) \ No newline at end of file + assert len(data_dict) >= 5