Merge pull request #617 from kollmats/master

fixes PermissionError for non-writable flagging path
This commit is contained in:
Abubakar Abid 2022-02-15 16:27:57 -05:00 committed by GitHub
commit 01f6869500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -684,7 +684,7 @@ class Interface:
if self.enable_queue is None:
self.enable_queue = enable_queue
if self.allow_flagging:
if self.allow_flagging != "never":
self.flagging_callback.setup(self.flagging_dir)
config = self.get_config_file()

View File

@ -67,5 +67,28 @@ class TestHuggingFaceDatasetSaver(unittest.TestCase):
self.assertEqual(row_count, 2) # 3 rows written including header
class TestDisableFlagging(unittest.TestCase):
def test_flagging_no_permission_error_with_flagging_disabled(self):
with tempfile.TemporaryDirectory() as tmpdirname:
os.chmod(tmpdirname, 0o444) # Make directory read-only
nonwritable_path = os.path.join(
tmpdirname, 'flagging_dir')
io = gr.Interface(
lambda x: x,
"text",
"text",
allow_flagging="never",
flagging_dir=nonwritable_path
)
try:
io.launch(prevent_thread_lock=True)
except PermissionError:
self.fail("launch() raised a PermissionError unexpectedly")
io.close()
if __name__ == "__main__":
unittest.main()