Skip to content

Commit 44c3223

Browse files
committed
more reorg and exercises (writing guide)
1 parent 03d7d41 commit 44c3223

File tree

8 files changed

+70
-11
lines changed

8 files changed

+70
-11
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
python-version: [3.7, 3.8, 3.9]
9+
python-version: [3.7, 3.8]
1010

1111
steps:
1212
- name: Checkout repository

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sciware Testing Examples and Exercises
22

3-
[![](https://github.com/flatironinstitute/sciware-testing-python/actions/workflows/test.yml/badge.svg)](https://github.com/flatironinstitute/sciware-testing-python/actions/workflows/test.yml/)
3+
[![](https://github.com/flatironinstitute/sciware-testing-python/actions/workflows/test.yml/badge.svg)](https://github.com/flatironinstitute/sciware-testing-python/actions)
44

55
This is an example repository for writing tests, for the Sciware Testing session.
66
It demonstrates how to setup a repository to use GitHub actions to automatically run tests
@@ -41,10 +41,11 @@ pytest
4141
* **[`requirements.txt`](requirements.txt)** - File listing the packages required to run the code. It is included by setup.py.
4242
* **[`LICENSE`](LICENSE)** - File containing the text of the license the code is released under. Having a license file allows other people to use the code.
4343
* **[`sciware_testing_python/`](sciware_testing_python/)** - Directory for all the code.
44-
* **[`sciware_testing_python/__init.py__`** - File that python imports to define the `sciware_testing_python`](sciware_testing_python/__init.py__`** - File that python imports to define the `sciware_testing_python) package.
45-
* **[`sciware_testing_python/sciware_testing_python.py`](sciware_testing_python/sciware_testing_python.py)** - File with all of the code.
44+
* **[`sciware_testing_python/__init.py__`](sciware_testing_python/__init__.py)** - File that python imports to define the `sciware_testing_python package.
45+
* **[`sciware_testing_python/main.py`](sciware_testing_python/main.py)** - File with all of the code.
4646
* **[`tests/`** - Directory for the code which tests the code in `sciware_testing_python`](tests/`** - Directory for the code which tests the code in `sciware_testing_python).
47-
* **[`tests/test_sciware_testing_python.py`](tests/test_sciware_testing_python.py)** - File containing the tests.
47+
* **[`tests/test_1.py`](tests/test_1.py)** - File to fill in with some tests
48+
* **[`tests/test_examples.py`](tests/test_examples.py)** - File containing some tests
4849
* **[`.gitignore`](.gitignore)** - File which tells github what files to not track (optional)
4950
* **[`.github/workflows/`](.github/workflows/)** - Directory containing the configuration file for GitHub actions.
5051
* **[`.github/workflows/test.yml`](.github/workflows/test.yml)** - File detailing the system configurations to use for the tests.

sciware_testing_python/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
__email__ = '[email protected]'
77
__version__ = '0.1.0'
88

9-
from .sciware_testing_python import *
9+
from .main import *

sciware_testing_python/sciware_testing_python_sol.py renamed to sciware_testing_python/examples.py

+36
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,39 @@ def add_vectors(vector_1, vector_2):
130130
sum_vec.append(a + b)
131131

132132
return sum_vec
133+
134+
def count_ones(input_list):
135+
"""Example function. Counts the number of 1s in a list.
136+
137+
Parameters
138+
----------
139+
input_list : list
140+
List of values
141+
142+
Returns
143+
-------
144+
int
145+
Numbers of values that == 1
146+
147+
Notes
148+
-----
149+
This is NOT good Python, just an example function for tests.
150+
151+
Examples
152+
--------
153+
>>> count_ones([2,1,1,3,-1])
154+
2
155+
156+
Empty lists are returned as zero
157+
>>> count_ones([])
158+
0
159+
160+
"""
161+
162+
count = 0
163+
for n in input_list:
164+
if n == 1:
165+
count += 1
166+
167+
return count
168+

sciware_testing_python/sciware_testing_python.py renamed to sciware_testing_python/main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def sum_numbers(number_list):
1919
-----
2020
This is NOT good Python, just an example function for tests.
2121
22+
Example
23+
-------
24+
>>> 1
25+
1
2226
"""
2327

2428
sum_val = 0
@@ -52,6 +56,6 @@ def add_vectors(vector_1, vector_2):
5256
sum_vec = []
5357

5458
for a, b in zip(vector_1, vector_2):
55-
sum_vec.append(a + b)
59+
sum_vec.append(a * b)
5660

5761
return sum_vec

tests/test_sciware_testing_python.py renamed to tests/test_examples.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
def test_sum_numbers():
1010
"""Sample test function for sum_numbers."""
1111

12+
assert 0 == stp.sum_numbers([])
13+
1214
number_list = [2, 3, 4]
1315
our_result = stp.sum_numbers(number_list)
1416
assert our_result == sum(number_list)
1517

1618

1719
def test_adding_vectors():
18-
v1 = [2, 3, 4]
19-
v2 = [4, 9, 16]
20-
assert stp.add_vectors(v1, v2) == [6, 12, 20]
20+
v1 = [2, 0]
21+
v2 = [2, 0]
22+
assert stp.add_vectors(v1, v2) == [4, 0]
2123

2224

2325
def test_add_zero_length_vectors():
@@ -82,7 +84,7 @@ def test_parametrize_sum_numbers(number_list, expect_val):
8284
assert stp.sum_numbers(number_list) == expect_val
8385

8486

85-
@pytest.mark.xfail(strict=True)
87+
@pytest.mark.xfail
8688
def test_add_different_length_vectors():
8789
"""
8890
"""

tests/test_exercise.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
import sciware_testing_python
3+
4+
def test_sum1():
5+
# basic sanity test: do we get the right answer for a simple case?
6+
assert True
7+
8+
def test_sum2():
9+
# what's the sum of an empty list
10+
pass

tests/test_tdd.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
import sciware_testing_python
3+
4+
@pytest.mark.skip(reason="not yet implemented")
5+
def test_count_ones():
6+
assert sciware_testing_python.count_ones([2,1,1,3,-1] == 2)

0 commit comments

Comments
 (0)