From 3c251c8d655011ec2ee4ec02933e8e02163b4620 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sat, 17 Sep 2022 18:30:57 +0200 Subject: Fix a corner case when open() fails w/ NXIO/OPNOTSUPP on reg file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: https://github.com/projg2/gemato/issues/21 Signed-off-by: Michał Górny --- tests/test_verify.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test_verify.py b/tests/test_verify.py index 8890e1a..0c3fba9 100644 --- a/tests/test_verify.py +++ b/tests/test_verify.py @@ -4,11 +4,13 @@ # Licensed under the terms of 2-clause BSD license import contextlib +import errno import itertools import os import os.path import socket import stat +import unittest.mock import pytest @@ -560,3 +562,11 @@ def test_entry_compatibility(a_cls, a_name, a_args, b_cls, b_name, e1 = new_manifest_entry(a_cls, a_name, *a_args) e2 = new_manifest_entry(b_cls, b_name, *b_args) assert verify_entry_compatibility(e1, e2) == (expected, diff) + + +def test_get_file_metadata_fail_to_open_reg(test_tree): + """Regression test for when open() fails on a seemingly regular file""" + with unittest.mock.patch("os.open") as mock_open: + mock_open.side_effect = OSError(errno.ENXIO, "mocked error") + with pytest.raises(OSError): + list(get_file_metadata(test_tree / "regular-file", {})) -- cgit v1.2.3