-
Notifications
You must be signed in to change notification settings - Fork 13
unit test level 1 #3
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
DmitryTokyo
wants to merge
16
commits into
python-testing-sandbox:main
Choose a base branch
from
DmitryTokyo: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
16 commits
Select commit
Hold shift + click to select a range
c0819c2
Pass unit test levev 1
DmitryTokyo 0bbd923
Update requirements.txt
DmitryTokyo c4f9c01
Initial commit
DmitryTokyo 800059d
Update requirements.txt
DmitryTokyo 28d87e9
Add flake8 config
DmitryTokyo 352ec5f
Add CI integrations
DmitryTokyo 01a4857
Fix import
DmitryTokyo 53e7643
Fix flake8 bugs
DmitryTokyo e96932d
Fix flake8 bugs
DmitryTokyo 586fda4
Update README.md
DmitryTokyo 389f872
Add flake8 config
DmitryTokyo 17b1501
update .gitignore
DmitryTokyo 4995c11
update requirements.txt
DmitryTokyo 6bced3c
Add fixture and class
DmitryTokyo 123833e
Update all test functions
DmitryTokyo 3d9ae26
Update requirements.txt
DmitryTokyo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = venv, code.py | ||
ignore = C812, D103, TAE001, D100, D101 |
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 |
---|---|---|
|
@@ -348,3 +348,4 @@ make.exe | |
|
||
*.json | ||
*sqlite3 | ||
practice.py |
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 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,12 @@ | ||
import pytest | ||
from PIL import Image | ||
|
||
|
||
@pytest.fixture | ||
def get_fixture_image_object(): | ||
im = Image.new('1', (100, 100)) | ||
return im | ||
|
||
|
||
class SomeClass: | ||
pass |
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,40 @@ | ||
Pillow==8.1.2 | ||
requests==2.25.1 | ||
pytest==6.2.4 | ||
coverage==5.5 | ||
pytest-cov==2.12.0 | ||
requests-mock==1.9.3 | ||
pytest-mock==3.6.1 | ||
|
||
flake8==3.9.2 | ||
flake8-2020==1.6.0 | ||
flake8-blind-except==0.2.0 | ||
flake8-bugbear==20.11.1 | ||
flake8-builtins==1.5.3 | ||
flake8-commas==2.0.0 | ||
flake8-comprehensions==3.3.1 | ||
flake8-debugger==4.0.0 | ||
flake8-docstrings==1.5.0 | ||
flake8-eradicate==1.0.0 | ||
flake8-polyfill==1.0.2 | ||
flake8-print==4.0.0 | ||
flake8-quotes==3.2.0 | ||
flake8-string-format==0.3.0 | ||
flake8-fixme==1.1.1 | ||
flake8-annotations-complexity==0.0.6 | ||
flake8-variables-names==0.0.4 | ||
flake8-class-attributes-order==0.1.2 | ||
flake8-broken-line==0.3.0 | ||
flake8-tidy-imports==4.2.1 | ||
flake8-typing-imports==1.10.1 | ||
flake8-if-statements==0.1.0 | ||
flake8-functions==0.0.5 | ||
flake8-annotations-coverage==0.0.5 | ||
flake8-expression-complexity==0.0.9 | ||
flake8-printf-formatting==1.1.2 | ||
flake8-multiline-containers==0.0.17 | ||
flake8-absolute-import==1.0 | ||
flake8-simplify==0.13.0 | ||
flake8-functions-names==0.0.5 | ||
mypy-extensions==0.4.3 | ||
|
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,171 @@ | ||
import datetime | ||
import pytest | ||
import ast | ||
|
||
from code import (chunks, flat, has_recursive_calls, parse_iso_datetime, get_image_height_in_pixels, | ||
if_logs_has_any_of_commands, extract_all_constants_from_ast, is_camel_case_word, | ||
split_camel_case_words, is_path_in_exclude_list, get_full_class_name, max_with_default, | ||
is_python_class_name) | ||
from conftest import SomeClass | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'somelist, chunk_size, expected', | ||
[ | ||
([1, 2, 3, 4, 5], 2, [[1, 2], [3, 4], [5]]), | ||
([], 3, []), | ||
(['a', 'b'], 3, [['a', 'b']]), | ||
] | ||
) | ||
def test_chunk_iteration(somelist, chunk_size, expected): | ||
some_chunks = chunks(somelist, chunk_size) | ||
assert list(some_chunks) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_list, expected', | ||
[ | ||
([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'j']], ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']), | ||
([], []), | ||
([{1: 'a', 2: 'b'}, {3: 'q', 4: 'w'}], [1, 2, 3, 4]), | ||
] | ||
) | ||
def test_flat(some_list, expected): | ||
assert flat(some_list) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'expression, expected', | ||
[ | ||
('5/3+8', False), | ||
('def foo(): return foo()', True), | ||
|
||
] | ||
) | ||
def test_has_recursive_calls(expression, expected): | ||
funcdef = ast.parse(expression).body[0] | ||
assert has_recursive_calls(funcdef) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_datetime, expected', | ||
[ | ||
('2021-05-24T10:34:25.518993Z', datetime.datetime(2021, 5, 24, 10, 34, 25, 518993)), | ||
('2021.05.28', None), | ||
('', None), | ||
('2021-05-24T10:34:25.518993', datetime.datetime(2021, 5, 24, 10, 34, 25, 518993)), | ||
|
||
] | ||
) | ||
def test_parse_iso_datetime(some_datetime, expected): | ||
assert parse_iso_datetime(some_datetime) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'log, commands, expected', | ||
[ | ||
(['move forward'], ['move'], True), | ||
(['variable set on'], ['set'], True), | ||
(['put'], ['put'], True), | ||
(['some text'], ['erase'], False), | ||
] | ||
) | ||
def test_if_logs_has_any_of_commands(log, commands, expected): | ||
assert if_logs_has_any_of_commands(log, commands) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'expression, expected', | ||
[ | ||
('def foo(): return foo()', []), | ||
('def foo(): return "text"', ['text']), | ||
] | ||
) | ||
def test_extract_all_constants_from_ast(expression, expected): | ||
tree = ast.parse(expression).body[0] | ||
assert extract_all_constants_from_ast(tree) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'some_word, expected', | ||
[ | ||
('SuperClass', True), | ||
('nonameclass', False), | ||
('email_address', False), | ||
('EmailVerification', True), | ||
('oldEmail', True), | ||
] | ||
) | ||
def test_is_camel_case_word(some_word, expected): | ||
assert is_camel_case_word(some_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'camel_cased_word, expected', | ||
[ | ||
('SuperMegaClass', ['super', 'mega', 'class']), | ||
('userName', ['user', 'name']), | ||
('Sometext', ['sometext']), | ||
] | ||
) | ||
def test_split_camel_case_words(camel_cased_word, expected): | ||
assert split_camel_case_words(camel_cased_word) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'path, exclude, expected', | ||
[ | ||
('user/project/template', ['project', 'projects'], True), | ||
('lib/bin/', ['project', 'projects'], False), | ||
('C:\\User\\Documents', ['User'], True), | ||
('D:\\Game\\Civilization', ['Program', 'User'], False), | ||
] | ||
) | ||
def test_is_path_in_exclude_list(path, exclude, expected): | ||
assert is_path_in_exclude_list(path, exclude) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'items, default, expected', | ||
[ | ||
([], 1, 1), | ||
([1, 2], None, 2), | ||
] | ||
) | ||
def test_max_with_default(items, default, expected): | ||
assert max_with_default(items, default) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'classname, expected', | ||
[ | ||
('List', True), | ||
('car', False), | ||
] | ||
) | ||
def test_is_python_class_name(classname, expected): | ||
assert is_python_class_name(classname) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'image_url, expected', | ||
[ | ||
('some.url', None), | ||
('https://fake.url', 100), | ||
] | ||
) | ||
def test_get_image_height_in_pixels(requests_mock, mocker, get_fixture_image_object, image_url, expected): | ||
requests_mock.get(image_url, content=b'fakeurl') | ||
mocker.patch('PIL.Image.open', return_value=get_fixture_image_object) | ||
assert get_image_height_in_pixels(image_url) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'obj, expected', | ||
[ | ||
('Hello World', 'str'), | ||
(SomeClass(), 'conftest.SomeClass') | ||
] | ||
) | ||
def test_get_full_class_name(obj, expected): | ||
assert get_full_class_name(obj) == 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.
suggestion: Можно добавить на проверку букв еще)