-
Notifications
You must be signed in to change notification settings - Fork 12
add tests and CI #4
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
Open
fattybobcat
wants to merge
9
commits into
python-testing-sandbox:main
Choose a base branch
from
fattybobcat:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d8d1e33
add test coverage 100%
1e9fac6
add travis.yml
ee3cd50
add travis.yml
9215a10
Update README.md
fattybobcat 18fe7b3
Update README.md
fattybobcat d755478
try add 1% test
2fa3d08
Merge remote-tracking branch 'origin/main' into main
7eb1e9d
ignore pragma
4eb36b3
add test after review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,11 @@ | ||
language: python | ||
python: | ||
- "3.9" | ||
install: | ||
- pip install -r requirements.txt | ||
script: | ||
- flake8 . | ||
- pytest --cov=code tests/ | ||
- coverage run -m --branch pytest | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,2 +1,7 @@ | ||
Pillow==8.1.2 | ||
requests==2.25.1 | ||
flake8==3.9.2 | ||
pytest==6.2.4 | ||
pytest-cov==2.12.0 | ||
pytest-mock==3.6.1 | ||
requests-mock==1.9.2 |
This file contains hidden or 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 @@ | ||
[flake8] | ||
max-line-length = 120 |
Empty file.
This file contains hidden or 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,15 @@ | ||
import pytest | ||
from PIL import Image | ||
|
||
|
||
SIZE_IMAGE = 100 | ||
|
||
|
||
class MyTestClass: | ||
pass | ||
|
||
|
||
@pytest.fixture() | ||
def create_image(): | ||
image = Image.new('RGBA', size=(SIZE_IMAGE, SIZE_IMAGE)) | ||
return image |
This file contains hidden or 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,180 @@ | ||
import pytest | ||
import ast | ||
import datetime | ||
|
||
from code import (flat, is_python_class_name, parse_iso_datetime, chunks, | ||
is_camel_case_word, if_logs_has_any_of_commands, is_path_in_exclude_list, | ||
get_full_class_name, max_with_default, split_camel_case_words, extract_all_constants_from_ast, | ||
has_recursive_calls, get_image_height_in_pixels) | ||
from .conftest import MyTestClass | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_list, expected', | ||
[ | ||
([['People'], ['Name', 'Job']], ['People', 'Name', 'Job']), | ||
([[], [1, 'a']], [1, 'a']), | ||
([[], {}], []), | ||
([{}, [1, 2, {'a': 4}]], [1, 2, {'a': 4}]) | ||
], | ||
) | ||
def test_flat(some_list, expected): | ||
assert flat(some_list) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_name, expected', | ||
[ | ||
('User', True), | ||
('name', False), | ||
('userName', False) | ||
], | ||
) | ||
def test_is_python_class_name(some_name, expected): | ||
assert is_python_class_name(some_name) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'iso_datetime, expected', | ||
[ | ||
('2008-09-03T20:56:35.450686Z', datetime.datetime(2008, 9, 3, 20, 56, 35, 450686)), | ||
('name', None), | ||
('2018-11-11', datetime.datetime(2018, 11, 11, 0, 0)), | ||
('2010-09-03T20:56:35.45', None), | ||
], | ||
) | ||
def test_parse_iso_datetime(iso_datetime, expected): | ||
assert parse_iso_datetime(iso_datetime) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_list, chunk_size, expected', | ||
[ | ||
([1, 2, 3, 4, 5, 6, 7, 8, 9], 4, [[1, 2, 3, 4], [5, 6, 7, 8], [9]]), | ||
([1, 2, 3, 4, 5], 3, [[1, 2, 3], [4, 5]]), | ||
([], 3, []), | ||
] | ||
|
||
) | ||
def test_chunks(some_list, chunk_size, expected): | ||
assert list(chunks(some_list, chunk_size)) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'log, some_commands, expected', | ||
[ | ||
(['update photo', 'delete'], ['update', 'read', 'exit'], True), | ||
(['user post new recipes', 'user read url'], ['update', 'read', 'exit'], True), | ||
(['delete', 'send'], ['update'], False), | ||
([], ['read'], False), | ||
(['start'], ['start'], True) | ||
], | ||
) | ||
def test_if_logs_has_any_of_commands(log, some_commands, expected): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно проверить 3-е условие - base_command == required_command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это чтобы полностью повторялась base_command в required_command? |
||
assert if_logs_has_any_of_commands(log, some_commands) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_word, expected', | ||
[ | ||
('CamelCaps', True), | ||
('camelcaps', False), | ||
('CamelHumpedWord', True), | ||
('Ca', False), | ||
('cA', True), | ||
('', False), | ||
], | ||
) | ||
def test_is_camel_case_word(some_word, expected): | ||
assert is_camel_case_word(some_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_path, exclude, expected', | ||
[ | ||
('some_path', ['some', 'path'], True), | ||
('some path', ['path'], True), | ||
('some path', [''], True), | ||
('some path', [], False), | ||
('', [], False), | ||
('', [''], True), | ||
] | ||
) | ||
def test_is_path_in_exclude_list(some_path, exclude, expected): | ||
assert is_path_in_exclude_list(some_path, exclude) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_obj, expected', | ||
[ | ||
(4.3, 'float'), | ||
('text', 'str'), | ||
([2], 'list'), | ||
(MyTestClass(), 'tests.conftest.MyTestClass'), | ||
] | ||
) | ||
def test_get_full_class_name(some_obj, expected): | ||
assert get_full_class_name(some_obj) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_items, default, expected', | ||
[ | ||
([1, -2, 3], 1, 3), | ||
('', None, 0), | ||
([], 15, 15), | ||
('AaBbCcXxYyZz', None, 'z'), | ||
] | ||
) | ||
def test_max_with_default(some_items, default, expected): | ||
assert max_with_default(some_items, default) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'camel_cased_word, expected', | ||
[ | ||
('SomeCamelCasedWord', ['some', 'camel', 'cased', 'word']), | ||
(' CamelCasedWord', [' ', 'camel', 'cased', 'word']), | ||
('CamelCasedsoMeWorD', ['camel', 'casedso', 'me', 'wor', 'd']), | ||
('aCa', ['a', 'ca']), | ||
(" Camel Case WordCase case wordCase", [' ', 'camel ', 'case ', 'word', 'case case word', 'case']) | ||
] | ||
) | ||
def test_split_camel_case_words(camel_cased_word, expected): | ||
assert split_camel_case_words(camel_cased_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'ast_tree, expected', | ||
[ | ||
("fruits = ['mango', 'grapes']", {'mango', 'grapes'}), | ||
("a = 'Bob'", {'Bob'}), | ||
] | ||
|
||
) | ||
def test_extract_all_constants_from_ast(ast_tree, expected): | ||
assert {*extract_all_constants_from_ast(ast.parse(ast_tree))} == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_funcdef, expected', | ||
[ | ||
('def func(n):\n\treturn func(n/2)', True), | ||
('def func(n):\n\treturn n/2', False), | ||
] | ||
) | ||
def test_has_recursive_calls(some_funcdef, expected): | ||
assert has_recursive_calls(ast.parse(some_funcdef).body[0]) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_url, expected', | ||
[ | ||
('url', None), | ||
('http://climbhub.com/', 100), | ||
], | ||
) | ||
def test_get_image_height_in_pixels(some_url, expected, create_image, requests_mock, mocker): | ||
requests_mock.get(some_url, content=b"request") | ||
mocker.patch('PIL.Image.open', return_value=create_image) | ||
assert get_image_height_in_pixels(some_url) == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Еще можно протестировать на передачу пустого списка и словарей в списке