<commit_before>--
-- Created by IntelliJ IDEA.
-- User: alex
-- Date: 24/09/2015
-- Time: 18:53
-- To change this template use File | Settings | File Templates.
--

local handle, msg = loadlib(getenv("LIBRARY_PATH"))
if (not handle or handle == -1) then error(msg) end

callfromlib(handle, 'luaopen_python')
assert(python, "undefined python object")

-- python home
python.system_init("C:\\Python27");

local builtins = python.builtins()
local locals = python.locals()

python.execute([[
def TestFunc(*args, **kwargs):
    _args = (1, 2, 3, 4, 5, ('a', 'c', 'd', 'e', {'a': 1, 'c': 3, 'b': 2}))
    _kwargs = {
        'host': '127.0.0.1',
        'user': 'user',
        'passwd': '<PASSWORD>&*',
        'db': 'mysqdb'
    }
    assert args == _args, "[TestFunc] args no match!"

    for k in _kwargs:
        assert k in kwargs, "[TestFunc] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc] data no match!"
    return True
]])

python.execute([[
def TestFunc2(limit, *args, **kwargs):
    assert range(1,limit) == list(args[0]), '[TestFunc2] args no match!'
]])

python.execute([[
def TestFunc3(*args, **kwargs):
    _args = (1,2,3,4)
    _kwargs = {'a': 1, 'b': 2, 'c': 3}
    assert _args == args, '[TestFunc3] args no match!'
    for k in _kwargs:
        assert k in kwargs, "[TestFunc] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc] data no match!"
]])

python.execute([[
def TestFunc4(*args, **kwargs):
    _kwargs = {'a': 1, 'b': 2, 'c': 3}
    assert args == (), '[TestFunc3] args no match!'
    for k in _kwargs:
        assert k in kwargs, "[TestFunc] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc] data no match!"
]])

local index = 0
while (index < 10) do
    local args = python.args(1,2,3,4,5,{'a','c','d','e', {a=1,b=2,c=3}})
    local kwargs = python.kwargs({host='127.0.0.1', user='user', passwd='<PASSWORD>&*', db='mysqdb'})
    locals.TestFunc(args, kwargs)
    index = index + 1
end

locals.TestFunc2(5, builtins.range(1,5))
locals.TestFunc2(5, python.args(1,2,3,4))

-- global args, kwargs
locals.TestFunc3(args(1,2,3,4), kwargs{a=1, b=2, c=3})
locals.TestFunc4(kwargs{a=1, b=2, c=3})<commit_msg>Test args, kwargs 3.<commit_after>--
-- Created by IntelliJ IDEA.
-- User: alex
-- Date: 24/09/2015
-- Time: 18:53
-- To change this template use File | Settings | File Templates.
--

local handle, msg = loadlib(getenv("LIBRARY_PATH"))
if (not handle or handle == -1) then error(msg) end

callfromlib(handle, 'luaopen_python')
assert(python, "undefined python object")

-- python home
python.system_init("C:\\Python27");

local builtins = python.builtins()
local locals = python.locals()

python.execute([[
def TestFunc(*args, **kwargs):
    _args = (1, 2, 3, 4, 5, ('a', 'c', 'd', 'e', {'a': 1, 'c': 3, 'b': 2}))
    _kwargs = {
        'host': '127.0.0.1',
        'user': 'user',
        'passwd': '<PASSWORD>&*',
        'db': 'mysqdb'
    }
    assert args == _args, "[TestFunc] args no match!"

    for k in _kwargs:
        assert k in kwargs, "[TestFunc] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc] data no match!"
    return True
]])

python.execute([[
def TestFunc2(limit, *args, **kwargs):
    assert range(1,limit) == list(args[0]), '[TestFunc2] args no match!'
]])

python.execute([[
def TestFunc3(*args, **kwargs):
    _args = (1,2,3,4)
    _kwargs = {'a': 1, 'b': 2, 'c': 3}
    assert _args == args, '[TestFunc3] args no match!'
    for k in _kwargs:
        assert k in kwargs, "[TestFunc3] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc3] data no match!"
]])

python.execute([[
def TestFunc4(*args, **kwargs):
    _kwargs = {'a': 1, 'b': 2, 'c': 3}
    assert args == (), '[TestFunc4] args no match!'
    for k in _kwargs:
        assert k in kwargs, "[TestFunc4] key not found"
        assert kwargs[k] == _kwargs[k], "[TestFunc4] data no match!"
]])

python.execute([[
def TestFunc5(*args, **kwargs):
    _args = (1,2,3,4)
    assert args == _args, '[TestFunc5] args no match!'
    assert kwargs == {}, '[TestFunc5] kwargs no match!'
]])

local index = 0
while (index < 10) do
    local args = python.args(1,2,3,4,5,{'a','c','d','e', {a=1,b=2,c=3}})
    local kwargs = python.kwargs({host='127.0.0.1', user='user', passwd='<PASSWORD>&*', db='mysqdb'})
    locals.TestFunc(args, kwargs)
    index = index + 1
end

locals.TestFunc2(5, builtins.range(1,5))
locals.TestFunc2(5, python.args(1,2,3,4))

-- global args, kwargs
locals.TestFunc3(args(1,2,3,4), kwargs{a=1, b=2, c=3})
locals.TestFunc4(kwargs{a=1, b=2, c=3})
locals.TestFunc5(args(1,2,3,4))
{'fraction_non_alphanumeric': 0.20239912758996728, 'fraction_numerical': 0.041657579062159215, 'mean_word_length': 3.5814185814185815, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '279954', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1752, 'n_words': 480}