Created
June 15, 2019 03:37
-
-
Save bkhanale/6211ac75859a50a051005ae705e0738a to your computer and use it in GitHub Desktop.
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
import os | |
import platform | |
import stat | |
from queue import Queue | |
from bears.general.FileModeBear import FileModeBear | |
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | |
from coalib.results.Result import RESULT_SEVERITY, Result | |
from coalib.settings.Section import Section | |
from coalib.settings.Setting import Setting | |
def get_testfile_path(file): | |
return os.path.join(os.path.dirname(__file__), | |
'filemode_test_files', file) | |
FILE_PATH = get_testfile_path('test_file.txt') | |
class FileModeBearTest(LocalBearTestHelper): | |
def setUp(self): | |
self.section = Section('') | |
self.uut = FileModeBear(self.section, Queue()) | |
def test_r_to_r_permissions(self): | |
os.chmod(FILE_PATH, stat.S_IRUSR) | |
self.section.append(Setting('filemode', 'r')) | |
self.check_results( | |
self.uut, | |
[], | |
[], | |
filename=FILE_PATH, | |
) | |
def test_w_to_w_permissions(self): | |
os.chmod(FILE_PATH, stat.S_IWUSR) | |
self.section.append(Setting('filemode', 'w')) | |
self.check_results( | |
self.uut, | |
[], | |
[], | |
filename=FILE_PATH, | |
) | |
def test_x_to_x_permissions(self): | |
os.chmod(FILE_PATH, stat.S_IXUSR) | |
if platform.system() != 'Windows': | |
self.section.append(Setting('filemode', 'x')) | |
self.check_results( | |
self.uut, | |
[], | |
[], | |
filename=FILE_PATH, | |
) | |
def test_rw_to_rw_permissions(self): | |
os.chmod(FILE_PATH, stat.S_IRUSR | stat.S_IWUSR) | |
self.section.append(Setting('filemode', 'rw')) | |
self.check_results( | |
self.uut, | |
[], | |
[], | |
filename=FILE_PATH, | |
) | |
def test_wx_to_wx_permissions(self): | |
os.chmod(FILE_PATH, stat.S_IWUSR | stat.S_IXUSR) | |
if platform.system() != 'Windows': | |
self.section.append(Setting('filemode', 'wx')) | |
self.check_results( | |
self.uut, | |
[], | |
[], | |
filename=FILE_PATH, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment