mirror of
https://github.com/samba-team/samba.git
synced 2025-12-18 08:23:51 +03:00
tests: Fix use of self.assertRaises()
The with statement creates a new variable. I thought it opens a block where "e" is only valid in that block. But instead it runs the whole thing, expecting an exception somewhere. Learning python.... Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: David Mulder <dmulder@samba.org>
This commit is contained in:
@@ -57,7 +57,9 @@ class ReparsePoints(samba.tests.libsmb.LibsmbTests):
|
||||
|
||||
with self.assertRaises(NTSTATUSError) as e:
|
||||
conn.fsctl(fd, libsmb.FSCTL_GET_REPARSE_POINT, b'', 1024)
|
||||
self.assertEqual(e.args[0], ntstatus.NT_STATUS_NOT_A_REPARSE_POINT)
|
||||
|
||||
self.assertEqual(e.exception.args[0],
|
||||
ntstatus.NT_STATUS_NOT_A_REPARSE_POINT)
|
||||
|
||||
conn.close(fd)
|
||||
|
||||
@@ -129,8 +131,9 @@ class ReparsePoints(samba.tests.libsmb.LibsmbTests):
|
||||
filename,
|
||||
DesiredAccess=sec.SEC_STD_DELETE,
|
||||
CreateDisposition=libsmb.FILE_CREATE)
|
||||
self.assertEqual(
|
||||
e.args[0], ntstatus.NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED)
|
||||
|
||||
self.assertEqual(e.exception.args[0],
|
||||
ntstatus.NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED)
|
||||
|
||||
conn.delete_on_close(dir_fd, 1)
|
||||
conn.close(dir_fd);
|
||||
@@ -198,7 +201,9 @@ class ReparsePoints(samba.tests.libsmb.LibsmbTests):
|
||||
DesiredAccess=sec.SEC_FILE_READ_DATA,
|
||||
CreateDisposition=libsmb.FILE_OPEN,
|
||||
CreateOptions=libsmb.FILE_OPEN_REPARSE_POINT)
|
||||
self.assertEqual(e.args[0], ntstatus.NT_STATUS_SHARING_VIOLATION)
|
||||
|
||||
self.assertEqual(e.exception.args[0],
|
||||
ntstatus.NT_STATUS_SHARING_VIOLATION)
|
||||
|
||||
conn.delete_on_close(fd1, 1);
|
||||
conn.close(fd1)
|
||||
|
||||
@@ -91,11 +91,13 @@ class Smb2SymlinkTests(samba.tests.libsmb.LibsmbTests):
|
||||
|
||||
with self.assertRaises(NTSTATUSError) as e:
|
||||
fd = smb2.create_ex(f'{symlink}\\{suffix}')
|
||||
self.assert_symlink_exception(
|
||||
e, { 'unparsed_path_length' : len(suffix)+1,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0x20000001 })
|
||||
|
||||
self.assert_symlink_exception(
|
||||
e.exception,
|
||||
{ 'unparsed_path_length' : len(suffix)+1,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0x20000001 })
|
||||
|
||||
self.clean_file(smb1, symlink)
|
||||
|
||||
@@ -109,11 +111,13 @@ class Smb2SymlinkTests(samba.tests.libsmb.LibsmbTests):
|
||||
|
||||
with self.assertRaises(NTSTATUSError) as e:
|
||||
fd = smb2.create_ex(f'{symlink}')
|
||||
self.assert_symlink_exception(
|
||||
e, { 'unparsed_path_length' : 0,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0x20000001 })
|
||||
|
||||
self.assert_symlink_exception(
|
||||
e.exception,
|
||||
{ 'unparsed_path_length' : 0,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0x20000001 })
|
||||
|
||||
self.clean_file(smb1, symlink)
|
||||
|
||||
@@ -131,11 +135,13 @@ class Smb2SymlinkTests(samba.tests.libsmb.LibsmbTests):
|
||||
|
||||
with self.assertRaises(NTSTATUSError) as e:
|
||||
fd = smb2.create_ex(f'{symlink}')
|
||||
self.assert_symlink_exception(
|
||||
e, { 'unparsed_path_length' : 0,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0 })
|
||||
|
||||
self.assert_symlink_exception(
|
||||
e.exception,
|
||||
{ 'unparsed_path_length' : 0,
|
||||
'substitute_name' : target,
|
||||
'print_name' : target,
|
||||
'flags' : 0 })
|
||||
|
||||
self.clean_file(smb1, symlink)
|
||||
|
||||
@@ -153,11 +159,13 @@ class Smb2SymlinkTests(samba.tests.libsmb.LibsmbTests):
|
||||
|
||||
with self.assertRaises(NTSTATUSError) as e:
|
||||
fd = smb2.create_ex(f'{symlink}')
|
||||
self.assert_symlink_exception(
|
||||
e, { 'unparsed_path_length' : 0,
|
||||
'substitute_name' : rel_dest,
|
||||
'print_name' : rel_dest,
|
||||
'flags' : 0 })
|
||||
|
||||
self.assert_symlink_exception(
|
||||
e.exception,
|
||||
{ 'unparsed_path_length' : 0,
|
||||
'substitute_name' : rel_dest,
|
||||
'print_name' : rel_dest,
|
||||
'flags' : 0 })
|
||||
|
||||
self.clean_file(smb1, symlink)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user