From 6c181263827802b8bb989bfdcfc8dede3ac5d7f5 Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Mon, 4 Feb 2019 10:32:17 +0000 Subject: [PATCH] Improve test coverage of os.open --- tests/snippets/builtin_open.py | 8 ++++++++ tests/snippets/os_open.py | 6 ++++++ vm/src/builtins.rs | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 tests/snippets/builtin_open.py diff --git a/tests/snippets/builtin_open.py b/tests/snippets/builtin_open.py new file mode 100644 index 000000000..805c975c8 --- /dev/null +++ b/tests/snippets/builtin_open.py @@ -0,0 +1,8 @@ +fd = open('README.md') +assert 'RustPython' in fd.read() + +try: + open('DoesNotExist') + assert False +except FileNotFoundError: + pass diff --git a/tests/snippets/os_open.py b/tests/snippets/os_open.py index ca5a61d5a..8138f820c 100644 --- a/tests/snippets/os_open.py +++ b/tests/snippets/os_open.py @@ -2,3 +2,9 @@ import os assert os.open('README.md', 0) > 0 + +try: + os.open('DOES_NOT_EXIST', 0) + assert False +except FileNotFoundError: + pass diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index b1e5904eb..068394afe 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -767,6 +767,11 @@ pub fn make_module(ctx: &PyContext) -> PyObjectRef { ctx.set_attr(&py_mod, "ValueError", ctx.exceptions.value_error.clone()); ctx.set_attr(&py_mod, "IndexError", ctx.exceptions.index_error.clone()); ctx.set_attr(&py_mod, "ImportError", ctx.exceptions.import_error.clone()); + ctx.set_attr( + &py_mod, + "FileNotFoundError", + ctx.exceptions.file_not_found_error.clone(), + ); ctx.set_attr( &py_mod, "StopIteration",