Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] oj testでディレクトリ指定できないバグ修正 #233

Merged
merged 8 commits into from
Jan 4, 2019

Conversation

fukatani
Copy link
Contributor

@fukatani fukatani commented Jan 3, 2019

/home/ryo/work/github/rust-debug/src/
というディレクトリにおいて
oj test -c ./a.out -d ./testを行うと、

Traceback (most recent call last):
  File "/home/ryo/.virtualenvs/default/bin/oj", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/ryo/work/github/online-judge-tools/oj", line 6, in <module>
    onlinejudge.implementation.main.main(args=sys.argv[1:])
  File "/home/ryo/work/github/online-judge-tools/onlinejudge/implementation/main.py", line 345, in main
    run_program(namespace, parser=parser)
  File "/home/ryo/work/github/online-judge-tools/onlinejudge/implementation/main.py", line 320, in run_program
    test(args)
  File "/home/ryo/work/github/online-judge-tools/onlinejudge/implementation/command/test.py", line 41, in test
    tests = cutils.construct_relationship_of_files(args.test, args.directory, args.format)
  File "/home/ryo/work/github/online-judge-tools/onlinejudge/implementation/command/utils.py", line 52, in construct_relationship_of_files
    m = match_with_format(directory, format, path.resolve())
  File "/home/ryo/work/github/online-judge-tools/onlinejudge/implementation/command/utils.py", line 27, in match_with_format
    path = path.absolute().relative_to(directory.absolute()).resolve()
  File "/usr/lib/python3.5/pathlib.py", line 1109, in resolve
    s = self._flavour.resolve(self)
  File "/usr/lib/python3.5/pathlib.py", line 330, in resolve
    return _resolve(base, str(path)) or sep
  File "/usr/lib/python3.5/pathlib.py", line 315, in _resolve
    target = accessor.readlink(newpath)
  File "/usr/lib/python3.5/pathlib.py", line 422, in readlink
    return os.readlink(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/ryo/work/github/rust-debug/src/sample-1.in'

というエラーが発生します。
私がローカルで修正を試みたパッチを添えておきます。
実行環境: Python 3.5、https://atcoder.jp/contests/arc087/tasks/arc087_b の問題をダウンロード

table = {}
table['s'] = '(?P<name>.+)'
table['e'] = '(?P<ext>in|out)'
pattern = re.compile('^' + utils.parcentformat(format, table) + '$')
path = path.absolute().relative_to(directory.absolute()).resolve()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathにはcutils.glob_with_format(args.directory, args.format)の結果が入っていて
/home/ryo/work/github/rust-debug/src/test/sample1.inが格納されており、
directoryには/home/ryo/work/github/rust-debug/src/testが入っています。
この2つにrelativeをとると、'sample1.in'になり/home/ryo/work/github/rust-debug/src/sample-1.inをresolveするようにみえました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatがディレクトリを複数含んでいる場合、それに応じてサーチの際のルートディレクトリが変わるので、ベタに数えてカウントアップしてしまいました。
ただ、formatが"./"や"/"(システムのルートディレクトリ)から始まることはあるでしょうか?
-dから相対パスで探すものと仮定してコード書きました。

@kmyk kmyk mentioned this pull request Jan 3, 2019
@kmyk
Copy link
Member

kmyk commented Jan 3, 2019

ありがとうございます。
str だと分かりにくいので Path にしたときに混ざったバグのようです。
この部分のテストがないのでやらかしてしまいました。気付いてなかったので助かります。

ただCIが型チェックで落ちてるのと、他にもまだバグが残ってるのでまだmergeはできなさそうです。

他のバグとは、ケース名の取得が壊れている (下図) のと、 oj test -c ./a.out -d ./hoge/../test が動かないのとの2点です。
なお、報告されている例外は再現しないのでこれに関しては3.5特有の可能性はあります。

誤:

[*] /home/user/GitHub/online-judge-tools/foo/sample-1
[x] time: 0.003562 sec
[+] AC

正:

[*] sample-1
[x] time: 0.003562 sec
[+] AC

@kmyk
Copy link
Member

kmyk commented Jan 3, 2019

テストを書きました。 (#235) (CIが落ちるため develop branchにmergeしてます)
これにrebaseした上でCIが通るように修正してもらえればmergeします。

やってもらえるなら任せたいですが、バージョン依存は少ないはずなので続きは私にパスしてもらってもかまいません (せっかく直してもらったのに追加になってしまって申し訳なさがあるため)。どうしますか?

@fukatani
Copy link
Contributor Author

fukatani commented Jan 3, 2019

テスト追加ありがとうございます。
私としてはPR作成が趣味ですし、online_judge_toolsの理解を深めていきたいので、明日まで待ってもらえるならぜひやりたいです 😃

このPRもWIPのつもりで、「こんな感じでしょうか?」というつもり出したので、全然問題ないです。

@fukatani fukatani changed the title oj testがバグっている? [WIP] oj testでディレクトリ指定できないバグ修正 Jan 3, 2019
@kmyk
Copy link
Member

kmyk commented Jan 3, 2019

それならよかったです。では続きは任せます。


def test_call_test_dir(self):
self.snippet_call_test(
args=[ '-c', 'cat', '-d', 'p/o/../../p/o/y/o' ],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もともとはpath/toでしたが、そのようなディレクトリが存在しないことがエラーの原因なので、
テストケースを修正しました。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ知らなかったです。
Python 3.6のresolve()はいい感じにしてくれるけど3.5はだめ、普通のcatとかlsとかは同じエラーを吐くので、この修正は妥当そう。

@fukatani
Copy link
Contributor Author

fukatani commented Jan 4, 2019

generate-outputのテストも作成中です

@kmyk
Copy link
Member

kmyk commented Jan 4, 2019

CI通ってるのでひとまずmergeします。

generate-outputの方も壊れてるかもしれませんが、別のプルリクに分けましょう。

@kmyk kmyk merged commit 62abecf into online-judge-tools:master Jan 4, 2019
kmyk added a commit that referenced this pull request Jan 4, 2019
@kmyk
Copy link
Member

kmyk commented Jan 4, 2019

generate-outputのテストも書いてくれる (感謝) とのことなので、これができたらバージョン上げます

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants