Skip to content

Commit 03d7d41

Browse files
committed
more packaging/readme cleanups, test simplification
1 parent 1b29e66 commit 03d7d41

File tree

5 files changed

+45
-69
lines changed

5 files changed

+45
-69
lines changed

README.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,43 @@ on the code.
88

99
## Quick-start
1010

11-
### Test
11+
### Prerequisites
12+
13+
python3 with pip3 (at le
14+
15+
### Install
1216

1317
```bash
1418
git clone https://github.com/flatironinstitute/sciware-testing-python.git
1519
cd sciware-testing-python
16-
python3 ./setup.py pytest
20+
pip3 install -e .
21+
```
22+
23+
This will work with a virtualenv, conda, or on a personal machine.
24+
With a system python, you may need `pip3 install --user -e .`.
25+
This will also install dependencies (like `pytest`) specified in [`requirements.txt`](requirements.txt).
26+
27+
The `-e` indicates that we want to continue developing (editing) the installed package.
28+
29+
### Run tests
30+
31+
```bash
32+
pytest
1733
```
1834

1935
## Forking This Project
2036

2137
## Contents
2238

23-
* **`README.md`** - File generating this page.
24-
* **`setup.py`** - File describing the metadata for the package and rules to build/install/test it.
25-
* **`requirements.txt`** - File listing the packages required to run the code. It is included by setup.py.
26-
* **`LICENSE`** - File containing the text of the license the code is released under. Having a license file allows other people to use the code.
27-
* **`sciware_testing_python/`** - Directory for all the code.
28-
* **`sciware_testing_python/__init.py__`** - File that python imports to define the `sciware_testing_python` package.
29-
* **`sciware_testing_python/sciware_testing_python.py`** - File with all of the code.
30-
* **`tests/`** - Directory for the code which tests the code in `sciware_testing_python`.
31-
* **`tests/test_sciware_testing_python.py`** - File containing the tests.
32-
* **`.gitignore`** - File which tells github what files to not track (optional)
33-
* **`.github/workflows/`** - Directory containing the configuration file for GitHub actions.
34-
* **`.github/workflows/test.yml`** - File detailing the system configurations to use for the tests.
39+
* **[`README.md`](README.md)** - File generating this page.
40+
* **[`setup.py`](setup.py)** - File describing the metadata for the package and rules to build/install/test it.
41+
* **[`requirements.txt`](requirements.txt)** - File listing the packages required to run the code. It is included by setup.py.
42+
* **[`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.
43+
* **[`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.
46+
* **[`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.
48+
* **[`.gitignore`](.gitignore)** - File which tells github what files to not track (optional)
49+
* **[`.github/workflows/`](.github/workflows/)** - Directory containing the configuration file for GitHub actions.
50+
* **[`.github/workflows/test.yml`](.github/workflows/test.yml)** - File detailing the system configurations to use for the tests.

sciware_testing_python/sciware_testing_python.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ def add_vectors(vector_1, vector_2):
5252
sum_vec = []
5353

5454
for a, b in zip(vector_1, vector_2):
55-
sum_vec += [a + b]
55+
sum_vec.append(a + b)
5656

5757
return sum_vec

sciware_testing_python/sciware_testing_python_sol.py

+6-37
Original file line numberDiff line numberDiff line change
@@ -117,47 +117,16 @@ def add_vectors(vector_1, vector_2):
117117
ValueError: add_vectors can only sum vectors that are lists.
118118
119119
"""
120-
sum_vec = []
121-
if len(vector_1) != len(vector_2):
122-
raise RuntimeError(
123-
'add_vectors can only add vectors of the same length.')
124-
125120
if not isinstance(vector_1, list) or not isinstance(vector_2, list):
126121
raise ValueError(
127122
'add_vectors can only sum vectors that are lists.')
128123

124+
if len(vector_1) != len(vector_2):
125+
raise RuntimeError(
126+
'add_vectors can only add vectors of the same length.')
127+
128+
sum_vec = []
129129
for a, b in zip(vector_1, vector_2):
130-
sum_vec += [a + b]
130+
sum_vec.append(a + b)
131131

132132
return sum_vec
133-
134-
135-
# std::vector<double> add_vectors(std::vector<double> &v1, std::vector<double> &v2)
136-
# {
137-
# // Check inputs
138-
# if (v1.size() != v2.size())
139-
# {
140-
# throw std::invalid_argument("There's a mismatch in vector size" + std::to_string(v1.size()) + "!=" + std::to_string(v2.size()));
141-
# }
142-
143-
# //
144-
# // Solution 1
145-
# //
146-
147-
# // Add the vectors
148-
# std::vector<double> new_vector(v1.size());
149-
150-
# for (size_t i = 0; i < v1.size(); i++)
151-
# {
152-
# new_vector[i] = v1[i] + v2[i];
153-
# }
154-
155-
# //
156-
# // Solution 2
157-
# //
158-
159-
# // std::vector<double> new_vector = v1;
160-
# // std::transform(new_vector.begin(), new_vector.end(), v2.begin(), new_vector.begin(), std::plus<double>());
161-
162-
# return new_vector;
163-
# }

setup.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
from setuptools import find_packages, setup
77

8+
# load README.md contents to use as long_description
89
with open('README.md') as readme_file:
910
readme = readme_file.read()
1011

12+
# load requirements.txt to use as install_requires
1113
with open('requirements.txt', 'r') as f:
1214
requirements = [l for l in f if l.strip() and not l.startswith('#')]
1315

@@ -20,21 +22,18 @@
2022
version='0.1.0',
2123
long_description=readme,
2224
license="Apache Software License 2.0",
25+
# some (optional) tags
2326
classifiers=[
2427
'Development Status :: 2 - Pre-Alpha',
2528
'Intended Audience :: Developers',
2629
'License :: OSI Approved :: Apache Software License',
2730
'Natural Language :: English',
2831
'Programming Language :: Python :: 3',
32+
'Programming Language :: Python :: 3.6',
2933
'Programming Language :: Python :: 3.7',
3034
'Programming Language :: Python :: 3.8',
3135
'Programming Language :: Python :: 3.9',
3236
],
3337
install_requires=requirements,
34-
packages=find_packages(
35-
include=[
36-
'sciware_testing_python',
37-
'sciware_testing_python_sol']),
38-
test_suite='tests',
39-
setup_requires=['pytest-runner'],
38+
packages=find_packages()
4039
)

tests/test_sciware_testing_python.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
"""Tests for `sciware_testing_python` package."""
33

44
import random
5-
65
import pytest
7-
86
import sciware_testing_python as stp
9-
# import sciware_testing_python_sol as stps
107

118

129
def test_sum_numbers():
@@ -50,11 +47,6 @@ def generate_numbers():
5047

5148
return random.sample(range(100), 10)
5249

53-
54-
# shortcuts for pytest decorators
55-
skip = pytest.mark.skip
56-
parametrize = pytest.mark.parametrize
57-
xfail = pytest.mark.xfail
5850
#######################################################################
5951

6052

@@ -73,7 +65,7 @@ def test_random_sum_numbers_add_1(generate_numbers):
7365
assert our_result == sum(generate_numbers) + 1
7466

7567

76-
@xfail
68+
@pytest.mark.xfail
7769
def test_sum_numbers_with_bad_args():
7870
""" Test sum numbers when not given good input
7971
"""
@@ -90,7 +82,7 @@ def test_parametrize_sum_numbers(number_list, expect_val):
9082
assert stp.sum_numbers(number_list) == expect_val
9183

9284

93-
@xfail(strict=True)
85+
@pytest.mark.xfail(strict=True)
9486
def test_add_different_length_vectors():
9587
"""
9688
"""
@@ -99,7 +91,7 @@ def test_add_different_length_vectors():
9991
result = stp.add_vectors(v1, v2) # doctest: +IGNORE_EXCEPTION_DETAIL
10092

10193

102-
@skip
94+
@pytest.mark.skip
10395
def test_add_skip_test():
10496
""" This test would fail if not for the decorator
10597
"""

0 commit comments

Comments
 (0)