Skip to content

Commit ac209cb

Browse files
committed
Format Python scripts with black
1 parent 950fac9 commit ac209cb

File tree

7 files changed

+404
-319
lines changed

7 files changed

+404
-319
lines changed

setup.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,38 @@
2222
from setuptools import setup, find_packages
2323
from weechat_script_lint import __version__ as wsl_version
2424

25-
DESCRIPTION = 'Static analysis tool for WeeChat scripts.'
25+
DESCRIPTION = "Static analysis tool for WeeChat scripts."
2626

27-
with open('README.md', 'r', 'utf-8') as f:
27+
with open("README.md", "r", "utf-8") as f:
2828
readme = f.read()
2929

3030
setup(
31-
name='weechat-script-lint',
31+
name="weechat-script-lint",
3232
version=wsl_version,
3333
description=DESCRIPTION,
3434
long_description=readme,
35-
long_description_content_type='text/markdown',
36-
author='Sébastien Helleu',
37-
author_email='[email protected]',
38-
url='https://github.com/weechat/weechat-script-lint',
39-
license='GPL3',
40-
keywords='static analysis weechat script lint',
35+
long_description_content_type="text/markdown",
36+
author="Sébastien Helleu",
37+
author_email="[email protected]",
38+
url="https://github.com/weechat/weechat-script-lint",
39+
license="GPL3",
40+
keywords="static analysis weechat script lint",
4141
classifiers=[
42-
'Development Status :: 5 - Production/Stable',
43-
'Environment :: Console',
44-
'Intended Audience :: Developers',
45-
'License :: OSI Approved :: GNU General Public License v3 '
46-
'or later (GPLv3+)',
47-
'Natural Language :: English',
48-
'Operating System :: OS Independent',
49-
'Programming Language :: Python',
50-
'Programming Language :: Python :: 3',
51-
'Topic :: Software Development',
52-
'Topic :: Utilities',
42+
"Development Status :: 5 - Production/Stable",
43+
"Environment :: Console",
44+
"Intended Audience :: Developers",
45+
"License :: OSI Approved :: GNU General Public License v3 "
46+
"or later (GPLv3+)",
47+
"Natural Language :: English",
48+
"Operating System :: OS Independent",
49+
"Programming Language :: Python",
50+
"Programming Language :: Python :: 3",
51+
"Topic :: Software Development",
52+
"Topic :: Utilities",
5353
],
5454
packages=find_packages(),
55-
tests_require=['pytest'],
55+
tests_require=["pytest"],
5656
entry_points={
57-
'console_scripts': ['weechat-script-lint=weechat_script_lint:main'],
58-
}
57+
"console_scripts": ["weechat-script-lint=weechat_script_lint:main"],
58+
},
5959
)

tests/test_main.py

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@
2929

3030
import weechat_script_lint
3131

32-
SCRIPTS_DIR = Path(__file__).resolve().parent / 'scripts'
32+
SCRIPTS_DIR = Path(__file__).resolve().parent / "scripts"
3333

3434

3535
def test_main_no_scripts():
3636
"""Test main function without scripts."""
3737

3838
# no argument
39-
args = ['weechat-script-lint']
39+
args = ["weechat-script-lint"]
4040
with pytest.raises(SystemExit) as exc:
41-
with mock.patch.object(sys, 'argv', args):
41+
with mock.patch.object(sys, "argv", args):
4242
weechat_script_lint.main()
4343
assert exc.type == SystemExit
4444
assert exc.value.code == 2
4545

4646
# display help
47-
args = ['weechat-script-lint', '--help']
47+
args = ["weechat-script-lint", "--help"]
4848
with pytest.raises(SystemExit) as exc:
49-
with mock.patch.object(sys, 'argv', args):
49+
with mock.patch.object(sys, "argv", args):
5050
weechat_script_lint.main()
5151
assert exc.type == SystemExit
5252
assert exc.value.code == 0
@@ -56,19 +56,19 @@ def test_main_script():
5656
"""Test main function with a single script."""
5757

5858
# script not found
59-
filename = str(SCRIPTS_DIR / 'unknown.py')
60-
args = ['weechat-script-lint', filename]
59+
filename = str(SCRIPTS_DIR / "unknown.py")
60+
args = ["weechat-script-lint", filename]
6161
with pytest.raises(SystemExit) as exc:
62-
with mock.patch.object(sys, 'argv', args):
62+
with mock.patch.object(sys, "argv", args):
6363
weechat_script_lint.main()
6464
assert exc.type == SystemExit
65-
assert 'FATAL' in exc.value.code
65+
assert "FATAL" in exc.value.code
6666

6767
# check script OK
68-
filename = str(SCRIPTS_DIR / 'script_valid.py')
69-
args = ['weechat-script-lint', filename]
68+
filename = str(SCRIPTS_DIR / "script_valid.py")
69+
args = ["weechat-script-lint", filename]
7070
with pytest.raises(SystemExit) as exc:
71-
with mock.patch.object(sys, 'argv', args):
71+
with mock.patch.object(sys, "argv", args):
7272
weechat_script_lint.main()
7373
assert exc.type == SystemExit
7474
assert exc.value.code == 0
@@ -79,89 +79,91 @@ def test_main_dir():
7979

8080
# check directory with scripts
8181
args = [
82-
'weechat-script-lint',
83-
'--verbose',
84-
'--recursive',
82+
"weechat-script-lint",
83+
"--verbose",
84+
"--recursive",
8585
str(SCRIPTS_DIR),
8686
]
8787
with pytest.raises(SystemExit) as exc:
88-
with mock.patch.object(sys, 'argv', args):
88+
with mock.patch.object(sys, "argv", args):
8989
weechat_script_lint.main()
9090
assert exc.type == SystemExit
9191
assert exc.value.code == 7
9292

9393
# check directory with scripts, treat warnings as errors
9494
args = [
95-
'weechat-script-lint',
96-
'--strict',
97-
'--verbose',
98-
'--recursive',
95+
"weechat-script-lint",
96+
"--strict",
97+
"--verbose",
98+
"--recursive",
9999
str(SCRIPTS_DIR),
100100
]
101101
with pytest.raises(SystemExit) as exc:
102-
with mock.patch.object(sys, 'argv', args):
102+
with mock.patch.object(sys, "argv", args):
103103
weechat_script_lint.main()
104104
assert exc.type == SystemExit
105105
assert exc.value.code == 23
106106

107107
args = [
108-
'weechat-script-lint',
109-
'--ignore-files', 'script_valid.py,script_missing_email.py',
110-
'--verbose',
111-
'--recursive',
108+
"weechat-script-lint",
109+
"--ignore-files",
110+
"script_valid.py,script_missing_email.py",
111+
"--verbose",
112+
"--recursive",
112113
str(SCRIPTS_DIR),
113114
]
114115
with pytest.raises(SystemExit) as exc:
115-
with mock.patch.object(sys, 'argv', args):
116+
with mock.patch.object(sys, "argv", args):
116117
weechat_script_lint.main()
117118
assert exc.type == SystemExit
118119
assert exc.value.code == 6
119120

120121
# check a script returning only a warning
121-
filename = str(SCRIPTS_DIR / 'script_modifier_irc_in.py')
122+
filename = str(SCRIPTS_DIR / "script_modifier_irc_in.py")
122123
args = [
123-
'weechat-script-lint',
124-
'--verbose',
124+
"weechat-script-lint",
125+
"--verbose",
125126
filename,
126127
]
127128
with pytest.raises(SystemExit) as exc:
128-
with mock.patch.object(sys, 'argv', args):
129+
with mock.patch.object(sys, "argv", args):
129130
weechat_script_lint.main()
130131
assert exc.type == SystemExit
131132
assert exc.value.code == 0
132133

133134
# check a script returning only an info
134-
filename = str(SCRIPTS_DIR / 'script_unneeded_shebang.py')
135+
filename = str(SCRIPTS_DIR / "script_unneeded_shebang.py")
135136
args = [
136-
'weechat-script-lint',
137-
'--verbose',
137+
"weechat-script-lint",
138+
"--verbose",
138139
filename,
139140
]
140141
with pytest.raises(SystemExit) as exc:
141-
with mock.patch.object(sys, 'argv', args):
142+
with mock.patch.object(sys, "argv", args):
142143
weechat_script_lint.main()
143144
assert exc.type == SystemExit
144145
assert exc.value.code == 0
145146

146147
# check a file that isn't a WeeChat script
147-
filename = str(SCRIPTS_DIR / 'not_a_script.txt')
148-
args = ['weechat-script-lint', '--verbose', filename]
148+
filename = str(SCRIPTS_DIR / "not_a_script.txt")
149+
args = ["weechat-script-lint", "--verbose", filename]
149150
with pytest.raises(SystemExit) as exc:
150-
with mock.patch.object(sys, 'argv', args):
151+
with mock.patch.object(sys, "argv", args):
151152
weechat_script_lint.main()
152153
assert exc.type == SystemExit
153154
assert exc.value.code == 0
154155

155156

156157
def test_init():
157158
"""Test init function."""
158-
filename = str(SCRIPTS_DIR / 'script_valid.py')
159-
args = ['weechat-script-lint', filename]
159+
filename = str(SCRIPTS_DIR / "script_valid.py")
160+
args = ["weechat-script-lint", filename]
160161
with pytest.raises(SystemExit) as exc:
161-
with mock.patch.object(weechat_script_lint, 'main', return_value=0):
162-
with mock.patch.object(weechat_script_lint,
163-
'__name__', '__main__'):
164-
with mock.patch.object(sys, 'argv', args):
162+
with mock.patch.object(weechat_script_lint, "main", return_value=0):
163+
with mock.patch.object(
164+
weechat_script_lint, "__name__", "__main__"
165+
):
166+
with mock.patch.object(sys, "argv", args):
165167
weechat_script_lint.init(force=True)
166168
assert exc.type == SystemExit
167169
assert exc.value.code == 0

tests/test_script.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,102 +24,99 @@
2424

2525
from weechat_script_lint import WeechatScript
2626

27-
SCRIPTS_DIR = Path(__file__).resolve().parent / 'scripts'
27+
SCRIPTS_DIR = Path(__file__).resolve().parent / "scripts"
2828

2929
ALL_ERRORS = [
30-
('error', 1, 'missing_email'),
31-
('error', 17, 'missing_infolist_free'),
32-
('error', 18, 'python2_bin'),
33-
('warning', 27, 'sys_exit'),
34-
('warning', 19, 'deprecated_hook_completion_get_string'),
35-
('warning', 20, 'deprecated_hook_completion_list_add'),
36-
('warning', 22, 'deprecated_irc_nick_color'),
37-
('warning', 23, 'deprecated_irc_nick_color_name'),
38-
('warning', 24, 'modifier_irc_in'),
39-
('warning', 25, 'signal_irc_out'),
40-
('warning', 26, 'signal_irc_outtags'),
41-
('info', 1, 'unneeded_shebang'),
42-
('info', 13, 'url_weechat'),
30+
("error", 1, "missing_email"),
31+
("error", 17, "missing_infolist_free"),
32+
("error", 18, "python2_bin"),
33+
("warning", 27, "sys_exit"),
34+
("warning", 19, "deprecated_hook_completion_get_string"),
35+
("warning", 20, "deprecated_hook_completion_list_add"),
36+
("warning", 22, "deprecated_irc_nick_color"),
37+
("warning", 23, "deprecated_irc_nick_color_name"),
38+
("warning", 24, "modifier_irc_in"),
39+
("warning", 25, "signal_irc_out"),
40+
("warning", 26, "signal_irc_outtags"),
41+
("info", 1, "unneeded_shebang"),
42+
("info", 13, "url_weechat"),
4343
]
4444

4545

4646
def test_script_valid():
4747
"""Tests on a valid script."""
48-
path = SCRIPTS_DIR / 'script_valid.py'
48+
path = SCRIPTS_DIR / "script_valid.py"
4949

5050
script = WeechatScript(path)
51-
assert str(script) == ''
51+
assert str(script) == ""
5252
assert script.path == path.resolve()
5353
assert script.ignored_msg == []
5454
assert script.msg_level == 2
5555
assert script.use_colors is True
5656
assert script.messages == []
57-
assert script.count == {'error': 0, 'warning': 0, 'info': 0}
57+
assert script.count == {"error": 0, "warning": 0, "info": 0}
5858
assert script.script
5959
script.check()
60-
assert str(script) == ''
61-
assert script.count == {'error': 0, 'warning': 0, 'info': 0}
62-
assert script.get_report(False) == ''
63-
assert script.get_report(True) == ''
60+
assert str(script) == ""
61+
assert script.count == {"error": 0, "warning": 0, "info": 0}
62+
assert script.get_report(False) == ""
63+
assert script.get_report(True) == ""
6464

6565

6666
def test_script_all_errors():
6767
"""Tests on a script with all possible messages."""
68-
path = SCRIPTS_DIR / 'script_all_errors.py'
68+
path = SCRIPTS_DIR / "script_all_errors.py"
6969

7070
script = WeechatScript(path)
71-
assert str(script) == ''
71+
assert str(script) == ""
7272
assert script.path == path.resolve()
7373
assert script.ignored_msg == []
7474
assert script.msg_level == 2
7575
assert script.use_colors is True
7676
assert script.messages == []
77-
assert script.count == {'error': 0, 'warning': 0, 'info': 0}
77+
assert script.count == {"error": 0, "warning": 0, "info": 0}
7878
assert script.script
7979
script.check()
8080
assert str(script)
81-
assert len(str(script).split('\n')) == 13
82-
assert script.count == {'error': 3, 'warning': 8, 'info': 2}
83-
errors = [
84-
(msg.level, msg.line, msg.msg_name)
85-
for msg in script.messages
86-
]
81+
assert len(str(script).split("\n")) == 13
82+
assert script.count == {"error": 3, "warning": 8, "info": 2}
83+
errors = [(msg.level, msg.line, msg.msg_name) for msg in script.messages]
8784
assert errors == ALL_ERRORS
88-
assert len(script.get_report(False).split('\n')) == 13
89-
assert script.get_report(True) == 'script_all_errors.py'
85+
assert len(script.get_report(False).split("\n")) == 13
86+
assert script.get_report(True) == "script_all_errors.py"
9087

9188
# ignore 2 messages: "missing_email" and "sys_exit"
92-
script = WeechatScript(path, ignore='missing_email,sys_exit')
93-
assert str(script) == ''
89+
script = WeechatScript(path, ignore="missing_email,sys_exit")
90+
assert str(script) == ""
9491
assert script.path == path.resolve()
95-
assert script.ignored_msg == ['missing_email', 'sys_exit']
92+
assert script.ignored_msg == ["missing_email", "sys_exit"]
9693
assert script.msg_level == 2
9794
assert script.use_colors is True
9895
assert script.messages == []
99-
assert script.count == {'error': 0, 'warning': 0, 'info': 0}
96+
assert script.count == {"error": 0, "warning": 0, "info": 0}
10097
assert script.script
10198
script.check()
10299
assert str(script)
103-
assert len(str(script).split('\n')) == 11
104-
assert script.count == {'error': 2, 'warning': 7, 'info': 2}
105-
assert len(script.get_report(False).split('\n')) == 11
106-
assert script.get_report(True) == 'script_all_errors.py'
100+
assert len(str(script).split("\n")) == 11
101+
assert script.count == {"error": 2, "warning": 7, "info": 2}
102+
assert len(script.get_report(False).split("\n")) == 11
103+
assert script.get_report(True) == "script_all_errors.py"
107104

108105

109106
def test_script_empty_file():
110107
"""Tests on a script with all possible messages."""
111-
path = SCRIPTS_DIR / 'script_empty.py'
108+
path = SCRIPTS_DIR / "script_empty.py"
112109
script = WeechatScript(path)
113-
assert str(script) == ''
110+
assert str(script) == ""
114111
assert script.path == path.resolve()
115112
assert script.ignored_msg == []
116113
assert script.msg_level == 2
117114
assert script.use_colors is True
118115
assert script.messages == []
119-
assert script.count == {'error': 0, 'warning': 0, 'info': 0}
120-
assert script.script == ''
116+
assert script.count == {"error": 0, "warning": 0, "info": 0}
117+
assert script.script == ""
121118
script.check()
122119
assert str(script)
123-
assert script.count == {'error': 1, 'warning': 0, 'info': 0}
124-
assert len(script.get_report(False).split('\n')) == 1
125-
assert script.get_report(True) == 'script_empty.py'
120+
assert script.count == {"error": 1, "warning": 0, "info": 0}
121+
assert len(script.get_report(False).split("\n")) == 1
122+
assert script.get_report(True) == "script_empty.py"

0 commit comments

Comments
 (0)