mirror of https://github.com/yandex/gixy
Add Python 3.9 to 3.13 support, Drop all other version
* Remove __future__ imports * Use relative imports * Remove six * Remove argparse * Replace nose with pynose * Replace deprecated testing functions * Fix flake8 warnings * Update dependency info in requirements, setup.py and rpmspecpull/148/head
parent
6f68624a75
commit
2c789d9684
|
@ -1,7 +1,7 @@
|
|||
# flake8: noqa
|
||||
|
||||
from configargparse import *
|
||||
from six.moves import StringIO
|
||||
from io import StringIO
|
||||
|
||||
from gixy.core.plugins_manager import PluginsManager
|
||||
|
||||
|
@ -119,7 +119,8 @@ class ArgsParser(ArgumentParser):
|
|||
config_file_keys = self.get_possible_config_keys(action)
|
||||
if config_file_keys and not action.is_positional_arg and \
|
||||
already_on_command_line(existing_command_line_args,
|
||||
action.option_strings):
|
||||
action.option_strings,
|
||||
self.prefix_chars):
|
||||
value = getattr(parsed_namespace, action.dest, None)
|
||||
if value is not None:
|
||||
if type(value) is bool:
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import six
|
||||
import logging
|
||||
import re
|
||||
import random
|
||||
|
@ -13,7 +12,7 @@ LOG = logging.getLogger(__name__)
|
|||
def _build_reverse_list(original):
|
||||
result = []
|
||||
for c in range(1, 126):
|
||||
c = six.unichr(c)
|
||||
c = chr(c)
|
||||
if c not in original:
|
||||
result.append(c)
|
||||
return frozenset(result)
|
||||
|
@ -35,7 +34,7 @@ CATEGORIES = {
|
|||
'0123456789_')),
|
||||
sre_parse.CATEGORY_LINEBREAK: frozenset('\n'),
|
||||
sre_parse.CATEGORY_NOT_LINEBREAK: _build_reverse_list(frozenset('\n')),
|
||||
'ANY': [six.unichr(x) for x in range(1, 127) if x != 10]
|
||||
'ANY': [chr(x) for x in range(1, 127) if x != 10]
|
||||
}
|
||||
|
||||
CATEGORIES_NAMES = {
|
||||
|
@ -94,10 +93,10 @@ def _gen_combinator(variants, _merge=True):
|
|||
producted = itertools.product(*res)
|
||||
if _merge:
|
||||
# TODO(buglloc): ??!
|
||||
return list(six.moves.map(_merge_variants, producted))
|
||||
return list(map(_merge_variants, producted))
|
||||
return producted
|
||||
elif _merge:
|
||||
return list(six.moves.map(_merge_variants, [res]))
|
||||
return list(map(_merge_variants, [res]))
|
||||
return res
|
||||
|
||||
|
||||
|
@ -178,7 +177,7 @@ class LiteralToken(Token):
|
|||
type = sre_parse.LITERAL
|
||||
|
||||
def _parse(self):
|
||||
self.char = six.unichr(self.token[1])
|
||||
self.char = chr(self.token[1])
|
||||
|
||||
def can_contain(self, char, skip_literal=True):
|
||||
if skip_literal:
|
||||
|
@ -199,7 +198,7 @@ class NotLiteralToken(Token):
|
|||
type = sre_parse.NOT_LITERAL
|
||||
|
||||
def _parse(self):
|
||||
self.char = six.unichr(self.token[1])
|
||||
self.char = chr(self.token[1])
|
||||
self.gen_char_list = list(_build_reverse_list(frozenset(self.char)))
|
||||
|
||||
def can_contain(self, char, skip_literal=True):
|
||||
|
@ -225,8 +224,8 @@ class RangeToken(Token):
|
|||
def _parse(self):
|
||||
self.left_code = self.token[1][0]
|
||||
self.right_code = self.token[1][1]
|
||||
self.left = six.unichr(self.left_code)
|
||||
self.right = six.unichr(self.right_code)
|
||||
self.left = chr(self.left_code)
|
||||
self.right = chr(self.right_code)
|
||||
|
||||
def can_contain(self, char, skip_literal=True):
|
||||
return self.left <= char <= self.right
|
||||
|
@ -238,7 +237,7 @@ class RangeToken(Token):
|
|||
if self.can_contain(context.char):
|
||||
return context.char
|
||||
|
||||
return six.unichr(random.randint(self.token[1][0], self.token[1][1]))
|
||||
return chr(random.randint(self.token[1][0], self.token[1][1]))
|
||||
|
||||
def __str__(self):
|
||||
return '{left}-{right}'.format(left=self.left, right=self.right)
|
||||
|
@ -657,7 +656,7 @@ class InToken(Token):
|
|||
elif isinstance(child, LiteralToken):
|
||||
blacklisted.add(child.char)
|
||||
elif isinstance(child, RangeToken):
|
||||
blacklisted.update(six.unichr(c) for c in six.moves.range(child.left_code, child.right_code + 1))
|
||||
blacklisted.update(chr(c) for c in range(child.left_code, child.right_code + 1))
|
||||
elif isinstance(child, CategoryToken):
|
||||
blacklisted.update(child.char_list)
|
||||
else:
|
||||
|
|
|
@ -10,11 +10,9 @@
|
|||
# See the sre.py file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
"""Internal support module for sre"""
|
||||
|
||||
from sre_constants import *
|
||||
from .sre_constants import *
|
||||
|
||||
SPECIAL_CHARS = ".\\[{()*+?^$|"
|
||||
REPEAT_CHARS = "*+?{"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from jinja2 import Environment, PackageLoader
|
||||
|
||||
from gixy.utils.text import to_text
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import gixy
|
||||
from gixy.directives import block
|
||||
|
||||
|
@ -74,10 +72,10 @@ class BaseFormatter(object):
|
|||
for leap in tree.children:
|
||||
if leap not in points:
|
||||
continue
|
||||
printable = type(leap) not in self.skip_parents
|
||||
printable = all(not isinstance(leap, p) for p in self.skip_parents)
|
||||
# Special hack for includes
|
||||
# TODO(buglloc): fix me
|
||||
have_parentheses = type(leap) != block.IncludeBlock
|
||||
have_parentheses = not isinstance(leap, block.IncludeBlock)
|
||||
|
||||
if printable:
|
||||
if leap.is_block:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from gixy.formatters.base import BaseFormatter
|
||||
from gixy.formatters._jinja import load_template
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
from gixy.formatters.base import BaseFormatter
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from gixy.formatters.base import BaseFormatter
|
||||
from gixy.formatters._jinja import load_template
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import logging
|
||||
import codecs
|
||||
import six
|
||||
import re
|
||||
from cached_property import cached_property
|
||||
|
||||
from pyparsing import (
|
||||
Literal, Suppress, White, Word, alphanums, Forward, Group, Optional, Combine,
|
||||
Literal, Suppress, Word, alphanums, Forward, Group, Optional, Combine,
|
||||
Keyword, OneOrMore, ZeroOrMore, Regex, QuotedString, nestedExpr, ParseResults)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -17,7 +17,7 @@ class NginxQuotedString(QuotedString):
|
|||
# '^https?:\/\/yandex\.ru\/\00\'\"' -> ^https?:\/\/yandex\.ru\/\00'"
|
||||
# TODO(buglloc): research and find another special characters!
|
||||
|
||||
self.escCharReplacePattern = '\\\\(\'|")'
|
||||
self.unquote_scan_re = re.compile("(\\\\t|\\\\r|\\\\n)|(\\\\\"|\\\\')|(\\n|.)")
|
||||
|
||||
|
||||
class RawParser(object):
|
||||
|
@ -29,7 +29,7 @@ class RawParser(object):
|
|||
"""
|
||||
Returns the parsed tree.
|
||||
"""
|
||||
if isinstance(data, six.binary_type):
|
||||
if isinstance(data, bytes):
|
||||
if data[:3] == codecs.BOM_UTF8:
|
||||
encoding = 'utf-8-sig'
|
||||
else:
|
||||
|
@ -49,7 +49,6 @@ class RawParser(object):
|
|||
left_bracket = Suppress("{")
|
||||
right_bracket = Suppress("}")
|
||||
semicolon = Suppress(";")
|
||||
space = White().suppress()
|
||||
keyword = Word(alphanums + ".+-_/")
|
||||
path = Word(alphanums + ".-_/")
|
||||
variable = Word("$_-" + alphanums)
|
||||
|
@ -71,23 +70,22 @@ class RawParser(object):
|
|||
# so we capture all content between parentheses and then parse it :(
|
||||
# TODO(buglloc): may be use something better?
|
||||
condition_body = (
|
||||
(if_modifier + Optional(space) + value) |
|
||||
(variable + Optional(space + if_modifier + Optional(space) + value))
|
||||
(if_modifier + value) |
|
||||
(variable + Optional(if_modifier + value))
|
||||
)
|
||||
condition = Regex(r'\((?:[^()\n\r\\]|(?:\(.*\))|(?:\\.))+?\)')\
|
||||
.setParseAction(lambda s, l, t: condition_body.parseString(t[0][1:-1]))
|
||||
.setParseAction(lambda s, loc, toks: condition_body.parseString(toks[0][1:-1]))
|
||||
|
||||
# rules
|
||||
include = (
|
||||
Keyword("include") +
|
||||
space +
|
||||
value +
|
||||
semicolon
|
||||
)("include")
|
||||
|
||||
directive = (
|
||||
keyword +
|
||||
ZeroOrMore(space + value) +
|
||||
ZeroOrMore(value) +
|
||||
semicolon
|
||||
)("directive")
|
||||
|
||||
|
@ -103,7 +101,7 @@ class RawParser(object):
|
|||
|
||||
hash_value = Group(
|
||||
value +
|
||||
ZeroOrMore(space + value) +
|
||||
ZeroOrMore(value) +
|
||||
semicolon
|
||||
)("hash_value")
|
||||
|
||||
|
@ -136,8 +134,7 @@ class RawParser(object):
|
|||
location_block << (
|
||||
Keyword("location") +
|
||||
Group(
|
||||
Optional(space + location_modifier) +
|
||||
Optional(space) + value) +
|
||||
Optional(location_modifier) + value) +
|
||||
Suppress(Optional(comment)) +
|
||||
Group(
|
||||
left_bracket +
|
||||
|
@ -147,7 +144,7 @@ class RawParser(object):
|
|||
|
||||
hash_block << (
|
||||
keyword +
|
||||
Group(OneOrMore(space + value)) +
|
||||
Group(OneOrMore(value)) +
|
||||
Group(
|
||||
left_bracket +
|
||||
Optional(OneOrMore(hash_value)) +
|
||||
|
@ -156,7 +153,7 @@ class RawParser(object):
|
|||
|
||||
generic_block << (
|
||||
keyword +
|
||||
Group(ZeroOrMore(space + value)) +
|
||||
Group(ZeroOrMore(value)) +
|
||||
Suppress(Optional(comment)) +
|
||||
Group(
|
||||
left_bracket +
|
||||
|
@ -166,7 +163,7 @@ class RawParser(object):
|
|||
|
||||
unparsed_block << (
|
||||
keyword +
|
||||
Group(ZeroOrMore(space + value)) +
|
||||
Group(ZeroOrMore(value)) +
|
||||
nestedExpr(opener="{", closer="}")
|
||||
)("unparsed_block")
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from six import PY3, text_type, binary_type
|
||||
|
||||
|
||||
def to_bytes(obj, encoding='latin1', errors='strict', nonstring='replace'):
|
||||
if isinstance(obj, binary_type):
|
||||
if isinstance(obj, bytes):
|
||||
return obj
|
||||
|
||||
if isinstance(obj, text_type):
|
||||
if isinstance(obj, str):
|
||||
try:
|
||||
# Try this first as it's the fastest
|
||||
return obj.encode(encoding, errors)
|
||||
|
@ -36,10 +32,10 @@ def to_bytes(obj, encoding='latin1', errors='strict', nonstring='replace'):
|
|||
|
||||
|
||||
def to_text(obj, encoding='latin1', errors='strict', nonstring='replace'):
|
||||
if isinstance(obj, text_type):
|
||||
if isinstance(obj, str):
|
||||
return obj
|
||||
|
||||
if isinstance(obj, binary_type):
|
||||
if isinstance(obj, bytes):
|
||||
try:
|
||||
return obj.decode(encoding, errors)
|
||||
except UnicodeEncodeError:
|
||||
|
@ -66,7 +62,4 @@ def to_text(obj, encoding='latin1', errors='strict', nonstring='replace'):
|
|||
return to_text(value, encoding, errors)
|
||||
|
||||
|
||||
if PY3:
|
||||
to_native = to_text
|
||||
else:
|
||||
to_native = to_bytes
|
||||
to_native = to_text
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
nose>=1.3.7
|
||||
mock>=2.0.0
|
||||
coverage>=4.3
|
||||
flake8>=3.2
|
||||
tox>=2.7.0
|
||||
pynose>=1.5.4
|
||||
mock>=5.2.0
|
||||
coverage>=7.7.0
|
||||
flake8>=7.1.2
|
||||
tox>=4.24.2
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
pyparsing>=1.5.5,<3
|
||||
cached-property>=1.2.0
|
||||
argparse>=1.4.0
|
||||
six>=1.1.0
|
||||
Jinja2>=2.8
|
||||
ConfigArgParse>=0.11.0
|
||||
pyparsing>=3.2.1
|
||||
cached-property>=2.0.1
|
||||
Jinja2>=3.1.5
|
||||
ConfigArgParse>=1.7
|
||||
|
|
|
@ -14,11 +14,14 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
|||
|
||||
BuildArch: noarch
|
||||
|
||||
BuildRequires: python-devel python-setuptools
|
||||
BuildRequires: python-devel
|
||||
BuildRequires: python-setuptools
|
||||
|
||||
Requires: python-setuptools python-six >= 1.1.0 python-jinja >= 2.8
|
||||
Requires: python2-cached_property >= 1.2.0 python2-configargparse >= 0.11.0
|
||||
Requires: python-argparse >= 1.4.0 pyparsing >= 1.5.5 python-markupsafe
|
||||
Requires: python-setuptools
|
||||
Requires: python-jinja >= 3.1.5
|
||||
Requires: python-cached_property >= 2.0.1
|
||||
Requires: python2-configargparse >= 1.7
|
||||
Requires: pyparsing >= 3.2.1
|
||||
|
||||
Provides: %{name} = %{verion}-%{release}
|
||||
|
||||
|
|
19
setup.py
19
setup.py
|
@ -16,13 +16,12 @@ setup(
|
|||
author='Yandex IS Team',
|
||||
author_email='buglloc@yandex.ru',
|
||||
url='https://github.com/yandex/gixy',
|
||||
python_requires='>=3.9',
|
||||
install_requires=[
|
||||
'pyparsing>=1.5.5,<3',
|
||||
'cached-property>=1.2.0',
|
||||
'argparse>=1.4.0;python_version<"3.2"',
|
||||
'six>=1.1.0',
|
||||
'Jinja2>=2.8',
|
||||
'ConfigArgParse>=0.11.0'
|
||||
'pyparsing>=3.2.1',
|
||||
'cached-property>=2.0.1',
|
||||
'Jinja2>=3.1.5',
|
||||
'ConfigArgParse>=1.7'
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': ['gixy=gixy.cli.main:main'],
|
||||
|
@ -36,7 +35,13 @@ setup(
|
|||
'Intended Audience :: Developers',
|
||||
'Topic :: Security',
|
||||
'Topic :: Software Development :: Quality Assurance',
|
||||
'Topic :: Software Development :: Testing'
|
||||
'Topic :: Software Development :: Testing',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3 :: 3.9',
|
||||
'Programming Language :: Python :: 3 :: 3.10',
|
||||
'Programming Language :: Python :: 3 :: 3.11',
|
||||
'Programming Language :: Python :: 3 :: 3.12',
|
||||
'Programming Language :: Python :: 3 :: 3.13',
|
||||
],
|
||||
include_package_data=True
|
||||
)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from nose.tools import with_setup, assert_equals, assert_not_equals, assert_true
|
||||
from gixy.core.context import get_context, pop_context, push_context, purge_context, CONTEXTS, Context
|
||||
from nose.tools import with_setup, assert_equal, assert_not_equal, assert_true
|
||||
from gixy.core.context import get_context, pop_context, push_context, purge_context, CONTEXTS
|
||||
from gixy.directives.block import Root
|
||||
from gixy.core.variable import Variable
|
||||
from gixy.core.regexp import Regexp
|
||||
|
||||
|
||||
def setup():
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert_equal(len(CONTEXTS), 0)
|
||||
|
||||
|
||||
def tear_down():
|
||||
|
@ -17,39 +17,39 @@ def tear_down():
|
|||
def test_push_pop_context():
|
||||
root_a = Root()
|
||||
push_context(root_a)
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert_equal(len(CONTEXTS), 1)
|
||||
root_b = Root()
|
||||
push_context(root_b)
|
||||
assert_equals(len(CONTEXTS), 2)
|
||||
assert_equal(len(CONTEXTS), 2)
|
||||
|
||||
poped = pop_context()
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert_equals(poped.block, root_b)
|
||||
assert_equal(len(CONTEXTS), 1)
|
||||
assert_equal(poped.block, root_b)
|
||||
poped = pop_context()
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert_equals(poped.block, root_a)
|
||||
assert_equal(len(CONTEXTS), 0)
|
||||
assert_equal(poped.block, root_a)
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_push_get_purge_context():
|
||||
root = Root()
|
||||
push_context(root)
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert_equals(get_context().block, root)
|
||||
assert_equal(len(CONTEXTS), 1)
|
||||
assert_equal(get_context().block, root)
|
||||
root = Root()
|
||||
push_context(root)
|
||||
assert_equals(len(CONTEXTS), 2)
|
||||
assert_equals(get_context().block, root)
|
||||
assert_equal(len(CONTEXTS), 2)
|
||||
assert_equal(get_context().block, root)
|
||||
|
||||
purge_context()
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert_equal(len(CONTEXTS), 0)
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_add_variables():
|
||||
context = push_context(Root())
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 0)
|
||||
assert_equal(len(context.variables['index']), 0)
|
||||
assert_equal(len(context.variables['name']), 0)
|
||||
|
||||
one_str_var = Variable('1')
|
||||
context.add_var('1', one_str_var)
|
||||
|
@ -58,32 +58,32 @@ def test_add_variables():
|
|||
some_var = Variable('some')
|
||||
context.add_var('some', some_var)
|
||||
|
||||
assert_equals(len(context.variables['index']), 1)
|
||||
assert_equals(context.variables['index'][1], one_int_var)
|
||||
assert_equals(len(context.variables['name']), 1)
|
||||
assert_equals(context.variables['name']['some'], some_var)
|
||||
assert_equal(len(context.variables['index']), 1)
|
||||
assert_equal(context.variables['index'][1], one_int_var)
|
||||
assert_equal(len(context.variables['name']), 1)
|
||||
assert_equal(context.variables['name']['some'], some_var)
|
||||
context.clear_index_vars()
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 1)
|
||||
assert_equals(context.variables['name']['some'], some_var)
|
||||
assert_equal(len(context.variables['index']), 0)
|
||||
assert_equal(len(context.variables['name']), 1)
|
||||
assert_equal(context.variables['name']['some'], some_var)
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_get_variables():
|
||||
context = push_context(Root())
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 0)
|
||||
assert_equal(len(context.variables['index']), 0)
|
||||
assert_equal(len(context.variables['name']), 0)
|
||||
|
||||
one_var = Variable(1)
|
||||
context.add_var(1, one_var)
|
||||
some_var = Variable('some')
|
||||
context.add_var('some', some_var)
|
||||
|
||||
assert_equals(context.get_var(1), one_var)
|
||||
assert_equals(context.get_var('some'), some_var)
|
||||
assert_equal(context.get_var(1), one_var)
|
||||
assert_equal(context.get_var('some'), some_var)
|
||||
# Checks not existed variables, for now context may return None
|
||||
assert_equals(context.get_var(0), None)
|
||||
assert_equals(context.get_var('not_existed'), None)
|
||||
assert_equal(context.get_var(0), None)
|
||||
assert_equal(context.get_var('not_existed'), None)
|
||||
# Checks builtins variables
|
||||
assert_true(context.get_var('uri'))
|
||||
assert_true(context.get_var('document_uri'))
|
||||
|
@ -94,41 +94,41 @@ def test_get_variables():
|
|||
@with_setup(setup, tear_down)
|
||||
def test_context_depend_variables():
|
||||
push_context(Root())
|
||||
assert_equals(len(get_context().variables['index']), 0)
|
||||
assert_equals(len(get_context().variables['name']), 0)
|
||||
assert_equal(len(get_context().variables['index']), 0)
|
||||
assert_equal(len(get_context().variables['name']), 0)
|
||||
|
||||
get_context().add_var(1, Variable(1, value='one'))
|
||||
get_context().add_var('some', Variable('some', value='some'))
|
||||
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equal(get_context().get_var(1).value, 'one')
|
||||
assert_equal(get_context().get_var('some').value, 'some')
|
||||
|
||||
# Checks top context variables are still exists
|
||||
push_context(Root())
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equal(get_context().get_var(1).value, 'one')
|
||||
assert_equal(get_context().get_var('some').value, 'some')
|
||||
|
||||
# Checks variable overriding
|
||||
get_context().add_var('some', Variable('some', value='some_new'))
|
||||
get_context().add_var('foo', Variable('foo', value='foo'))
|
||||
assert_not_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equals(get_context().get_var('some').value, 'some_new')
|
||||
assert_equals(get_context().get_var('foo').value, 'foo')
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_not_equal(get_context().get_var('some').value, 'some')
|
||||
assert_equal(get_context().get_var('some').value, 'some_new')
|
||||
assert_equal(get_context().get_var('foo').value, 'foo')
|
||||
assert_equal(get_context().get_var(1).value, 'one')
|
||||
|
||||
# Checks variables after restore previous context
|
||||
pop_context()
|
||||
assert_not_equals(get_context().get_var('some').value, 'some_new')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equals(get_context().get_var('foo'), None)
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_not_equal(get_context().get_var('some').value, 'some_new')
|
||||
assert_equal(get_context().get_var('some').value, 'some')
|
||||
assert_equal(get_context().get_var('foo'), None)
|
||||
assert_equal(get_context().get_var(1).value, 'one')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_push_failed_with_regexp_py35_gixy_10():
|
||||
push_context(Root())
|
||||
assert_equals(len(get_context().variables['index']), 0)
|
||||
assert_equals(len(get_context().variables['name']), 0)
|
||||
assert_equal(len(get_context().variables['index']), 0)
|
||||
assert_equal(len(get_context().variables['name']), 0)
|
||||
|
||||
regexp = Regexp('^/some/(.*?)')
|
||||
for name, group in regexp.groups.items():
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from nose.tools import assert_true, assert_false, assert_equals
|
||||
from nose.tools import assert_true, assert_false, assert_equal
|
||||
from gixy.core.regexp import Regexp
|
||||
|
||||
'''
|
||||
|
@ -88,7 +88,7 @@ def test_to_string():
|
|||
(r'foo', 'foo'),
|
||||
(r'(1)(2)(?:3)', '(1)(2)(?:3)'),
|
||||
(r'(1)((2)|(?:3))', '(1)((?:(2)|(?:3)))'),
|
||||
(r'\w|1|3-5|[a-z]', '(?:[\w]|1|3\\-5|[a-z])'),
|
||||
(r'\w|1|3-5|[a-z]', '(?:[\\w]|1|3\\-5|[a-z])'),
|
||||
(r'(1|(?:3)|([4-6]))', '((?:1|(?:3)|([4-6])))'),
|
||||
(r'(1|(?:3)|(?P<aaa>[4-6]))', '((?:1|(?:3)|([4-6])))'),
|
||||
(r'^sss', '^sss'),
|
||||
|
@ -258,26 +258,26 @@ def test_generate():
|
|||
|
||||
def test_strict_generate():
|
||||
reg = Regexp('^foo|bar', strict=True)
|
||||
assert_equals(sorted(reg.generate('|', anchored=True)), sorted(['^foo', '^bar']))
|
||||
assert_equal(sorted(reg.generate('|', anchored=True)), sorted(['^foo', '^bar']))
|
||||
|
||||
|
||||
def test_gen_anchor():
|
||||
|
||||
reg = Regexp('^some$')
|
||||
val = next(reg.generate('', anchored=False))
|
||||
assert_equals(val, 'some')
|
||||
assert_equal(val, 'some')
|
||||
|
||||
reg = Regexp('^some$')
|
||||
val = next(reg.generate('', anchored=True))
|
||||
assert_equals(val, '^some$')
|
||||
assert_equal(val, '^some$')
|
||||
|
||||
reg = Regexp('^some$', strict=True)
|
||||
val = next(reg.generate('', anchored=False))
|
||||
assert_equals(val, 'some')
|
||||
assert_equal(val, 'some')
|
||||
|
||||
reg = Regexp('^some$', strict=True)
|
||||
val = next(reg.generate('', anchored=True))
|
||||
assert_equals(val, '^some$')
|
||||
assert_equal(val, '^some$')
|
||||
|
||||
|
||||
def test_group_can_contains():
|
||||
|
@ -345,12 +345,12 @@ def check_negative_startswith(regexp, char, strict):
|
|||
|
||||
def check_groups_names(regexp, groups):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(set(reg.groups.keys()), set(groups))
|
||||
assert_equal(set(reg.groups.keys()), set(groups))
|
||||
|
||||
|
||||
def check_to_string(regexp, string):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(str(reg), string)
|
||||
assert_equal(str(reg), string)
|
||||
|
||||
|
||||
def check_positive_must_contain(regexp, char):
|
||||
|
@ -399,4 +399,4 @@ def check_negative_must_startswith(regexp, char, strict):
|
|||
|
||||
def check_generate(regexp, values):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(sorted(reg.generate('|', anchored=True)), sorted(values))
|
||||
assert_equal(sorted(reg.generate('|', anchored=True)), sorted(values))
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from nose.tools import assert_true, assert_false, assert_equals, with_setup
|
||||
from nose.tools import assert_true, assert_false, assert_equal, with_setup
|
||||
from gixy.core.context import get_context, push_context, purge_context
|
||||
from gixy.directives.block import Root
|
||||
from gixy.core.regexp import Regexp
|
||||
from gixy.core.variable import Variable
|
||||
|
||||
|
||||
def setup():
|
||||
push_context(Root())
|
||||
|
||||
|
@ -17,7 +18,7 @@ def test_literal():
|
|||
var = Variable(name='simple', value='$uri', have_script=False)
|
||||
assert_false(var.depends)
|
||||
assert_false(var.regexp)
|
||||
assert_equals(var.value, '$uri')
|
||||
assert_equal(var.value, '$uri')
|
||||
|
||||
assert_false(var.can_startswith('$'))
|
||||
assert_false(var.can_contain('i'))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from nose.tools import assert_equals, assert_true, assert_false
|
||||
from nose.tools import assert_equal, assert_true, assert_false
|
||||
from tests.asserts import assert_is_instance, assert_is_none, assert_is_not_none
|
||||
from gixy.parser.nginx_parser import NginxParser
|
||||
from gixy.directives.block import *
|
||||
from gixy.directives.block import Block, HttpBlock, ServerBlock, LocationBlock, IfBlock, MapBlock, GeoBlock
|
||||
|
||||
|
||||
# TODO(buglloc): what about include block?
|
||||
|
||||
|
@ -51,7 +52,7 @@ server {
|
|||
assert_is_instance(directive, ServerBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_true(directive.self_context)
|
||||
assert_equals([d.args[0] for d in directive.get_names()], ['_', 'cool.io'])
|
||||
assert_equal([d.args[0] for d in directive.get_names()], ['_', 'cool.io'])
|
||||
assert_false(directive.provide_variables)
|
||||
|
||||
|
||||
|
@ -67,7 +68,7 @@ location / {
|
|||
assert_true(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_is_none(directive.modifier)
|
||||
assert_equals(directive.path, '/')
|
||||
assert_equal(directive.path, '/')
|
||||
assert_false(directive.is_internal)
|
||||
|
||||
|
||||
|
@ -91,8 +92,8 @@ location = / {
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, LocationBlock)
|
||||
assert_equals(directive.modifier, '=')
|
||||
assert_equals(directive.path, '/')
|
||||
assert_equal(directive.modifier, '=')
|
||||
assert_equal(directive.path, '/')
|
||||
|
||||
|
||||
def test_if():
|
||||
|
@ -106,7 +107,7 @@ if ($some) {
|
|||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_false(directive.provide_variables)
|
||||
assert_equals(directive.variable, '$some')
|
||||
assert_equal(directive.variable, '$some')
|
||||
assert_is_none(directive.operand)
|
||||
assert_is_none(directive.value)
|
||||
|
||||
|
@ -119,8 +120,8 @@ if (-f /some) {
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, IfBlock)
|
||||
assert_equals(directive.operand, '-f')
|
||||
assert_equals(directive.value, '/some')
|
||||
assert_equal(directive.operand, '-f')
|
||||
assert_equal(directive.value, '/some')
|
||||
assert_is_none(directive.variable)
|
||||
|
||||
|
||||
|
@ -132,9 +133,9 @@ if ($http_some = '/some') {
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, IfBlock)
|
||||
assert_equals(directive.variable, '$http_some')
|
||||
assert_equals(directive.operand, '=')
|
||||
assert_equals(directive.value, '/some')
|
||||
assert_equal(directive.variable, '$http_some')
|
||||
assert_equal(directive.operand, '=')
|
||||
assert_equal(directive.value, '/some')
|
||||
|
||||
|
||||
def test_block_some_flat():
|
||||
|
@ -152,7 +153,7 @@ def test_block_some_flat():
|
|||
for d in ['default_type', 'sendfile', 'keepalive_timeout']:
|
||||
c = directive.some(d, flat=True)
|
||||
assert_is_not_none(c)
|
||||
assert_equals(c.name, d)
|
||||
assert_equal(c.name, d)
|
||||
|
||||
|
||||
def test_block_some_not_flat():
|
||||
|
@ -183,9 +184,9 @@ def test_block_find_flat():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
finds = directive.find('directive', flat=True)
|
||||
assert_equals(len(finds), 2)
|
||||
assert_equals([x.name for x in finds], ['directive', 'directive'])
|
||||
assert_equals([x.args[0] for x in finds], ['1', '2'])
|
||||
assert_equal(len(finds), 2)
|
||||
assert_equal([x.name for x in finds], ['directive', 'directive'])
|
||||
assert_equal([x.args[0] for x in finds], ['1', '2'])
|
||||
|
||||
|
||||
def test_block_find_not_flat():
|
||||
|
@ -200,9 +201,9 @@ def test_block_find_not_flat():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
finds = directive.find('directive', flat=False)
|
||||
assert_equals(len(finds), 1)
|
||||
assert_equals([x.name for x in finds], ['directive'])
|
||||
assert_equals([x.args[0] for x in finds], ['1'])
|
||||
assert_equal(len(finds), 1)
|
||||
assert_equal([x.name for x in finds], ['directive'])
|
||||
assert_equal([x.args[0] for x in finds], ['1'])
|
||||
|
||||
|
||||
def test_block_map():
|
||||
|
@ -218,7 +219,7 @@ map $some_var $some_other_var {
|
|||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_other_var')
|
||||
assert_equal(directive.variable, 'some_other_var')
|
||||
|
||||
|
||||
def test_block_geo_two_vars():
|
||||
|
@ -234,7 +235,7 @@ geo $some_var $some_other_var {
|
|||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_other_var')
|
||||
assert_equal(directive.variable, 'some_other_var')
|
||||
|
||||
|
||||
def test_block_geo_one_var():
|
||||
|
@ -250,4 +251,4 @@ geo $some_var {
|
|||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_var')
|
||||
assert_equal(directive.variable, 'some_var')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from nose.tools import assert_equals, assert_false, assert_true
|
||||
from nose.tools import assert_equal, assert_false, assert_true
|
||||
from tests.asserts import assert_is_instance
|
||||
from gixy.parser.nginx_parser import NginxParser
|
||||
from gixy.directives.directive import *
|
||||
from gixy.directives.directive import Directive, AddHeaderDirective, SetDirective, RewriteDirective, RootDirective
|
||||
|
||||
|
||||
def _get_parsed(config):
|
||||
|
@ -14,9 +14,9 @@ def test_directive():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, Directive)
|
||||
assert_equals(directive.name, 'some')
|
||||
assert_equals(directive.args, ['foo', 'bar'])
|
||||
assert_equals(str(directive), 'some foo bar;')
|
||||
assert_equal(directive.name, 'some')
|
||||
assert_equal(directive.args, ['foo', 'bar'])
|
||||
assert_equal(str(directive), 'some foo bar;')
|
||||
|
||||
|
||||
def test_add_header():
|
||||
|
@ -24,12 +24,12 @@ def test_add_header():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, AddHeaderDirective)
|
||||
assert_equals(directive.name, 'add_header')
|
||||
assert_equals(directive.args, ['X-Foo', 'bar'])
|
||||
assert_equals(directive.header, 'x-foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_equal(directive.name, 'add_header')
|
||||
assert_equal(directive.args, ['X-Foo', 'bar'])
|
||||
assert_equal(directive.header, 'x-foo')
|
||||
assert_equal(directive.value, 'bar')
|
||||
assert_false(directive.always)
|
||||
assert_equals(str(directive), 'add_header X-Foo bar;')
|
||||
assert_equal(str(directive), 'add_header X-Foo bar;')
|
||||
|
||||
|
||||
def test_add_header_always():
|
||||
|
@ -37,12 +37,12 @@ def test_add_header_always():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, AddHeaderDirective)
|
||||
assert_equals(directive.name, 'add_header')
|
||||
assert_equals(directive.args, ['X-Foo', 'bar', 'always'])
|
||||
assert_equals(directive.header, 'x-foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_equal(directive.name, 'add_header')
|
||||
assert_equal(directive.args, ['X-Foo', 'bar', 'always'])
|
||||
assert_equal(directive.header, 'x-foo')
|
||||
assert_equal(directive.value, 'bar')
|
||||
assert_true(directive.always)
|
||||
assert_equals(str(directive), 'add_header X-Foo bar always;')
|
||||
assert_equal(str(directive), 'add_header X-Foo bar always;')
|
||||
|
||||
|
||||
def test_set():
|
||||
|
@ -50,11 +50,11 @@ def test_set():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, SetDirective)
|
||||
assert_equals(directive.name, 'set')
|
||||
assert_equals(directive.args, ['$foo', 'bar'])
|
||||
assert_equals(directive.variable, 'foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_equals(str(directive), 'set $foo bar;')
|
||||
assert_equal(directive.name, 'set')
|
||||
assert_equal(directive.args, ['$foo', 'bar'])
|
||||
assert_equal(directive.variable, 'foo')
|
||||
assert_equal(directive.value, 'bar')
|
||||
assert_equal(str(directive), 'set $foo bar;')
|
||||
assert_true(directive.provide_variables)
|
||||
|
||||
|
||||
|
@ -63,14 +63,14 @@ def test_rewrite():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RewriteDirective)
|
||||
assert_equals(directive.name, 'rewrite')
|
||||
assert_equals(directive.args, ['^', 'http://some'])
|
||||
assert_equals(str(directive), 'rewrite ^ http://some;')
|
||||
assert_equal(directive.name, 'rewrite')
|
||||
assert_equal(directive.args, ['^', 'http://some'])
|
||||
assert_equal(str(directive), 'rewrite ^ http://some;')
|
||||
assert_true(directive.provide_variables)
|
||||
|
||||
assert_equals(directive.pattern, '^')
|
||||
assert_equals(directive.replace, 'http://some')
|
||||
assert_equals(directive.flag, None)
|
||||
assert_equal(directive.pattern, '^')
|
||||
assert_equal(directive.replace, 'http://some')
|
||||
assert_equal(directive.flag, None)
|
||||
|
||||
|
||||
def test_rewrite_flags():
|
||||
|
@ -78,14 +78,14 @@ def test_rewrite_flags():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RewriteDirective)
|
||||
assert_equals(directive.name, 'rewrite')
|
||||
assert_equals(directive.args, ['^/(.*)$', 'http://some/$1', 'redirect'])
|
||||
assert_equals(str(directive), 'rewrite ^/(.*)$ http://some/$1 redirect;')
|
||||
assert_equal(directive.name, 'rewrite')
|
||||
assert_equal(directive.args, ['^/(.*)$', 'http://some/$1', 'redirect'])
|
||||
assert_equal(str(directive), 'rewrite ^/(.*)$ http://some/$1 redirect;')
|
||||
assert_true(directive.provide_variables)
|
||||
|
||||
assert_equals(directive.pattern, '^/(.*)$')
|
||||
assert_equals(directive.replace, 'http://some/$1')
|
||||
assert_equals(directive.flag, 'redirect')
|
||||
assert_equal(directive.pattern, '^/(.*)$')
|
||||
assert_equal(directive.replace, 'http://some/$1')
|
||||
assert_equal(directive.flag, 'redirect')
|
||||
|
||||
|
||||
def test_root():
|
||||
|
@ -93,9 +93,9 @@ def test_root():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RootDirective)
|
||||
assert_equals(directive.name, 'root')
|
||||
assert_equals(directive.args, ['/var/www/html'])
|
||||
assert_equals(str(directive), 'root /var/www/html;')
|
||||
assert_equal(directive.name, 'root')
|
||||
assert_equal(directive.args, ['/var/www/html'])
|
||||
assert_equal(str(directive), 'root /var/www/html;')
|
||||
assert_true(directive.provide_variables)
|
||||
|
||||
assert_equals(directive.path, '/var/www/html')
|
||||
assert_equal(directive.path, '/var/www/html')
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from nose.tools import assert_equal
|
||||
from tests.asserts import assert_is_instance
|
||||
from gixy.parser.nginx_parser import NginxParser
|
||||
from gixy.directives.directive import *
|
||||
from gixy.directives.block import *
|
||||
from gixy.directives.directive import Directive, SetDirective, RewriteDirective
|
||||
from gixy.directives.block import Block, Root, HttpBlock, ServerBlock, LocationBlock, IfBlock, IncludeBlock
|
||||
|
||||
|
||||
def _parse(config):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from nose.tools import assert_equals
|
||||
from gixy.parser.raw_parser import *
|
||||
from nose.tools import assert_equal
|
||||
from gixy.parser.raw_parser import RawParser
|
||||
|
||||
|
||||
def test_directive():
|
||||
|
@ -11,8 +11,8 @@ set $foo "bar";
|
|||
set $foo 'bar';
|
||||
proxy_pass http://unix:/run/sock.socket;
|
||||
rewrite ^/([a-zA-Z0-9]+)$ /$1/${arg_v}.pb break;
|
||||
server_name some.tld ~^(www\.)?podberi.(?:ru|com|ua)$
|
||||
~^(www\.)?guru.yandex.ru$;
|
||||
server_name some.tld ~^(www\\.)?podberi.(?:ru|com|ua)$
|
||||
~^(www\\.)?guru.yandex.ru$;
|
||||
'''
|
||||
|
||||
expected = [
|
||||
|
@ -23,7 +23,7 @@ rewrite ^/([a-zA-Z0-9]+)$ /$1/${arg_v}.pb break;
|
|||
['set', '$foo', 'bar'],
|
||||
['proxy_pass', 'http://unix:/run/sock.socket'],
|
||||
['rewrite', '^/([a-zA-Z0-9]+)$', '/$1/${arg_v}.pb', 'break'],
|
||||
['server_name', 'some.tld', '~^(www\.)?podberi.(?:ru|com|ua)$', '~^(www\.)?guru.yandex.ru$']
|
||||
['server_name', 'some.tld', '~^(www\\.)?podberi.(?:ru|com|ua)$', '~^(www\\.)?guru.yandex.ru$']
|
||||
]
|
||||
|
||||
assert_config(config, expected)
|
||||
|
@ -63,7 +63,7 @@ location ~* ^/baz$ {
|
|||
location ^~ ^/bazz {
|
||||
}
|
||||
# Whitespace may be omitted:((
|
||||
location ~\.(js|css)$ {
|
||||
location ~\\.(js|css)$ {
|
||||
}
|
||||
'''
|
||||
|
||||
|
@ -73,7 +73,7 @@ location ~\.(js|css)$ {
|
|||
['location', ['~*', '^/baz$'], []],
|
||||
['location', ['^~', '^/bazz'], []],
|
||||
['Whitespace may be omitted:(('],
|
||||
['location', ['~', '\.(js|css)$'], []]]
|
||||
['location', ['~', '\\.(js|css)$'], []]]
|
||||
|
||||
assert_config(config, expected)
|
||||
|
||||
|
@ -222,14 +222,14 @@ if (!-e "/var/data/$dataset") {
|
|||
return 503;
|
||||
}
|
||||
|
||||
if ($https_or_slb = (by_\(sl\)b|https)) {
|
||||
if ($https_or_slb = (by_\\(sl\\)b|https)) {
|
||||
}
|
||||
|
||||
if ($host ~* (lori|rage2)\.yandex\.(ru|ua|com|com\.tr)) {
|
||||
if ($host ~* (lori|rage2)\\.yandex\\.(ru|ua|com|com\\.tr)) {
|
||||
set $x_frame_options ALLOW;
|
||||
}
|
||||
|
||||
if ($request_filename ~* ^.*?/(\d+_)([^/]+)$) {
|
||||
if ($request_filename ~* ^.*?/(\\d+_)([^/]+)$) {
|
||||
}
|
||||
|
||||
if ($http_user_agent ~* "^WordPress.*; verifying pingback") {
|
||||
|
@ -258,12 +258,12 @@ if ($foo = "BAR") { rewrite ^(.*)$ /bar; }
|
|||
['if', ['!-e', '/var/data/$dataset'], [
|
||||
['return', '503']
|
||||
]],
|
||||
['if', ['$https_or_slb', '=', '(by_\(sl\)b|https)'], [
|
||||
['if', ['$https_or_slb', '=', '(by_\\(sl\\)b|https)'], [
|
||||
]],
|
||||
['if', ['$host', '~*', '(lori|rage2)\.yandex\.(ru|ua|com|com\.tr)'], [
|
||||
['if', ['$host', '~*', '(lori|rage2)\\.yandex\\.(ru|ua|com|com\\.tr)'], [
|
||||
['set', '$x_frame_options', 'ALLOW']
|
||||
]],
|
||||
['if', ['$request_filename', '~*', '^.*?/(\d+_)([^/]+)$'], [
|
||||
['if', ['$request_filename', '~*', '^.*?/(\\d+_)([^/]+)$'], [
|
||||
]],
|
||||
['if', ['$http_user_agent', '~*', '^WordPress.*; verifying pingback'], [
|
||||
]],
|
||||
|
@ -360,14 +360,14 @@ server {
|
|||
def test_issue_8():
|
||||
config = '''
|
||||
# http://nginx.org/ru/docs/http/ngx_http_upstream_module.html
|
||||
if ($http_referer ~* (\.(ru|ua|by|kz)/(pages/music|partners/|page-no-rights\.xml)) ) {
|
||||
if ($http_referer ~* (\\.(ru|ua|by|kz)/(pages/music|partners/|page-no-rights\\.xml)) ) {
|
||||
set $temp A;
|
||||
}
|
||||
'''
|
||||
|
||||
expected = [
|
||||
['http://nginx.org/ru/docs/http/ngx_http_upstream_module.html'],
|
||||
['if', ['$http_referer', '~*', '(\.(ru|ua|by|kz)/(pages/music|partners/|page-no-rights\.xml))'], [
|
||||
['if', ['$http_referer', '~*', '(\\.(ru|ua|by|kz)/(pages/music|partners/|page-no-rights\\.xml))'], [
|
||||
['set', '$temp', 'A']
|
||||
]]
|
||||
]
|
||||
|
@ -415,9 +415,9 @@ location = /lua {
|
|||
['content_by_lua_block', [], [
|
||||
'local', 'res', '=', 'ngx.location.capture(', '"/some_other_location"', ')',
|
||||
'if', 'res', 'then',
|
||||
'ngx.say(', '"status: "', ',', 'res.status)',
|
||||
'ngx.say(', '"body:"', ')',
|
||||
'ngx.print(res.body)',
|
||||
'ngx.say(', '"status: "', ',', 'res.status)',
|
||||
'ngx.say(', '"body:"', ')',
|
||||
'ngx.print(res.body)',
|
||||
'end']]
|
||||
]]
|
||||
]
|
||||
|
@ -442,7 +442,7 @@ location = /foo {
|
|||
['location', ['=', '/foo'], [
|
||||
['rewrite_by_lua_block', [], [
|
||||
'res', '=', 'ngx.location.capture(', '"/memc"', ',',
|
||||
['args', '=', ['cmd', '=', '"incr"', ',', 'key', '=', 'ngx.var.uri']],
|
||||
['args', '=', ['cmd', '=', '"incr"', ',', 'key', '=', 'ngx.var.uri']],
|
||||
')']],
|
||||
['proxy_pass', 'http://blah.blah.com']
|
||||
]]
|
||||
|
@ -481,15 +481,15 @@ def test_comments():
|
|||
# Some comment
|
||||
add_header X-Some-Comment some;
|
||||
|
||||
#
|
||||
#
|
||||
# Comment with padding
|
||||
#
|
||||
#
|
||||
add_header X-Padding-Comment padding;
|
||||
|
||||
#
|
||||
add_header X-Blank-Comment blank;
|
||||
|
||||
if (1) # Comment
|
||||
if (1) # Comment
|
||||
{
|
||||
add_header X-Inline blank;
|
||||
}
|
||||
|
@ -556,9 +556,9 @@ add_header X-Test "Windows-1251";
|
|||
'''
|
||||
|
||||
actual = RawParser().parse(config)
|
||||
assert_equals(len(actual.asList()), 2)
|
||||
assert_equal(len(actual.asList()), 2)
|
||||
|
||||
|
||||
def assert_config(config, expected):
|
||||
actual = RawParser().parse(config)
|
||||
assert_equals(actual.asList(), expected)
|
||||
assert_equal(actual.asList(), expected)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from nose.tools import assert_equals, assert_true
|
||||
from nose.tools import assert_equal, assert_true
|
||||
from tests.asserts import assert_in
|
||||
import os
|
||||
from os import path
|
||||
import json
|
||||
|
||||
from ..utils import *
|
||||
from gixy.core.manager import Manager as Gixy
|
||||
from gixy.core.plugins_manager import PluginsManager
|
||||
from gixy.core.config import Config
|
||||
from gixy.formatters.base import BaseFormatter
|
||||
|
||||
|
||||
def setup_module():
|
||||
|
@ -57,7 +57,8 @@ def test_from_config():
|
|||
assert_true(plugin in tested_plugins,
|
||||
'Plugin {name!r} should have at least one simple test config'.format(name=plugin))
|
||||
assert_true(plugin in tested_fp_plugins,
|
||||
'Plugin {name!r} should have at least one simple test config with false positive'.format(name=plugin))
|
||||
'Plugin {name!r} should have at least one simple test config with false positive'
|
||||
.format(name=plugin))
|
||||
|
||||
|
||||
def parse_plugin_options(config_path):
|
||||
|
@ -86,15 +87,15 @@ def check_configuration(plugin, config_path, test_config):
|
|||
formatter.feed(config_path, yoda)
|
||||
_, results = formatter.reports.popitem()
|
||||
|
||||
assert_equals(len(results), 1, 'Should have one report')
|
||||
assert_equal(len(results), 1, 'Should have one report')
|
||||
result = results[0]
|
||||
|
||||
if 'severity' in test_config:
|
||||
if not hasattr(test_config['severity'], '__iter__'):
|
||||
assert_equals(result['severity'], test_config['severity'])
|
||||
assert_equal(result['severity'], test_config['severity'])
|
||||
else:
|
||||
assert_in(result['severity'], test_config['severity'])
|
||||
assert_equals(result['plugin'], plugin)
|
||||
assert_equal(result['plugin'], plugin)
|
||||
assert_true(result['summary'])
|
||||
assert_true(result['description'])
|
||||
assert_true(result['config'])
|
||||
|
@ -105,5 +106,5 @@ def check_configuration(plugin, config_path, test_config):
|
|||
def check_configuration_fp(plugin, config_path, test_config):
|
||||
with yoda_provider(plugin) as yoda:
|
||||
yoda.audit(config_path, open(config_path, mode='r'))
|
||||
assert_equals(len([x for x in yoda.results]), 0,
|
||||
'False positive configuration must not trigger any plugins')
|
||||
assert_equal(len([x for x in yoda.results]), 0,
|
||||
'False positive configuration must not trigger any plugins')
|
||||
|
|
|
@ -54,7 +54,7 @@ class Matcher(object):
|
|||
"""
|
||||
Try to match a single stored value (dv) with a supplied value (v).
|
||||
"""
|
||||
if type(v) != type(dv):
|
||||
if type(v) is not type(dv):
|
||||
result = False
|
||||
elif type(dv) is not str or k not in self._partial_matches:
|
||||
result = (v == dv)
|
||||
|
|
5
tox.ini
5
tox.ini
|
@ -1,5 +1,5 @@
|
|||
[tox]
|
||||
envlist = py26, py27, py34, py35, py36, py37, flake8
|
||||
envlist = py39, py310, py311, py312, py313, flake8
|
||||
skip_missing_interpreters = True
|
||||
|
||||
[testenv]
|
||||
|
@ -12,8 +12,7 @@ commands = nosetests -v
|
|||
deps =
|
||||
flake8
|
||||
basepython = python3
|
||||
commands =
|
||||
flake8 setup.py gixy
|
||||
commands = flake8
|
||||
|
||||
[flake8]
|
||||
max_line_length = 120
|
||||
|
|
Loading…
Reference in New Issue