-
Notifications
You must be signed in to change notification settings - Fork 13
Add tests #2
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
OdintsovTim
wants to merge
16
commits into
python-testing-sandbox:main
Choose a base branch
from
OdintsovTim: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
Add tests #2
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1f21fc5
update gitignore
OdintsovTim c55c2a4
make tests
OdintsovTim 65f308e
test cov
OdintsovTim a84bf4c
add code cov
OdintsovTim 0fb0baf
add new tests
OdintsovTim e5ab717
add checking for blank string
OdintsovTim e941239
mock get request
OdintsovTim b96731d
add set to avoid different order from ast.walk
OdintsovTim 7598b89
delete excess in gitignore
OdintsovTim 34a00f1
test exceptions in a separate function
OdintsovTim 72759d3
replace ast.parse from parametrize to function
OdintsovTim ff405a6
simplify test
OdintsovTim 72ef8d4
add branch coverage
OdintsovTim 9896207
fix branch coverage
OdintsovTim 7a30452
fix branch coverage
OdintsovTim 92b42da
add no cover, looks like bug
OdintsovTim 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 . | ||
- 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
from PIL import Image | ||
|
||
|
||
class FakeClass: | ||
pass | ||
|
||
|
||
def get_size(): | ||
return 50 | ||
|
||
|
||
@pytest.fixture | ||
def test_image_factory(): | ||
def create_test_image(a): | ||
image = Image.new('RGBA', size=(get_size(), get_size()), color=(155, 0, 0)) | ||
return image | ||
|
||
return create_test_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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
Pillow==8.1.2 | ||
requests==2.25.1 | ||
pytest==6.2.2 | ||
coverage==5.5 | ||
flake8==3.8.4 |
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 |
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,198 @@ | ||
import ast | ||
import datetime | ||
|
||
import pytest | ||
import requests | ||
from PIL import Image | ||
|
||
import code | ||
from conftest import FakeClass, get_size | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'name, expected', | ||
[('MyClass', False), ('Myclass', True), ('myclass', False), ('mYclass', False)] | ||
) | ||
def test_is_python_class_name(name, expected): | ||
assert code.is_python_class_name(name) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args, expected', | ||
[ | ||
(([], None), 0), | ||
(([],), 0), | ||
(([], 5), 5), | ||
(([-1], None), -1), | ||
(([1, 3, -1, 100], 5), 100), | ||
(((1, 3, -1, 101), 5), 101), | ||
(((1, 3, -1, 101),), 101), | ||
] | ||
) | ||
def test_max_with_default(args, expected): | ||
assert code.max_with_default(*args) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args, expected, ', | ||
[(((1, 3, -1, '101'),), None)] | ||
) | ||
def test_max_with_default_with_exception(args, expected): | ||
with pytest.raises(TypeError): | ||
assert code.max_with_default(*args) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'path, exclude, expected', | ||
[ | ||
('mypath', [], False), | ||
('mypath', ['my', 'path'], True), | ||
('mypath', ['mypath', 'anypath'], True), | ||
('', [''], True), | ||
('', [], False), | ||
] | ||
) | ||
def test_is_path_in_exclude_list(path, exclude, expected): | ||
assert code.is_path_in_exclude_list(path, exclude) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_list, expected', | ||
[ | ||
([[1, 2, 3], [4, 5, 6]], [1, 2, 3, 4, 5, 6]), | ||
([[1, 'b', 3], [{}, 5, 6], ['a', 8, 9]], [1, 'b', 3, {}, 5, 6, 'a', 8, 9]), | ||
([[], []], []), | ||
([], []), | ||
([[]], []), | ||
] | ||
) | ||
def test_flat(some_list, expected): | ||
assert code.flat(some_list) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'iso_datetime, expected', | ||
[ | ||
('2018-05-25T12:16:14Z', datetime.datetime(2018, 5, 25, 12, 16, 14)), | ||
('2018-02-25T18:16:15', datetime.datetime(2018, 2, 25, 18, 16, 15)), | ||
('2018:02-25T18:16:15', None), | ||
] | ||
) | ||
def test_parse_iso_datetime(iso_datetime, expected): | ||
assert code.parse_iso_datetime(iso_datetime) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'log, commands, expected', | ||
[ | ||
([], [], False), | ||
(['command'], ['command'], True), | ||
(['command'], ['pip'], False), | ||
(['pip command'], ['pip'], True), | ||
(['nice pip command'], ['pip'], True), | ||
(['command'], [], False), | ||
([], ['command'], False), | ||
] | ||
) | ||
def test_if_logs_has_any_of_commands(log, commands, expected): | ||
assert code.if_logs_has_any_of_commands(log, commands) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'word, expected', | ||
[ | ||
('small', False), | ||
('Bs', False), | ||
('BiG', True), | ||
('cAmel', True), | ||
('small', False), | ||
('BIG', False), | ||
OdintsovTim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
('', False), | ||
] | ||
) | ||
def test_is_camel_case_word(word, expected): | ||
assert code.is_camel_case_word(word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'obj, expected', | ||
[ | ||
('sting', 'str'), | ||
(1, 'int'), | ||
([2], 'list'), | ||
((1, 2, 3), 'tuple'), | ||
(FakeClass(), 'conftest.FakeClass'), | ||
] | ||
) | ||
def test_get_full_class_name(obj, expected): | ||
assert code.get_full_class_name(obj) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_list, chunk_size, expected', | ||
[ | ||
([1, 2, 3, 4, 5], 2, [[1, 2], [3, 4], [5]]), | ||
([], 2, []), | ||
] | ||
) | ||
def test_chunks(some_list, chunk_size, expected): | ||
gen = code.chunks(some_list, chunk_size) | ||
|
||
assert list(gen) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'camel_cased_word, expected', | ||
[ | ||
('BigGood', ['big', 'good']), | ||
('Big', ['big']), | ||
('bIg', ['b', 'ig']), | ||
] | ||
) | ||
def test_split_camel_case_words(camel_cased_word, expected): | ||
assert code.split_camel_case_words(camel_cased_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'camel_cased_word, expected, ', | ||
[('small', []), ('', [])] | ||
) | ||
def test_split_camel_case_words_with_exception(camel_cased_word, expected): | ||
with pytest.raises(IndexError): | ||
assert code.split_camel_case_words(camel_cased_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'url, expected', | ||
[ | ||
('https://yandex.ru/', get_size()), | ||
('yandex.ru/', None), | ||
] | ||
) | ||
def test_get_image_height_in_pixels(url, expected, monkeypatch, test_image_factory): | ||
monkeypatch.setattr(requests, 'get', b'some binary chars') | ||
monkeypatch.setattr(Image, 'open', test_image_factory) | ||
assert code.get_image_height_in_pixels(url) == expected | ||
OdintsovTim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
'module, expected', | ||
[ | ||
('a = "literal"\nb = 5', {'literal'}), | ||
('b = 5', set()), | ||
('a = "literal"\nb = "new literal"', {'literal', 'new literal'}), | ||
] | ||
) | ||
def test_extract_all_constants_from_ast(module, expected): | ||
assert {*code.extract_all_constants_from_ast(ast.parse(module))} == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'module, expected', | ||
[ | ||
('def not_recursive(a, b, c):\n return a + b + c', False), | ||
('def recursive(a, b, c):\n return recursive(a, b, c)', True), | ||
] | ||
) | ||
def test_has_recursive_calls(module, expected): | ||
assert code.has_recursive_calls(ast.parse(module).body[0]) == 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.
Uh oh!
There was an error while loading. Please reload this page.