-
Notifications
You must be signed in to change notification settings - Fork 7
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
204 changed files
with
8,029 additions
and
1 deletion.
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,18 @@ | ||
_site/ | ||
.sass-cache/ | ||
.jekyll-metadata | ||
|
||
# Vim undo files. Python# | ||
# ####################### | ||
*.un~ | ||
*.pyc | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db |
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 |
---|---|---|
@@ -1 +1,21 @@ | ||
# 100-days-of-Python | ||
# I've joined the #100DaysOfCode Challenge. | ||
|
||
## [Лог моих занятий 100 days of Python](log.md) | ||
|
||
## Правила | ||
|
||
* Каждый день уделять изучению Python 1 час | ||
* Хотя бы половина времени должны тратиться на код | ||
* После каждой сессии коротко описать прогресс и что именно я делала в этот день | ||
* В репозитории каждый день должен быть хотя бы один коммит | ||
* Можно прогулять один день в неделю, но нельзя два дня подряд | ||
* Все прогулы не учитываются | ||
|
||
## Ссылки | ||
|
||
* [Twitter #100DaysOfX](https://twitter.com/hashtag/100DaysOfX?src=hash) | ||
* [Twitter #100DaysOfCode](https://twitter.com/hashtag/100DaysOfCode?src=hash) | ||
* [Первая статья "Join the #100DaysOfCode"](https://medium.freecodecamp.org/join-the-100daysofcode-556ddb4579e4) | ||
* [100DaysOfX Challenges](http://100daysofx.com/) | ||
* [100DaysOfCode Challenge](http://100daysofcode.com/) | ||
|
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,5 @@ | ||
## Links | ||
|
||
* [Python Testing with pytest: Simple, Rapid, Effective, and Scalable](https://pragprog.com/book/bopytest/python-testing-with-pytest) | ||
* [Code](https://pragprog.com/titles/bopytest/source_code) | ||
|
33 changes: 33 additions & 0 deletions
33
books-tutorials/pytest-book/code/appendices/outcomes/test_outcomes.py
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,33 @@ | ||
import pytest | ||
|
||
|
||
def test_pass(): | ||
assert 1 == 1 | ||
|
||
|
||
def test_fail(): | ||
assert 1 == 2 | ||
|
||
|
||
@pytest.mark.xfail() | ||
def test_xfail(): | ||
assert 1 == 2 | ||
|
||
|
||
@pytest.mark.xfail() | ||
def test_xpass(): | ||
assert 1 == 1 | ||
|
||
|
||
@pytest.mark.skip() | ||
def test_skip(): | ||
pass | ||
|
||
|
||
@pytest.fixture() | ||
def flaky_fixture(): | ||
assert 1 == 2 | ||
|
||
|
||
def test_error(flaky_fixture): | ||
pass |
6 changes: 6 additions & 0 deletions
6
books-tutorials/pytest-book/code/appendices/packaging/some_module_proj/setup.py
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,6 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='some_module', | ||
py_modules=['some_module'] | ||
) |
2 changes: 2 additions & 0 deletions
2
books-tutorials/pytest-book/code/appendices/packaging/some_module_proj/some_module.py
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,2 @@ | ||
def some_func(): | ||
return 42 |
7 changes: 7 additions & 0 deletions
7
books-tutorials/pytest-book/code/appendices/packaging/some_package_proj/setup.py
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,7 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='some_package', | ||
packages=find_packages(where='src'), | ||
package_dir={'': 'src'}, | ||
) |
1 change: 1 addition & 0 deletions
1
...ials/pytest-book/code/appendices/packaging/some_package_proj/src/some_package/__init__.py
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 @@ | ||
from some_package.some_module import * |
2 changes: 2 additions & 0 deletions
2
...s/pytest-book/code/appendices/packaging/some_package_proj/src/some_package/some_module.py
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,2 @@ | ||
def some_func(): | ||
return 42 |
12 changes: 12 additions & 0 deletions
12
...orials/pytest-book/code/appendices/packaging/some_package_proj_v2/CHANGELOG.rst
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,12 @@ | ||
Changelog | ||
========= | ||
|
||
------------------------------------------------------ | ||
|
||
1.0 | ||
--- | ||
|
||
Changes: | ||
~~~~~~~~ | ||
|
||
- Initial version. |
10 changes: 10 additions & 0 deletions
10
books-tutorials/pytest-book/code/appendices/packaging/some_package_proj_v2/LICENSE
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,10 @@ | ||
Copyright (c) 2017 The Pragmatic Programmers, LLC | ||
|
||
All rights reserved. | ||
|
||
Copyrights apply to this source code. | ||
|
||
You may use the source code in your own projects, however the source code | ||
may not be used to create commercial training material, courses, books, | ||
articles, and the like. We make no guarantees that this source code is fit | ||
for any purpose. |
14 changes: 14 additions & 0 deletions
14
books-tutorials/pytest-book/code/appendices/packaging/some_package_proj_v2/setup.py
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,14 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='some_package', | ||
description='Demonstrate packaging and distribution', | ||
|
||
version='1.0', | ||
author='Brian Okken', | ||
author_email='brian@pythontesting.net', | ||
url='https://pragprog.com/book/bopytest/python-testing-with-pytest', | ||
|
||
packages=find_packages(where='src'), | ||
package_dir={'': 'src'}, | ||
) |
1 change: 1 addition & 0 deletions
1
...s/pytest-book/code/appendices/packaging/some_package_proj_v2/src/some_package/__init__.py
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 @@ | ||
from some_package.some_module import * |
2 changes: 2 additions & 0 deletions
2
...ytest-book/code/appendices/packaging/some_package_proj_v2/src/some_package/some_module.py
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,2 @@ | ||
def some_func(): | ||
return 42 |
24 changes: 24 additions & 0 deletions
24
books-tutorials/pytest-book/code/appendices/xdist/test_not_parallel.py
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,24 @@ | ||
import pytest | ||
import time | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def some_resource(): | ||
x = [] | ||
return x | ||
|
||
|
||
def test_1(some_resource): | ||
time.sleep(1) | ||
|
||
|
||
def test_2(some_resource): | ||
time.sleep(1) | ||
|
||
|
||
def test_3(some_resource): | ||
time.sleep(1) | ||
|
||
|
||
def test_4(some_resource): | ||
time.sleep(1) |
7 changes: 7 additions & 0 deletions
7
books-tutorials/pytest-book/code/appendices/xdist/test_parallel.py
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,7 @@ | ||
import pytest | ||
import time | ||
|
||
|
||
@pytest.mark.parametrize('x', list(range(10))) | ||
def test_something(x): | ||
time.sleep(1) |
39 changes: 39 additions & 0 deletions
39
books-tutorials/pytest-book/code/appendices/xunit/test_mixed_fixtures.py
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 @@ | ||
import pytest | ||
|
||
|
||
def setup_module(): | ||
print('\nsetup_module() - xUnit') | ||
|
||
|
||
def teardown_module(): | ||
print('teardown_module() - xUnit') | ||
|
||
|
||
def setup_function(): | ||
print('setup_function() - xUnit') | ||
|
||
|
||
def teardown_function(): | ||
print('teardown_function() - xUnit\n') | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def module_fixture(): | ||
print('module_fixture() setup - pytest') | ||
yield | ||
print('module_fixture() teardown - pytest') | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def function_fixture(): | ||
print('function_fixture() setup - pytest') | ||
yield | ||
print('function_fixture() teardown - pytest') | ||
|
||
|
||
def test_1(module_fixture, function_fixture): | ||
print('test_1()') | ||
|
||
|
||
def test_2(module_fixture, function_fixture): | ||
print('test_2()') |
44 changes: 44 additions & 0 deletions
44
books-tutorials/pytest-book/code/appendices/xunit/test_xUnit_fixtures.py
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,44 @@ | ||
def setup_module(module): | ||
print(f'\nsetup_module() for {module.__name__}') | ||
|
||
|
||
def teardown_module(module): | ||
print(f'teardown_module() for {module.__name__}') | ||
|
||
|
||
def setup_function(function): | ||
print(f'setup_function() for {function.__name__}') | ||
|
||
|
||
def teardown_function(function): | ||
print(f'teardown_function() for {function.__name__}') | ||
|
||
|
||
def test_1(): | ||
print('test_1()') | ||
|
||
|
||
def test_2(): | ||
print('test_2()') | ||
|
||
|
||
class TestClass: | ||
@classmethod | ||
def setup_class(cls): | ||
print(f'setup_class() for class {cls.__name__}') | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
print(f'teardown_class() for {cls.__name__}') | ||
|
||
def setup_method(self, method): | ||
print(f'setup_method() for {method.__name__}') | ||
|
||
def teardown_method(self, method): | ||
print(f'teardown_method() for {method.__name__}') | ||
|
||
def test_3(self): | ||
print('test_3()') | ||
|
||
def test_4(self): | ||
print('test_4()') |
3 changes: 3 additions & 0 deletions
3
books-tutorials/pytest-book/code/ch1/.cache/v/cache/lastfailed
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,3 @@ | ||
{ | ||
"test_two.py::test_failing": true | ||
} |
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,26 @@ | ||
"""Test the Task data type.""" | ||
|
||
from collections import namedtuple | ||
|
||
|
||
Task = namedtuple('Task', ['summary', 'owner', 'done', 'id']) | ||
Task.__new__.__defaults__ = (None, None, False, None) | ||
|
||
|
||
def test_asdict(): | ||
"""_asdict() should return a dictionary.""" | ||
t_task = Task('do something', 'okken', True, 21) | ||
t_dict = t_task._asdict() | ||
expected = {'summary': 'do something', | ||
'owner': 'okken', | ||
'done': True, | ||
'id': 21} | ||
assert t_dict == expected | ||
|
||
|
||
def test_replace(): | ||
"""replace() should change passed in fields.""" | ||
t_before = Task('finish book', 'brian', False) | ||
t_after = t_before._replace(id=10, done=True) | ||
t_expected = Task('finish book', 'brian', True, 10) | ||
assert t_after == t_expected |
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,21 @@ | ||
"""Test the Task data type.""" | ||
|
||
from collections import namedtuple | ||
|
||
Task = namedtuple('Task', ['summary', 'owner', 'done', 'id']) | ||
Task.__new__.__defaults__ = (None, None, False, None) | ||
|
||
|
||
def test_defaults(): | ||
"""Using no parameters should invoke defaults.""" | ||
t1 = Task() | ||
t2 = Task(None, None, False, None) | ||
assert t1 == t2 | ||
|
||
|
||
def test_member_access(): | ||
"""Check .field functionality of namedtuple.""" | ||
t = Task('buy milk', 'brian') | ||
assert t.summary == 'buy milk' | ||
assert t.owner == 'brian' | ||
assert (t.done, t.id) == (False, None) |
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,2 @@ | ||
def test_passing(): | ||
assert (1, 2, 3) == (1, 2, 3) |
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,2 @@ | ||
def test_failing(): | ||
assert (1, 2, 3) == (3, 2, 1) |
50 changes: 50 additions & 0 deletions
50
books-tutorials/pytest-book/code/ch2/tasks_proj/CHANGELOG.rst
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,50 @@ | ||
Changelog | ||
========= | ||
|
||
----------------------------------------------------------------- | ||
|
||
0.1.0 (ch2/tasks_proj/tests) | ||
---------------------------- | ||
|
||
Changes to tests: | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
- added tests/unit/test_Task.py | ||
- a few tests to demonstrate running tests | ||
|
||
- added tests/unit/test_Task_fail.py | ||
- demonstrate test failure | ||
|
||
- added tests/func/test_api_exceptions.py | ||
- testing for expected exceptions | ||
|
||
- added tests/func/test_add.py | ||
- testing ``tasks.add()`` | ||
- demonstrate user defined markers | ||
|
||
- added tests/func/test_unique_id_1.py | ||
- initial tests for ``tasks.unique_id()``. | ||
|
||
- added tests/func/test_unique_id_2.py | ||
- demonstrate ``@pytest.mark.skip()``. | ||
|
||
- added tests/func/test_unique_id_3.py : | ||
- demonstrate ``@pytest.mark.skipif()``. | ||
|
||
- added tests/func/test_unique_id_4.py | ||
- demonstrate ``@pytest.mark.xfail()``. | ||
|
||
- added tests/func/test_add_variety.py | ||
- demonstrate ``@pytest.mark.parametrize`` on functions and classes. | ||
|
||
|
||
--------------------------------------------------- | ||
|
||
0.1.0 | ||
----- | ||
|
||
Changes: | ||
~~~~~~~~ | ||
|
||
- Initial version. | ||
|
10 changes: 10 additions & 0 deletions
10
books-tutorials/pytest-book/code/ch2/tasks_proj/tests/func/__init__.py
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,10 @@ | ||
""" | ||
Avoid test file name collision. | ||
__init__.py files in test directories allow | ||
test files in multiple directories to have the same | ||
name in the same session. | ||
See "Avoiding Filename Collisions" in Chapter 6 for | ||
more information. | ||
""" |
Oops, something went wrong.