Skip to content

Bugfixes and simplifications #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# adapted from https://github.com/peaceiris/actions-gh-pages/blob/master/README.md#%EF%B8%8F-static-site-generators-with-nodejs and https://github.com/appleboy/scp-action/blob/master/README.md#example

name: build and deploy the site

on:
push:

jobs:
build-deploy:
runs-on: ubuntu-18.04
steps:
- name: Checkout repo
uses: actions/checkout@v1
with:
submodules: true

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: 'x64'

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r ./requirements.txt

- name: Build docs
run: mkdocs build

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ out.tmp
test/.pytest_cache/*
__pycache__/*
.coverage
htmlcov
_site
65 changes: 2 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,6 @@

This tutorial helps you to learn automated testing in Python 3 using the `pytest` framework.

![Moby Dick](images/mobydick.png)
## Credits

## Goal: Count Words in Moby Dick

*Captain Ahab was vicious because Moby Dick, the white whale, had bitten off his leg. So the captain set sail for a hunt. For months he was searching the sea for the white whale. The captain finally attacked the whale with a harpoon. Unimpressed, the whale devoured captain, crew and ship. The whale won.*

![tick marks while counting words](../images/counting470.png "Counting words")

Herman Melville's book *“Moby Dick”* describes the epic fight between the captain of a whaling ship and a whale. In the book, the whale wins by eating most of the other characters. **But does he also win by being mentioned more often?**

**In this course, you will test a program that is counting words in Melville's book.**


## Preparations

clone the repository:

:::bash
git clone https://github.com/krother/python_testing_tutorial.git

install **pytest**:

:::bash
pip install pytest

## Chapters

* [Unit Tests](articles/unit_tests.md)
* [Fixtures](articles/fixtures.md)
* [Parameterized Tests](articles/parameterized.md)
* [Organizing Tests](articles/organizing_tests.md)
* [Test Coverage](articles/test_coverage.md)
* [Recap Puzzle](articles/find_pairs.md)

## Appendix

* [Quotes on Testing](articles/quotes.md)
* [Instructions for Trainers](articles/instructions_for_trainers.md)

## Links

* [Python Testing Tutorial](https://katyhuff.github.io/python-testing/) - by Kathryn Huff
* [Introduction to pytest](https://www.youtube.com/watch?v=UPanUFVFfzY) - by Michael Tom-Wing and Christie Wilson
* [Test & Code Podcast](http://testandcode.com/) - by Brian Okken
* [The Clean Code Talks – Unit Testing](http://www.youtube.com/watch?v=wEhu57pih5w&feature=channel)
* [Test-Driven-Development](https://www.youtube.com/watch?v=L4hOiGOKSxQ) - by H.Percival


## Sources

Sources for this tutorial: [github.com/krother/python_testing_tutorial](https://github.com/krother/python_testing_tutorial).

## Copyright

Feedback and comments are welcome at: [krother@academis.eu](mailto:krother@academis.eu)

© 2018 Magdalena & Kristian Rother

Released under the conditions of a Creative Commons
Attribution License 4.0.

## Contributors

Kristian Rother, Magdalena Rother, Daniel Szoska
Adopted from [github.com/krother/python_testing_tutorial](https://github.com/krother/python_testing_tutorial).
60 changes: 60 additions & 0 deletions articles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Python Testing Tutorial

This tutorial helps you to learn automated testing in Python 3 using the `pytest` framework.

![Moby Dick](./images/mobydick.png)

## Goal: Count Words in Moby Dick

*Captain Ahab was vicious because Moby Dick, the white whale, had bitten off his leg. So the captain set sail for a hunt. For months he was searching the sea for the white whale. The captain finally attacked the whale with a harpoon. Unimpressed, the whale devoured captain, crew and ship. The whale won.*

![tick marks while counting words](images/counting470.png "Counting words")

Herman Melville's book *“Moby Dick”* describes the epic fight between the captain of a whaling ship and a whale. In the book, the whale wins by eating most of the other characters. **But does he also win by being mentioned more often?**

**In this course, you will test a program that is counting words in Melville's book.**


## Preparations

clone the repository:

```shell
git clone https://github.com/bonartm/python_testing_tutorial.git
```

install **pytest**:

```shell
pip install pytest
```

## Getting Started

Start with the first exercises in the chapter [Unit Tests](unit_tests.md)!

## Links

* [Python Testing Tutorial](https://katyhuff.github.io/python-testing/) - by Kathryn Huff
* [Introduction to pytest](https://www.youtube.com/watch?v=UPanUFVFfzY) - by Michael Tom-Wing and Christie Wilson
* [Test & Code Podcast](http://testandcode.com/) - by Brian Okken
* [The Clean Code Talks – Unit Testing](http://www.youtube.com/watch?v=wEhu57pih5w&feature=channel)
* [Test-Driven-Development](https://www.youtube.com/watch?v=L4hOiGOKSxQ) - by H.Percival


## Sources

Sources for this tutorial: [github.com/krother/python_testing_tutorial](https://github.com/krother/python_testing_tutorial).

## Copyright

Feedback and comments are welcome at: [krother@academis.eu](mailto:krother@academis.eu)

© 2018 Magdalena & Kristian Rother

Released under the conditions of a Creative Commons
Attribution License 4.0.

## Contributors

Kristian Rother, Magdalena Rother, Daniel Szoska, Malte Bonart
53 changes: 0 additions & 53 deletions articles/challenges.md

This file was deleted.

2 changes: 1 addition & 1 deletion articles/find_pairs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

**Match the test strategies with the correct descriptions.**

![recap puzzle](../images/recap_puzzle.svg)
![recap puzzle](./images/recap_puzzle.svg)

This exercise works best on the board or on paper.
29 changes: 16 additions & 13 deletions articles/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ There, add a function that loads the file `data/mobydick_summary.txt`:

Place the decorator `@pytest.fixture` on top of it:

:::python3
import pytest
```python
import pytest

@pytest.fixture
def text_summary():
return open(...).read()
@pytest.fixture
def text_summary():
return open(...).read()
```

----

### Exercise 2: Using the fixture

Now create a module `test_corpus.py` with a function that uses the fixture:

:::python3
def test_short_sample(text_summary):
assert count_words(text_summary) == 77
```python
def test_short_sample(text_summary):
assert count_words(text_summary) == 77
```

Execute the module with `pytest`. Note that you **do not** need to import `conftest`. Pytest does that automatically.

Expand All @@ -44,11 +46,12 @@ Create a fixture for the full text of the book `mobydick_full.txt` as well.

Create a fixture in `conftest.py` that prepares a dictionary with word counts using the `word_counter.count_words_dict()` function.

:::python3
from word_counter import count_words_dict
```python
from word_counter import count_words_dict

@pytest.fixture
def count_dict(text_summary):
return ...
@pytest.fixture
def count_dict(text_summary):
return ...
```

Write a simple test that makes sure the dictionary is not empty.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
56 changes: 0 additions & 56 deletions articles/instructions_for_trainers.md

This file was deleted.

8 changes: 0 additions & 8 deletions articles/mock_objects.md

This file was deleted.

20 changes: 0 additions & 20 deletions articles/multiple_packages.md

This file was deleted.

Loading