Fedoraプロジェクトで使用している自動テストのフレームワークにAutoQAというのがあって、これはLinuxカーネルのテストで使われているAuotestを利用して作られているんですが、これのcontrolファイルでちょっと疑問に思った書き方があったので調べてみました。
言語はPythonです。
このcontrolファイルの最後でテストケースの呼出があるんですが、この3番目の引数がポインタっぽいんだけどなにって思った次第です。
job.run_test('rats_install', config=autoqa_conf, **autoqa_args)
Pythonのドキュメントを調べてみると、リファレンスマニュアルの7.6章「関数定義」に答えが書いてありました。
詳細は上記のマニュアルを見ればOKだと思いますので、テストコードだけ。
#!/usr/bin/env python def test_func2(hello_string, **argv): print hello_string print argv def test_func1(hello_string, *argv): print hello_string print argv if __name__ == "__main__": test_func1("hello, world", 1) test_func1("hello, world", 1,2) test_func1("hello, world", 1,2,3) test_func1("hello, world", 1,2,3,4) test_func1("hello, world", 1,2,3,4,5) test_func2("hello, world", a=1) test_func2("hello, world", a=1, b=2) test_func2("hello, world", a=1, b=2, c=3) test_func2("hello, world", a=1, b=2, c=3, d=4) test_func2("hello, world", a=1, b=2, c=3, d=4, e=5)
このコードを実行するとこんな感じに出力
[masami@moon]~% ./test.py ./test.py hello, world (1,) hello, world (1, 2) hello, world (1, 2, 3) hello, world (1, 2, 3, 4) hello, world (1, 2, 3, 4, 5) hello, world {'a': 1} hello, world {'a': 1, 'b': 2} hello, world {'a': 1, 'c': 3, 'b': 2} hello, world {'a': 1, 'c': 3, 'b': 2, 'd': 4} hello, world {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}