def test_no_print_set(self): """Function: test_no_print_set Description: Test with no_print option set. Arguments: """ err_msg_chk = self.err_mask % (self.d_name) status, err_msg = gen_libs.chk_crt_dir(self.d_name, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_dir_not_exist(self): """Function: test_dir_not_exist Description: Test with directory does not exist. Arguments: """ err_msg_chk = self.err_mask % (self.d_name) status, err_msg = gen_libs.chk_crt_dir(self.d_name, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_no_dir_name(self): """Function: test_no_dir_name Description: Test with no directory name passed. Arguments: """ err_msg_chk = "Error: No value passed for directory name" status, err_msg = gen_libs.chk_crt_dir("", no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_print_file2(self): """Function: test_print_file2 Description: Test with printing error messages to file. Arguments: """ err_msg_chk = self.err_mask % (self.d_name) f_hdlr = open(self.f_name, "w") _, _ = gen_libs.chk_crt_dir(self.d_name, f_hdlr=f_hdlr, no_print=True) f_hdlr.close() self.assertFalse(err_msg_chk in open(self.f_name).read())
def test_create_dir(self): """Function: test_create_dir Description: Test with creating directory. Arguments: """ err_msg_chk = None status, err_msg = gen_libs.chk_crt_dir(self.d_name, create=True, no_print=True) self.assertTrue(status) self.assertEqual(err_msg, err_msg_chk)
def test_read_dir(self): """Function: test_read_dir Description: Test with checking read permission on directory. Arguments: """ err_msg_chk = None os.makedirs(self.d_name) status, err_msg = gen_libs.chk_crt_dir(self.d_name, read=True, no_print=True) self.assertTrue(status) self.assertEqual(err_msg, err_msg_chk)
def test_exe_file(self): """Function: test_exe_file Description: Test with checking execute permission on file. Arguments: """ err_msg_chk = None os.makedirs(self.d_name) os.chmod(self.d_name, 0755) status, err_msg = gen_libs.chk_crt_dir(self.d_name, exe=True, no_print=True) self.assertTrue(status) self.assertEqual(err_msg, err_msg_chk)
def test_print_file(self): """Function: test_print_file Description: Test with printing error messages to file. Arguments: """ err_msg_chk = self.err_mask % (self.d_name) f_hdlr = open(self.f_name, "w") status, err_msg = gen_libs.chk_crt_dir(self.d_name, f_hdlr=f_hdlr, no_print=True) f_hdlr.close() self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_no_read_dir(self): """Function: test_no_read_dir Description: Test with checking no read permission on directory. Arguments: """ err_msg_chk = self.prt_template3 % (self.d_name) os.makedirs(self.d_name) os.chmod(self.d_name, 0333) status, err_msg = gen_libs.chk_crt_dir(self.d_name, read=True, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_no_exe_file(self): """Function: test_no_exe_file Description: Test with checking no execute permission on file. Arguments: """ err_msg_chk = self.prt_template4 % (self.d_name) os.makedirs(self.d_name) os.chmod(self.d_name, 0444) status, err_msg = gen_libs.chk_crt_dir(self.d_name, exe=True, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_no_write_dir(self): """Function: test_no_write_dir Description: Test with checking no write permission on directory. Arguments: """ err_msg_chk = "Error: Directory %s is not writeable." % (self.d_name) os.makedirs(self.d_name) os.chmod(self.d_name, 0444) status, err_msg = gen_libs.chk_crt_dir(self.d_name, write=True, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_multiple_errors2(self): """Function: test_multiple_errors2 Description: Test with exist and read errors. Arguments: """ err_msg_chk = self.prt_template % (self.d_name) err_msg_chk2 = self.prt_template3 % (self.d_name) err_msg_chk = "\n".join([err_msg_chk, err_msg_chk2]) err_msg_chk = err_msg_chk.strip("\n") status, err_msg = gen_libs.chk_crt_dir(self.d_name, read=True, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)
def test_multiple_errors(self): """Function: test_multiple_errors Description: Test with read and write errors. Arguments: """ err_msg_chk = self.prt_template2 % (self.d_name) err_msg_chk2 = self.prt_template3 % (self.d_name) err_msg_chk = "\n".join([err_msg_chk, err_msg_chk2]) err_msg_chk = err_msg_chk.strip("\n") os.makedirs(self.d_name) os.chmod(self.d_name, 0111) status, err_msg = gen_libs.chk_crt_dir(self.d_name, write=True, read=True, no_print=True) self.assertFalse(status) self.assertEqual(err_msg, err_msg_chk)