Skip to content

Commit

Permalink
Adds class checks
Browse files Browse the repository at this point in the history
Changes:
1. Forbids old-style classes, closes #35
2. Forbids `staticmethod`, closes #38
3. Forbids `__del__` magic method, closes #44
4. Forbids `async` and `await` variable names, closes #49
5. Forbids `__future__` import, closes #48
  • Loading branch information
sobolevn committed Jul 19, 2018
1 parent 520c95f commit d5f7668
Show file tree
Hide file tree
Showing 16 changed files with 434 additions and 144 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

We follow Semantic Versions.

## Version 0.0.4

### Features

- We now check `class`es to match our styleguide
- Classes have their own error group `Z3`
- Using `@staticmethod` is now forbidden
- Declaring `object` as a base class is now required
- Now we check that `__del__` magic method is not used
- Variable names `async` and `await` are forbidden
- We now forbid to use `__future__` imports
- We now have a whitelist for `__future__` imports
- Imports are now have its own subgroup `Z10`
- General rules now start from `Z11`


## Version 0.0.3

### Features
Expand Down
106 changes: 3 additions & 103 deletions pyproject.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ platform = "*"
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4"
version = "4.5.1"

[[package]]
category = "dev"
description = "Better living through Python with decorators"
name = "decorator"
optional = false
platform = "All"
python-versions = "*"
version = "4.3.0"

[[package]]
category = "dev"
description = "Style checker for Sphinx (or other) RST documentation"
Expand Down Expand Up @@ -131,32 +122,6 @@ version = "1.5.0"
[package.dependencies]
apipkg = ">=1.4"

[[package]]
category = "dev"
description = "A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby."
name = "factory-boy"
optional = false
platform = "*"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "2.11.1"

[package.dependencies]
Faker = ">=0.7.0"

[[package]]
category = "dev"
description = "Faker is a Python package that generates fake data for you."
name = "faker"
optional = false
platform = "any"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "0.8.17"

[package.dependencies]
python-dateutil = ">=2.4"
six = ">=1.10"
text-unidecode = "1.2"

[[package]]
category = "main"
description = "the modular source code checker: pep8, pyflakes and co"
Expand Down Expand Up @@ -333,15 +298,6 @@ platform = "*"
python-versions = "*"
version = "1.0.0"

[[package]]
category = "dev"
description = "A port of Ruby on Rails inflector to Python"
name = "inflection"
optional = false
platform = "UNKNOWN"
python-versions = "*"
version = "0.3.1"

[[package]]
category = "dev"
description = "A Python utility / library to sort Python imports."
Expand Down Expand Up @@ -588,20 +544,6 @@ version = "2.5.1"
coverage = ">=3.7.1"
pytest = ">=2.6.0"

[[package]]
category = "dev"
description = "Factory Boy support for pytest."
name = "pytest-factoryboy"
optional = false
platform = "*"
python-versions = "*"
version = "2.0.1"

[package.dependencies]
factory_boy = ">=2.10.0"
inflection = "*"
pytest = ">=3.3.2"

[[package]]
category = "dev"
description = "pytest plugin to check FLAKE8 requirements"
Expand Down Expand Up @@ -641,18 +583,6 @@ version = "1.2.3"
[package.dependencies]
pytest = "*"

[[package]]
category = "dev"
description = "Extensions to the standard Python datetime module"
name = "python-dateutil"
optional = false
platform = "*"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
version = "2.7.3"

[package.dependencies]
six = ">=1.5"

[[package]]
category = "dev"
description = "World timezone definitions, modern and historical"
Expand Down Expand Up @@ -714,7 +644,7 @@ name = "sphinx"
optional = false
platform = "any"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "1.7.5"
version = "1.7.6"

[package.dependencies]
Jinja2 = ">=2.3"
Expand Down Expand Up @@ -790,15 +720,6 @@ version = "1.28.0"
pbr = ">=2.0.0,<2.1.0 || >2.1.0"
six = ">=1.10.0"

[[package]]
category = "dev"
description = "The most basic Text::Unidecode port"
name = "text-unidecode"
optional = false
platform = "*"
python-versions = "*"
version = "1.2"

[[package]]
category = "dev"
description = "a fork of Python 2 and 3 ast modules with type comment support"
Expand All @@ -817,21 +738,8 @@ platform = "*"
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4"
version = "1.23"

[[package]]
category = "dev"
description = "Python Data Validation for Humans™."
name = "validators"
optional = false
platform = "any"
python-versions = "*"
version = "0.12.2"

[package.dependencies]
decorator = ">=3.4.0"
six = ">=1.4.0"

[metadata]
content-hash = "a0faf8b61fa9bced3a5790d46797f49ca6fa01b58339270dd5d96e3bce484623"
content-hash = "127dd2b3e98b6c05e552dfdba57053620e8437754070b81fda5acad68b190fff"
platform = "*"
python-versions = "^3.6"

Expand All @@ -845,12 +753,9 @@ certifi = ["13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7", "
chardet = ["84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"]
colorama = ["463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda", "48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1"]
coverage = ["03481e81d558d30d230bc12999e3edffe392d244349a90f4ef9b88425fac74ba", "0b136648de27201056c1869a6c0d4e23f464750fd9a9ba9750b8336a244429ed", "104ab3934abaf5be871a583541e8829d6c19ce7bde2923b2751e0d3ca44db60a", "15b111b6a0f46ee1a485414a52a7ad1d703bdf984e9ed3c288a4414d3871dcbd", "198626739a79b09fa0a2f06e083ffd12eb55449b5f8bfdbeed1df4910b2ca640", "1c383d2ef13ade2acc636556fd544dba6e14fa30755f26812f54300e401f98f2", "28b2191e7283f4f3568962e373b47ef7f0392993bb6660d079c62bd50fe9d162", "2eb564bbf7816a9d68dd3369a510be3327f1c618d2357fa6b1216994c2e3d508", "337ded681dd2ef9ca04ef5d93cfc87e52e09db2594c296b4a0a3662cb1b41249", "3a2184c6d797a125dca8367878d3b9a178b6fdd05fdc2d35d758c3006a1cd694", "3c79a6f7b95751cdebcd9037e4d06f8d5a9b60e4ed0cd231342aa8ad7124882a", "3d72c20bd105022d29b14a7d628462ebdc61de2f303322c0212a054352f3b287", "3eb42bf89a6be7deb64116dd1cc4b08171734d721e7a7e57ad64cc4ef29ed2f1", "4635a184d0bbe537aa185a34193898eee409332a8ccb27eea36f262566585000", "56e448f051a201c5ebbaa86a5efd0ca90d327204d8b059ab25ad0f35fbfd79f1", "5a13ea7911ff5e1796b6d5e4fbbf6952381a611209b736d48e675c2756f3f74e", "69bf008a06b76619d3c3f3b1983f5145c75a305a0fea513aca094cae5c40a8f5", "6bc583dc18d5979dc0f6cec26a8603129de0304d5ae1f17e57a12834e7235062", "701cd6093d63e6b8ad7009d8a92425428bc4d6e7ab8d75efbb665c806c1d79ba", "7608a3dd5d73cb06c531b8925e0ef8d3de31fed2544a7de6c63960a1e73ea4bc", "76ecd006d1d8f739430ec50cc872889af1f9c1b6b8f48e29941814b09b0fd3cc", "7aa36d2b844a3e4a4b356708d79fd2c260281a7390d678a10b91ca595ddc9e99", "7d3f553904b0c5c016d1dad058a7554c7ac4c91a789fca496e7d8347ad040653", "7e1fe19bd6dce69d9fd159d8e4a80a8f52101380d5d3a4d374b6d3eae0e5de9c", "8c3cb8c35ec4d9506979b4cf90ee9918bc2e49f84189d9bf5c36c0c1119c6558", "9d6dd10d49e01571bf6e147d3b505141ffc093a06756c60b053a859cb2128b1f", "9e112fcbe0148a6fa4f0a02e8d58e94470fc6cb82a5481618fea901699bf34c4", "ac4fef68da01116a5c117eba4dd46f2e06847a497de5ed1d64bb99a5fda1ef91", "b8815995e050764c8610dbc82641807d196927c3dbed207f0a079833ffcf588d", "be6cfcd8053d13f5f5eeb284aa8a814220c3da1b0078fa859011c7fffd86dab9", "c1bb572fab8208c400adaf06a8133ac0712179a334c09224fb11393e920abcdd", "de4418dadaa1c01d497e539210cb6baa015965526ff5afc078c57ca69160108d", "e05cb4d9aad6233d67e0541caa7e511fa4047ed7750ec2510d466e806e0255d6", "e4d96c07229f58cb686120f168276e434660e4358cc9cf3b0464210b04913e77", "f3f501f345f24383c0000395b26b726e46758b71393267aeae0bd36f8b3ade80", "f8a923a85cb099422ad5a2e345fe877bbc89a8a8b23235824a93488150e45f6e"]
decorator = ["2c51dff8ef3c447388fe5e4453d24a2bf128d3a4c32af3fabef1f01c6851ab82", "c39efa13fbdeb4506c476c9b3babf6a718da943dab7811c206005a4a956c080c"]
doc8 = ["2df89f9c1a5abfb98ab55d0175fed633cae0cf45025b8b1e0ee5ea772be28543", "d12f08aa77a4a65eb28752f4bc78f41f611f9412c4155e2b03f1f5d4a45efe04"]
docutils = ["02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6", "51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274", "7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6"]
execnet = ["a7a84d5fa07a089186a329528f127c9d73b9de57f1a1131b82bb5320ee651f6a", "fc155a6b553c66c838d1a22dba1dc9f5f505c43285a878c6f74a79c024750b83"]
factory-boy = ["6f25cc4761ac109efd503f096e2ad99421b1159f01a29dbb917359dcd68e08ca", "d552cb872b310ae78bd7429bf318e42e1e903b1a109e899a523293dfa762ea4f"]
faker = ["0e9a1227a3a0f3297a485715e72ee6eb77081b17b629367042b586e38c03c867", "b4840807a94a3bad0217d6ed3f9b65a1cc6e1db1c99e1184673056ae2c0a4c4d"]
flake8 = ["7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0", "c7841163e2b576d435799169b78703ad6ac1bbb0f199994fc05f700b2a90ea37"]
flake8-blind-except = ["0d7d1adb4cabf2268d6eebb815a7a5014bcb7e8419f7a74339c46d0b8847b858", "aca3356633825544cec51997260fe31a8f24a1a2795ce8e81696b9916745e599"]
flake8-bugbear = ["541746f0f3b2f1a8d7278e1d2d218df298996b60b02677708560db7c7e620e3b", "5f14a99d458e29cb92be9079c970030e0dd398b2decb179d76d39a5266ea1578"]
Expand All @@ -866,7 +771,6 @@ flake8-quotes = ["fd9127ad8bbcf3b546fa7871a5266fd8623ce765ebe3d5aa5eabb80c01212b
flake8-string-format = ["68ea72a1a5b75e7018cae44d14f32473c798cf73d75cbaed86c6a9a907b770b2", "774d56103d9242ed968897455ef49b7d6de272000cfa83de5814273a868832f1"]
idna = ["156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", "684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"]
imagesize = ["3620cc0cadba3f7475f9940d22431fc4d407269f1be59ec9b8edcca26440cf18", "5b326e4678b6925158ccc66a9fa3122b6106d7c876ee32d7de6ce59385b96315"]
inflection = ["18ea7fb7a7d152853386523def08736aa8c32636b047ade55f7578c4edeb16ca"]
isort = ["1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af", "b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8", "ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497"]
jinja2 = ["74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd", "f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"]
m2r = ["1c358d8bf21ff70e569968d604a0e3c9b05fe01b5f362389235e97bc7c0cd542"]
Expand All @@ -889,23 +793,19 @@ pyparsing = ["0832bcf47acd283788593e7a0f542407bd9550a55a8a8435214a1960e04bcb04",
pytest = ["0453c8676c2bee6feb0434748b068d5510273a916295fd61d306c4f22fbfd752", "4b208614ae6d98195430ad6bde03641c78553acee7c83cec2e85d613c0cd383d"]
pytest-cache = ["be7468edd4d3d83f1e844959fd6e3fd28e77a481440a7118d430130ea31b07a9"]
pytest-cov = ["03aa752cf11db41d281ea1d807d954c4eda35cfa1b21d6971966cc041bbf6e2d", "890fe5565400902b0c78b5357004aab1c814115894f4f21370e2433256a3eeec"]
pytest-factoryboy = ["ad438d191d2b2a0f26956d437c1963875db573147a84ffd85d7bbeaefae22458"]
pytest-flake8 = ["e5cdc4f459c9436ac6c649e428a014bb5988605858549397374ec29a776cae68", "ec248d4a215d6c7cd9d3ca48f365ece0e3892b46d626c22a95ccc80188ff35ed"]
pytest-isort = ["ce36b62ca1108e16a8b8fc0d5a82302ba0796a3c352b093e13ccbb18e772edc6", "d4d195ecfe33d81e258d251b2679b32216bad84131fb41984da22d9d0328a6fe"]
pytest-randomly = ["6db5e03d72b54052b9b379dc3cfa4749c19bfe4de161cf3eb24762049f4ce9be", "92ec6745d3ebdd690ecb598648748c9601f16f5afacf83ccef2b50d23e6edb7f"]
python-dateutil = ["1adb80e7a782c12e52ef9a8182bebeb73f1d7e24e374397af06fb4956c8dc5c0", "e27001de32f627c22380a688bcc43ce83504a7bc5da472209b4c70f02829f0b8"]
pytz = ["a061aa0a9e06881eb8b3b2b43f05b9439d6583c206d0a6c340ff72a7b6669053", "ffb9ef1de172603304d9d2819af6f5ece76f2e85ec10692a524dd876e72bf277"]
requests = ["63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", "ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a"]
restructuredtext-lint = ["c48ca9a84c312b262809f041fe47dcfaedc9ee4879b3e1f9532f745c182b4037"]
six = ["70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", "832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"]
snowballstemmer = ["919f26a68b2c17a7634da993d91339e288964f93c274f1343e3bbbe2096e1128", "9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89"]
sphinx = ["85f7e32c8ef07f4ba5aeca728e0f7717bef0789fba8458b8d9c5c294cad134f3", "d45480a229edf70d84ca9fae3784162b1bc75ee47e480ffe04a4b7f21a95d76d"]
sphinx = ["217ad9ece2156ed9f8af12b5d2c82a499ddf2c70a33c5f81864a08d8c67b9efc", "a765c6db1e5b62aae857697cd4402a5c1a315a7b0854bbcd0fc8cdc524da5896"]
sphinx-autodoc-typehints = ["1a9df6cb3ba72453ea4bfbe96ea887abc0d796b2ce9508c2189217a1bb69b366", "46cc9e985ee6d8bbbd07fffd95b815c39a72df6afb600f59671f85f7340e7d0d"]
sphinx-readable-theme = ["f5fe65a2e112cb956b366df41e0fc894ff6b6f0e4a4814fcbff692566db47fc0"]
sphinxcontrib-napoleon = ["614b779888629f14dfdfad6c17bffbb6d3813a0a0917a9541651d85384d4d6bd", "cbb31953b15d2102c18f16f02591f92e2614a08ef0218c9e514e2dc4c4f9daf9"]
sphinxcontrib-websupport = ["68ca7ff70785cbe1e7bccc71a48b5b6d965d79ca50629606c7861a21b206d9dd", "9de47f375baf1ea07cdb3436ff39d7a9c76042c10a769c52353ec46e4e8fc3b9"]
stevedore = ["e3d96b2c4e882ec0c1ff95eaebf7b575a779fd0ccb4c741b9832bed410d58b3d", "f1c7518e7b160336040fee272174f1f7b29a46febb3632502a8f2055f973d60b"]
text-unidecode = ["5a1375bb2ba7968740508ae38d92e1f889a0832913cb1c447d5e2046061a396d", "801e38bd550b943563660a91de8d4b6fa5df60a542be9093f7abf819f86050cc"]
typed-ast = ["0948004fa228ae071054f5208840a1e88747a357ec1101c17217bfe99b299d58", "25d8feefe27eb0303b73545416b13d108c6067b846b543738a25ff304824ed9a", "29464a177d56e4e055b5f7b629935af7f49c196be47528cc94e0a7bf83fbc2b9", "2e214b72168ea0275efd6c884b114ab42e316de3ffa125b267e732ed2abda892", "3e0d5e48e3a23e9a4d1a9f698e32a542a4a288c871d33ed8df1b092a40f3a0f9", "519425deca5c2b2bdac49f77b2c5625781abbaf9a809d727d3a5596b30bb4ded", "57fe287f0cdd9ceaf69e7b71a2e94a24b5d268b35df251a88fef5cc241bf73aa", "668d0cec391d9aed1c6a388b0d5b97cd22e6073eaa5fbaa6d2946603b4871efe", "68ba70684990f59497680ff90d18e756a47bf4863c604098f10de9716b2c0bdd", "6de012d2b166fe7a4cdf505eee3aaa12192f7ba365beeefaca4ec10e31241a85", "79b91ebe5a28d349b6d0d323023350133e927b4de5b651a8aa2db69c761420c6", "8550177fa5d4c1f09b5e5f524411c44633c80ec69b24e0e98906dd761941ca46", "a8034021801bc0440f2e027c354b4eafd95891b573e12ff0418dec385c76785c", "bc978ac17468fe868ee589c795d06777f75496b1ed576d308002c8a5756fb9ea", "c05b41bc1deade9f90ddc5d988fe506208019ebba9f2578c622516fd201f5863", "c9b060bd1e5a26ab6e8267fd46fc9e02b54eb15fffb16d112d4c7b1c12987559", "edb04bdd45bfd76c8292c4d9654568efaedf76fe78eb246dde69bdb13b2dad87", "f19f2a4f547505fe9072e15f6f4ae714af51b5a681a97f187971f50c283193b6"]
urllib3 = ["a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf", "b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5"]
validators = ["172ac45f7d1944ce4beca3c5c53ca7c83e9759e39fd3fedc1cf28e2130268706"]
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.3"
version = "0.0.4"
description = "Opinionated styleguide that we use in wemake.services"

license = "MIT"
Expand Down Expand Up @@ -47,6 +47,7 @@ flake8 = "^3.5"
pytest-cov = "^2.5"
pytest-isort = "^0.2.0"
pytest-flake8 = "^1.0"
pytest-randomly = "^1.2"
pytest = "^3.6"
flake8-builtins = "^1.4"
flake8-commas = "^2.0"
Expand All @@ -60,9 +61,6 @@ flake8-module-name = "^0.1.5"
flake8-bugbear = "^18.2"
flake8-pytest = "^1.3"
pep8-naming = "^0.7.0"
validators = "^0.12.2"
pytest_factoryboy = "^2.0"
pytest-randomly = "^1.2"
mypy = "^0.610.0"
sphinx = "^1.7"
sphinx-autodoc-typehints = "^1.3"
Expand Down
23 changes: 15 additions & 8 deletions tests/fixtures/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
This file contains all possible errors.
"""

from __future__ import print_function # noqa: Z102
from .version import get_version # noqa: Z100
def some():
from my_module import some_function # noqa: Z101


del {'a': 1}['a'] # noqa: Z102
raise # noqa: Z103
raise NotImplemented # noqa: Z104
hasattr(object, 'some') # noqa: Z105
value = 1 # noqa: Z106
x = 2 # noqa: Z107
__private = 3 # noqa: Z108
__author__ = 'Nikita Sobolev' # noqa: Z109
del {'a': 1}['a'] # noqa: Z110
raise # noqa: Z111
raise NotImplemented # noqa: Z112
hasattr(object, 'some') # noqa: Z113
value = 1 # noqa: Z114
x = 2 # noqa: Z115
__private = 3 # noqa: Z116
__author__ = 'Nikita Sobolev' # noqa: Z117


class BadClass: # noqa: Z302
@staticmethod # noqa: Z300
def some_static(): ...

def __del__(self, *args, **kwargs): ... # noqa: Z301
1 change: 1 addition & 0 deletions tests/test_checkers/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ def test_noqa_fixture(absolute_path):
)
stdout, _ = process.communicate()

print(stdout)
assert stdout.count(b'Z') == 0
8 changes: 4 additions & 4 deletions tests/test_checkers/test_wrong_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_wrong_variables_in_fixture(absolute_path):
)
stdout, _ = process.communicate()

assert stdout.count(b'Z106') == 12
assert stdout.count(b'Z107') == 6
assert stdout.count(b'Z108') == 1
assert stdout.count(b'Z109') == 1
assert stdout.count(b'Z114') == 12
assert stdout.count(b'Z115') == 6
assert stdout.count(b'Z116') == 1
assert stdout.count(b'Z117') == 1
39 changes: 39 additions & 0 deletions tests/test_visitors/test_wrong_class/test_base_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.wrong_class import (
RequiredBaseClassViolation,
WrongClassVisitor,
)


def test_wrong_base_class(assert_errors, parse_ast_tree):
"""Testing that not using explicit base class with forbiden."""
tree = parse_ast_tree("""
class WithoutBase: ...
""")

visiter = WrongClassVisitor()
visiter.visit(tree)

assert_errors(visiter, [RequiredBaseClassViolation])


@pytest.mark.parametrize('base', [
'object',
'dict',
'CustomClass',
'Multiple, Classes, Mixins',
'Custom, keyword=1',
])
def test_regular_base_classes(assert_errors, parse_ast_tree, base):
"""Testing that regular base classes work."""
tree = parse_ast_tree("""
class Example({0}): ...
""".format(base))

visiter = WrongClassVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
41 changes: 41 additions & 0 deletions tests/test_visitors/test_wrong_class/test_magic_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.constants import BAD_MAGIC_METHODS
from wemake_python_styleguide.visitors.wrong_class import (
BadMagicMethodViolation,
WrongClassVisitor,
)

magic_method = """
class Example(object):
def {0}(): ...
"""


@pytest.mark.parametrize('method', BAD_MAGIC_METHODS)
def test_wrong_magic_used(assert_errors, parse_ast_tree, method):
"""Testing that some magic methods are restricted."""
tree = parse_ast_tree(magic_method.format(method))

visiter = WrongClassVisitor()
visiter.visit(tree)

assert_errors(visiter, [BadMagicMethodViolation])


@pytest.mark.parametrize('method', [
'__add__',
'__init__',
'next',
'regular',
])
def test_regular_method_used(assert_errors, parse_ast_tree, method):
"""Testing that other methods are working fine."""
tree = parse_ast_tree(magic_method.format(method))

visiter = WrongClassVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
Loading

0 comments on commit d5f7668

Please sign in to comment.