From: Douglas Bagnall Date: Fri, 14 Mar 2025 06:52:57 +0000 (+1300) Subject: pytest: samba-tool gpo: fix has_difference(sortlines=True) X-Git-Tag: samba-4.21.6~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5230c26adb5ff87ee9a092f0e96542536fe87b5;p=thirdparty%2Fsamba.git pytest: samba-tool gpo: fix has_difference(sortlines=True) We had file1 = open(path1).readlines() file1.sort() file2 = open(path1).readlines() file2.sort() which is opening path1 in both cases. This meant we were testing nothing because the assertions are all that the files are the same -- though the only affected check is one in test_backup_restore_generalize(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=15829 Signed-off-by: Douglas Bagnall Reviewed-by: Jennifer Sutton (cherry picked from commit 6b619b568f6661d3a5f0701cdfaf1e1e4943ff6f) --- diff --git a/python/samba/tests/samba_tool/gpo.py b/python/samba/tests/samba_tool/gpo.py index 714f8e54d8d..6df9c9fb5b6 100644 --- a/python/samba/tests/samba_tool/gpo.py +++ b/python/samba/tests/samba_tool/gpo.py @@ -141,21 +141,27 @@ source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../ provision_path = os.path.join(source_path, "source4/selftest/provisions/") def has_difference(path1, path2, binary=True, xml=True, sortlines=False): - """Use this function to determine if the GPO backup differs from another. + """Use this function to determine if the GPO backup differs from + another. It can compare pairs of files or pairs of directories. xml=True checks whether any xml files are equal binary=True checks whether any .SAMBABACKUP files are equal + sortlines=True ignore order of lines in comparison of single + files. + + returns None if there is no difference between the paths, + otherwise *something*. """ if os.path.isfile(path1): + with open(path1) as f1, open(path2) as f2: + lines1 = f1.readlines() + lines2 = f2.readlines() + if sortlines: - file1 = open(path1).readlines() - file1.sort() - file2 = open(path1).readlines() - file2.sort() - if file1 != file2: - return path1 - - elif open(path1).read() != open(path2).read(): + lines1.sort() + lines2.sort() + + if lines1 != lines2: return path1 return None diff --git a/selftest/knownfail.d/samba-tool-gpo b/selftest/knownfail.d/samba-tool-gpo new file mode 100644 index 00000000000..097495bba08 --- /dev/null +++ b/selftest/knownfail.d/samba-tool-gpo @@ -0,0 +1,2 @@ +^samba.tests.samba_tool.gpo.+GpoCmdTestCase.test_backup_restore_generalize +