mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
Rename "SingeFileError" to "SingleFileError" (#823)
This commit is contained in:
parent
c929e8f11c
commit
76c65566cf
3 changed files with 8 additions and 8 deletions
|
@ -9,7 +9,7 @@ import subprocess
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
class SingeFileError(Exception):
|
class SingleFileError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ def create_snapshot(url: str, filepath: str):
|
||||||
|
|
||||||
# check if the file was created
|
# check if the file was created
|
||||||
if not os.path.exists(temp_filepath):
|
if not os.path.exists(temp_filepath):
|
||||||
raise SingeFileError("Failed to create snapshot")
|
raise SingleFileError("Failed to create snapshot")
|
||||||
|
|
||||||
with open(temp_filepath, "rb") as raw_file, gzip.open(
|
with open(temp_filepath, "rb") as raw_file, gzip.open(
|
||||||
filepath, "wb"
|
filepath, "wb"
|
||||||
|
@ -47,12 +47,12 @@ def create_snapshot(url: str, filepath: str):
|
||||||
)
|
)
|
||||||
process.terminate()
|
process.terminate()
|
||||||
process.wait(timeout=20)
|
process.wait(timeout=20)
|
||||||
raise SingeFileError("Timeout expired while creating snapshot")
|
raise SingleFileError("Timeout expired while creating snapshot")
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
# Kill the whole process group, which should also clean up any chromium
|
# Kill the whole process group, which should also clean up any chromium
|
||||||
# processes spawned by single-file
|
# processes spawned by single-file
|
||||||
logger.error("Timeout expired while terminating. Killing process...")
|
logger.error("Timeout expired while terminating. Killing process...")
|
||||||
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
||||||
raise SingeFileError("Timeout expired while creating snapshot")
|
raise SingleFileError("Timeout expired while creating snapshot")
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
raise SingeFileError(f"Failed to create snapshot: {error.stderr}")
|
raise SingleFileError(f"Failed to create snapshot: {error.stderr}")
|
||||||
|
|
|
@ -536,7 +536,7 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
def test_create_html_snapshot_should_handle_error(self):
|
def test_create_html_snapshot_should_handle_error(self):
|
||||||
bookmark = self.setup_bookmark(url="https://example.com")
|
bookmark = self.setup_bookmark(url="https://example.com")
|
||||||
|
|
||||||
self.mock_singlefile_create_snapshot.side_effect = singlefile.SingeFileError(
|
self.mock_singlefile_create_snapshot.side_effect = singlefile.SingleFileError(
|
||||||
"Error"
|
"Error"
|
||||||
)
|
)
|
||||||
tasks.create_html_snapshot(bookmark)
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
|
|
@ -43,12 +43,12 @@ class SingleFileServiceTestCase(TestCase):
|
||||||
with mock.patch("subprocess.Popen") as mock_popen:
|
with mock.patch("subprocess.Popen") as mock_popen:
|
||||||
mock_popen.side_effect = subprocess.CalledProcessError(1, "command")
|
mock_popen.side_effect = subprocess.CalledProcessError(1, "command")
|
||||||
|
|
||||||
with self.assertRaises(singlefile.SingeFileError):
|
with self.assertRaises(singlefile.SingleFileError):
|
||||||
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
# so also check that it raises error if output file isn't created
|
# so also check that it raises error if output file isn't created
|
||||||
with mock.patch("subprocess.Popen"):
|
with mock.patch("subprocess.Popen"):
|
||||||
with self.assertRaises(singlefile.SingeFileError):
|
with self.assertRaises(singlefile.SingleFileError):
|
||||||
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
def test_create_snapshot_empty_options(self):
|
def test_create_snapshot_empty_options(self):
|
||||||
|
|
Loading…
Reference in a new issue