-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test path variables, comments, custom test case in own class, temp fi…
…les share remove function
- Loading branch information
Showing
3 changed files
with
68 additions
and
53 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
datalab/datalab_session/tests/test_files/file_extended_test_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pathlib as pl | ||
from hashlib import md5 | ||
from os import path, remove, listdir | ||
|
||
from django.test import TestCase | ||
|
||
# extending the TestCase class to include a custom assertions for file operations | ||
class FileExtendedTestCase(TestCase): | ||
def assertIsFile(self, path): | ||
if not pl.Path(path).resolve().is_file(): | ||
raise AssertionError("File does not exist: %s" % str(path)) | ||
|
||
def assertFilesEqual(self, image_1: str, image_2: str): | ||
with open(image_1, 'rb') as file_1, open(image_2, 'rb') as file_2: | ||
self.assertEqual(md5(file_1.read()).hexdigest(), md5(file_2.read()).hexdigest()) | ||
|
||
def clean_test_dir(self): | ||
test_files_dir = 'datalab/datalab_session/tests/test_files' | ||
for file_name in listdir(test_files_dir): | ||
if file_name.startswith('temp_'): | ||
file_path = path.join(test_files_dir, file_name) | ||
if path.isfile(file_path): | ||
remove(file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters