Skip to content

Commit

Permalink
Run black
Browse files Browse the repository at this point in the history
  • Loading branch information
ndparker committed Oct 3, 2023
1 parent 56e71e3 commit 5078c56
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 54 deletions.
10 changes: 6 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@
import os as _os

import rjsmin as _rjsmin

# pylint: disable = protected-access
py_jsmin = _rjsmin._make_jsmin(python_only=True)
py_jsmin2 = _rjsmin.jsmin_for_posers

import _rjsmin

c_jsmin = _rjsmin.jsmin


def load(name):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'rb') as fp:
return fp.read()


def save(name, value):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'wb') as fp:
fp.write(value)


def test_basic():
""" Test basic.js """
"""Test basic.js"""
# pylint: disable = unidiomatic-typecheck

inp = load('js/basic.js')
Expand Down Expand Up @@ -81,7 +83,7 @@ def test_basic():


def test_basic_bang():
""" Test basic.js with bang comments """
"""Test basic.js with bang comments"""
inp = load('js/basic.js')
exp = load('js/basic.bang.js')
# save('js/basic.bang.js', py_jsmin(inp, keep_bang_comments=True))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_ctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@
from pytest import raises

import rjsmin as _rjsmin

# pylint: disable = protected-access
py_jsmin = _rjsmin._make_jsmin(python_only=True)
py_jsmin2 = _rjsmin.jsmin_for_posers

import _rjsmin

c_jsmin = _rjsmin.jsmin

from . import _util as _test


def test_keep_bang_comments():
""" keep_bang_comments argument error """
"""keep_bang_comments argument error"""
with raises(RuntimeError) as e:
c_jsmin('', keep_bang_comments=_test.badbool)
assert e.value.args == ('yoyo',)


def test_input_type():
""" input type must be a string or bytes """
"""input type must be a string or bytes"""
with raises(TypeError):
c_jsmin(None)

Expand Down
22 changes: 12 additions & 10 deletions tests/test_incomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@
import os as _os

import rjsmin as _rjsmin

# pylint: disable = protected-access
py_jsmin = _rjsmin._make_jsmin(python_only=True)
py_jsmin2 = _rjsmin.jsmin_for_posers

import _rjsmin

c_jsmin = _rjsmin.jsmin


def load(name):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'rb') as fp:
return fp.read()


def save(name, value):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'wb') as fp:
fp.write(value)


def test_string():
""" Test incomplete string """
"""Test incomplete string"""
inp = load('js/incomplete_string.js')
exp = load('js/incomplete_string.min.js')
# save('js/incomplete_string.min.js', py_jsmin(inp))
Expand All @@ -67,7 +69,7 @@ def test_string():


def test_regex():
""" Test incomplete regex """
"""Test incomplete regex"""
inp = load('js/incomplete_regex.js')
exp = load('js/incomplete_regex.min.js')
# save('js/incomplete_regex.min.js', py_jsmin(inp))
Expand All @@ -83,7 +85,7 @@ def test_regex():


def test_regex2():
""" Test incomplete regex """
"""Test incomplete regex"""
inp = load('js/incomplete_regex2.js')
exp = load('js/incomplete_regex2.min.js')
# save('js/incomplete_regex2.min.js', py_jsmin(inp))
Expand All @@ -99,7 +101,7 @@ def test_regex2():


def test_comment():
""" Test incomplete comment """
"""Test incomplete comment"""
inp = load('js/incomplete_comment.js')
exp = load('js/incomplete_comment.min.js')
# save('js/incomplete_comment.min.js', py_jsmin(inp))
Expand All @@ -115,7 +117,7 @@ def test_comment():


def test_comment2():
""" Test incomplete comment """
"""Test incomplete comment"""
inp = load('js/incomplete_comment2.js')
exp = load('js/incomplete_comment2.min.js')
# save('js/incomplete_comment2.min.js', py_jsmin(inp))
Expand All @@ -131,7 +133,7 @@ def test_comment2():


def test_comment_bang():
""" Test incomplete bang comment """
"""Test incomplete bang comment"""
inp = load('js/incomplete_bang_comment.js')
exp = load('js/incomplete_bang_comment.min.js')
# save('js/incomplete_bang_comment.min.js',
Expand All @@ -148,7 +150,7 @@ def test_comment_bang():


def test_comment_bang2():
""" Test incomplete bang comment """
"""Test incomplete bang comment"""
inp = load('js/incomplete_bang_comment2.js')
exp = load('js/incomplete_bang_comment2.min.js')
# save('js/incomplete_bang_comment2.min.js',
Expand All @@ -165,7 +167,7 @@ def test_comment_bang2():


def test_slash():
""" Test lone slash """
"""Test lone slash"""
inp = load('js/lone_slash.js')
exp = load('js/lone_slash.min.js')
# save('js/lone_slash.min.js', py_jsmin(inp))
Expand Down
10 changes: 6 additions & 4 deletions tests/test_issue13.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@
import os as _os

import rjsmin as _rjsmin

# pylint: disable = protected-access
py_jsmin = _rjsmin._make_jsmin(python_only=True)
py_jsmin2 = _rjsmin.jsmin_for_posers

import _rjsmin

c_jsmin = _rjsmin.jsmin


def load(name):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'rb') as fp:
return fp.read()


def save(name, value):
""" Load a file """
"""Load a file"""
with open(_os.path.join(_os.path.dirname(__file__), name), 'wb') as fp:
fp.write(value)


def test_issue():
""" Test issue """
"""Test issue"""
inp = load('js/issue13.js')
exp = load('js/issue13.min.js')
# save('js/issue13.min.js', py_jsmin(inp))
Expand All @@ -67,7 +69,7 @@ def test_issue():


def test_issue_bang():
""" Test issue with bang comments """
"""Test issue with bang comments"""
inp = load('js/issue13.js')
exp = load('js/issue13.bang.js')
# save('js/issue13.bang.js', py_jsmin(inp, keep_bang_comments=True))
Expand Down
78 changes: 48 additions & 30 deletions tests/test_issue17.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@
__author__ = u"Andr\xe9 Malo"

import rjsmin as _rjsmin

# pylint: disable = protected-access
py_jsmin = _rjsmin._make_jsmin(python_only=True)
py_jsmin2 = _rjsmin.jsmin_for_posers

import _rjsmin

c_jsmin = _rjsmin.jsmin


def test_non_issue():
""" Test issue """
"""Test issue"""
inp = b'console.write((f++)/ 4 + 3 / 2)'
exp = b'console.write((f++)/4+3/2)'

Expand All @@ -53,7 +55,7 @@ def test_non_issue():


def test_non_issue_bang():
""" Test issue with bang comments """
"""Test issue with bang comments"""
inp = b'console.write((f++)/ 4 + 3 / 2)'
exp = b'console.write((f++)/4+3/2)'

Expand All @@ -69,11 +71,15 @@ def test_non_issue_bang():


def test_non_issue2():
""" Test issue """
inp = (b'if (Y) { ba=Math.max(ba, Math.round(W.minHeight/Y))}; '
b'bo.setKnobFactor((bp.width===0)? 0: br.width /bp.width);')
exp = (b'if(Y){ba=Math.max(ba,Math.round(W.minHeight/Y))};'
b'bo.setKnobFactor((bp.width===0)?0:br.width/bp.width);')
"""Test issue"""
inp = (
b'if (Y) { ba=Math.max(ba, Math.round(W.minHeight/Y))}; '
b'bo.setKnobFactor((bp.width===0)? 0: br.width /bp.width);'
)
exp = (
b'if(Y){ba=Math.max(ba,Math.round(W.minHeight/Y))};'
b'bo.setKnobFactor((bp.width===0)?0:br.width/bp.width);'
)

assert py_jsmin(inp) == exp
assert py_jsmin2(inp) == exp
Expand All @@ -87,11 +93,15 @@ def test_non_issue2():


def test_non_issue2_bang():
""" Test issue """
inp = (b'if (Y) { ba=Math.max(ba, Math.round(W.minHeight/Y))}; '
b'bo.setKnobFactor((bp.width===0)? 0: br.width /bp.width);')
exp = (b'if(Y){ba=Math.max(ba,Math.round(W.minHeight/Y))};'
b'bo.setKnobFactor((bp.width===0)?0:br.width/bp.width);')
"""Test issue"""
inp = (
b'if (Y) { ba=Math.max(ba, Math.round(W.minHeight/Y))}; '
b'bo.setKnobFactor((bp.width===0)? 0: br.width /bp.width);'
)
exp = (
b'if(Y){ba=Math.max(ba,Math.round(W.minHeight/Y))};'
b'bo.setKnobFactor((bp.width===0)?0:br.width/bp.width);'
)

assert py_jsmin(inp, keep_bang_comments=True) == exp
assert py_jsmin2(inp, keep_bang_comments=True) == exp
Expand All @@ -105,9 +115,11 @@ def test_non_issue2_bang():


def test_non_issue_complex():
""" Test issue """
inp = (b'console.write((f++)/*!dude*// 4 + 3 /a /* lalala */ '
b'/*!lololo*// 2)')
"""Test issue"""
inp = (
b'console.write((f++)/*!dude*// 4 + 3 /a /* lalala */ '
b'/*!lololo*// 2)'
)
exp = b'console.write((f++)/4+3/a/2)'

assert py_jsmin(inp) == exp
Expand All @@ -122,9 +134,11 @@ def test_non_issue_complex():


def test_non_issue_complex_bang():
""" Test issue with bang comments """
inp = (b'console.write((f++)/*!dude*// 4 + 3 /a /* lalala */ '
b'/*!lololo*// 2)')
"""Test issue with bang comments"""
inp = (
b'console.write((f++)/*!dude*// 4 + 3 /a /* lalala */ '
b'/*!lololo*// 2)'
)
exp = b'console.write((f++)/*!dude*//4+3/a/*!lololo*//2)'

assert py_jsmin(inp, keep_bang_comments=True) == exp
Expand All @@ -139,7 +153,7 @@ def test_non_issue_complex_bang():


def test_issue():
""" Test issue """
"""Test issue"""
inp = b'for(f=0;f<z;f++)/^ *-+: *$/.test(x)'
exp = b'for(f=0;f<z;f++)/^ *-+: *$/.test(x)'

Expand All @@ -155,7 +169,7 @@ def test_issue():


def test_issue_bang():
""" Test issue with bang comments """
"""Test issue with bang comments"""
inp = b'for(f=0;f<z;f++)/^ *-+: *$/.test(x)'
exp = b'for(f=0;f<z;f++)/^ *-+: *$/.test(x)'

Expand All @@ -171,9 +185,11 @@ def test_issue_bang():


def test_issue_complex():
""" Test issue """
inp = (b'for(f=0;f<z;f++)/*!dude*//^ *-+: *$/i/*haha*//*!hoho*/\n'
b'./*!hihi*/\n/*huhu*/test(x)')
"""Test issue"""
inp = (
b'for(f=0;f<z;f++)/*!dude*//^ *-+: *$/i/*haha*//*!hoho*/\n'
b'./*!hihi*/\n/*huhu*/test(x)'
)
exp = b'for(f=0;f<z;f++)/^ *-+: *$/i.test(x)'

assert py_jsmin(inp) == exp
Expand All @@ -188,9 +204,11 @@ def test_issue_complex():


def test_issue_complex_bang():
""" Test issue with bang comments """
inp = (b'for(f=0;f<z;f++)/*!dude*//^ *-+: *$/i/*haha*//*!hoho*/\n'
b'./*!hihi*/\n/*huhu*/test(x)')
"""Test issue with bang comments"""
inp = (
b'for(f=0;f<z;f++)/*!dude*//^ *-+: *$/i/*haha*//*!hoho*/\n'
b'./*!hihi*/\n/*huhu*/test(x)'
)
exp = b'for(f=0;f<z;f++)/*!dude*//^ *-+: *$/i/*!hoho*/./*!hihi*/test(x)'

assert py_jsmin(inp, keep_bang_comments=True) == exp
Expand All @@ -205,7 +223,7 @@ def test_issue_complex_bang():


def test_issue_error1():
""" Test issue """
"""Test issue"""
inp = b'for(f=0;f<z;f++)/^ *-+: *$//*'
exp = b'for(f=0;f<z;f++)/^*-+:*$'

Expand All @@ -221,7 +239,7 @@ def test_issue_error1():


def test_issue_error2():
""" Test issue """
"""Test issue"""
inp = b'for(f=0;f<z;f++)/'
exp = b'for(f=0;f<z;f++)/'

Expand All @@ -237,7 +255,7 @@ def test_issue_error2():


def test_issue_error3():
""" Test issue """
"""Test issue"""
inp = b'for(f=0;f<z;f++)/^ *-+: *$/./'
exp = b'for(f=0;f<z;f++)/^*-+:*$/./'

Expand All @@ -253,7 +271,7 @@ def test_issue_error3():


def test_issue_error4():
""" Test issue """
"""Test issue"""
inp = b'for(f=0;f<z;f++)/^ *-+: *$/."lalala"'
exp = b'for(f=0;f<z;f++)/^*-+:*$/."lalala"'

Expand Down
Loading

0 comments on commit 5078c56

Please sign in to comment.