Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
natenka committed Jan 4, 2018
1 parent 0257040 commit 3bbf912
Show file tree
Hide file tree
Showing 204 changed files with 8,029 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .gitignore
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
22 changes: 21 additions & 1 deletion README.md
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/)

5 changes: 5 additions & 0 deletions books-tutorials/pytest-book/README.md
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)

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
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']
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def some_func():
return 42
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'},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from some_package.some_module import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def some_func():
return 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Changelog
=========

------------------------------------------------------

1.0
---

Changes:
~~~~~~~~

- Initial version.
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.
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'},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from some_package.some_module import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def some_func():
return 42
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)
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)
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()')
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()')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_two.py::test_failing": true
}
26 changes: 26 additions & 0 deletions books-tutorials/pytest-book/code/ch1/tasks/test_four.py
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
21 changes: 21 additions & 0 deletions books-tutorials/pytest-book/code/ch1/tasks/test_three.py
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)
2 changes: 2 additions & 0 deletions books-tutorials/pytest-book/code/ch1/test_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
2 changes: 2 additions & 0 deletions books-tutorials/pytest-book/code/ch1/test_two.py
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 books-tutorials/pytest-book/code/ch2/tasks_proj/CHANGELOG.rst
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.

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.
"""
Loading

0 comments on commit 3bbf912

Please sign in to comment.