python类dircmp()的实例源码

test_utils.py 文件源码 项目:cfgcaddy 作者: tstapler 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_both_dirs_exist(self):
        self.source_tree = {
            "file1": "stuff",
            "file2": "stuff",
            "dir1": {
                "file3": "stuff"
            }
        }
        self.dest_tree = {
            "file4": "stuff",
            "file5": "stuff",
            "dir2": {
                "file6": "stuff"
            }
        }

        create_files_from_tree(self.source_tree, parent=self.source_dir)
        create_files_from_tree(self.dest_tree, parent=self.dest_dir)
        self.link_and_print()
        result = dircmp(self.source_dir, self.dest_dir)
        self.recursive_dircmp(result)
test_sdk_sanity.py 文件源码 项目:lago 作者: lago-project 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_extract_paths(tmpdir, randomized_dir, vms, vm_name, mode):
    if mode == 'dead':
        pytest.skip('extract_paths_dead is not stable in CI')
    vm = vms[vm_name]
    dst = '/root/extract-{vm}-{mode}'.format(vm=vm_name, mode=mode)
    vm.copy_to(randomized_dir.path, dst, recursive=True)
    res = vm.ssh(['sync'])
    assert res.code == 0
    if mode == 'normal':
        extract = getattr(vm, 'extract_paths')
    elif mode == 'dead':
        extract = getattr(vm, 'extract_paths_dead')
    extracted_path = str(tmpdir)
    extract([(dst, extracted_path)], ignore_nopath=False)

    cmp_res = filecmp.dircmp(
        os.path.join(extracted_path, os.path.basename(dst)),
        randomized_dir.path
    )
    assert sorted(cmp_res.left_list) == sorted(cmp_res.right_list)


# todo: Test extract_paths_dead once we figure why it's unstable in CI
file_cmp_class.py 文件源码 项目:Automation-Framework-for-devices 作者: tok-gogogo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def stdout_file(self,path1,path2):
        oldStdout = None
        logfile = None
        x = filecmp.dircmp(path1,path2)
        path1 = os.path.abspath(sys.argv[0])
        filepath = os.path.dirname(path1)
        self.find_file = filepath  + "\\find_file.log"
        try:  
            logfile = open( self.find_file,'w+')
            oldStdout = sys.stdout  
            sys.stdout = logfile
            x.report_full_closure()
        finally:  
            if logfile:  
                logfile.close()  
                if oldStdout:  
                    sys.stdout = oldStdout  
        result = self.find_str(self.find_file)
        return result
utils.py 文件源码 项目:sketch-components 作者: ibhubs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def phase0(self):
        return super(dircmp, self).phase0()
utils.py 文件源码 项目:sketch-components 作者: ibhubs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def phase1(self):
        return super(dircmp, self).phase1()
utils.py 文件源码 项目:sketch-components 作者: ibhubs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def phase2(self):
        return super(dircmp, self).phase2()
utils.py 文件源码 项目:sketch-components 作者: ibhubs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def phase4(self):  # Find out differences between common subdirectories
        # A new dircmp object is created for each common subdirectory,
        # these are stored in a dictionary indexed by filename.
        # The hide and ignore properties are inherited from the parent
        self.subdirs = {}
        for x in self.common_dirs:
            a_x = os.path.join(self.left, x)
            b_x = os.path.join(self.right, x)
            self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide)
test_driver.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _dirs_are_unequal(dir1, dir2):
    """Returns True if dir1 and dir2 are unequal"""
    dircmps = [filecmp.dircmp(dir1, dir2)]
    while len(dircmps):
        dircmp = dircmps.pop()
        if dircmp.left_only or dircmp.right_only:
            logger.error("The following files and directories are only "
                         "present in one directory")
            if dircmp.left_only:
                logger.error(dircmp.left_only)
            else:
                logger.error(dircmp.right_only)
            return True
        elif dircmp.common_funny or dircmp.funny_files:
            logger.error("The following files and directories could not be "
                         "compared:")
            if dircmp.common_funny:
                logger.error(dircmp.common_funny)
            else:
                logger.error(dircmp.funny_files)
            return True
        elif dircmp.diff_files:
            logger.error("The following files differ:")
            logger.error(dircmp.diff_files)
            return True

        for subdir in dircmp.subdirs.itervalues():
            dircmps.append(subdir)

    return False
defineCMS.py 文件源码 项目:comission 作者: Intrinsec 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def check_core_alteration(self, dir_path, core_url):
        alterations = []
        ignored = [".git", "cache", "plugins", "themes", "images", "license.txt", "readme.html",
                   "version.php"]

        temp_directory = uCMS.TempDir.create()

        log.print_cms("info", "[+] Checking core alteration", "", 0)

        try:
            response = requests.get(core_url)
            response.raise_for_status()

            if response.status_code == 200:
                zip_file = zipfile.ZipFile(io.BytesIO(response.content), 'r')
                zip_file.extractall(temp_directory)
                zip_file.close()

        except requests.exceptions.HTTPError as e:
            msg = "[-] The original WordPress archive has not been found. Search manually ! "
            log.print_cms("alert", msg, "", 0)
            return msg, e

        clean_core_path = os.path.join(temp_directory, "wordpress")

        dcmp = dircmp(clean_core_path, dir_path, ignored)
        uCMS.diff_files(dcmp, alterations, dir_path)

        if alterations is not None:
            msg = "[+] For further analysis, archive downloaded here : " + clean_core_path
            log.print_cms("info", msg, "", 1)

        return alterations, None
defineCMS.py 文件源码 项目:comission 作者: Intrinsec 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def check_core_alteration(self, dir_path, version_core, core_url):
        alterations = []
        ignored = ["modules", "CHANGELOG.txt", "COPYRIGHT.txt", "LICENSE.txt", "MAINTAINERS.txt",
                   "INSTALL.txt", "README.txt"]

        temp_directory = uCMS.TempDir.create()

        log.print_cms("info", "[+] Checking core alteration", "", 0)

        try:
            response = requests.get(core_url)
            response.raise_for_status()

            if response.status_code == 200:
                zip_file = zipfile.ZipFile(io.BytesIO(response.content), 'r')
                zip_file.extractall(temp_directory)
                zip_file.close()

        except requests.exceptions.HTTPError as e:
            msg = "[-] The original drupal archive has not been found. Search " \
                  "manually ! "
            log.print_cms("alert", msg, "", 0)
            return msg, e

        clean_core_path = os.path.join(temp_directory, "drupal-" + version_core)

        dcmp = dircmp(clean_core_path, dir_path, ignored)
        uCMS.diff_files(dcmp, alterations, dir_path)

        return alterations, None
compare_folders.py 文件源码 项目:compare_folders 作者: Pixinn 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def build_common_files(dcmp):
    # listing common files in dir
    commonFiles = []
    for filename in dcmp.common_files:
        commonFiles.append(dcmp.left + "/" + filename)
    # listing in sub-dirs
    for subdir in dcmp.common_dirs:
        subCommonFiles = build_common_files(dircmp(dcmp.left + "/" + subdir, dcmp.right + "/" + subdir))
        for filename in subCommonFiles:
            commonFiles.append(filename)
    commonFiles.sort()
    return commonFiles


# HASHING A FILE, READ BY 16M CHUNKS NOT TO OVERLOAD MEMORY
test_filecmp.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        d = filecmp.dircmp(self.dir, self.dir_same)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertEqual(d.common, ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, [])

        # Check attributes for comparison of two different directories
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertEqual(d.left_list, ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertEqual(d.common, ['file'])
        self.assertEqual(d.left_only, [])
        self.assertEqual(d.right_only, ['file2'])
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, ['file2'])
link_pyqt.py 文件源码 项目:qt_style_sheet_inspector 作者: ESSS 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def needs_update(source, dest):
    """Check if a file to be linked/copied needs to be updated."""
    if os.path.islink(dest):
        # No need to delete a link and relink -> skip this
        return False
    elif os.path.isdir(dest):
        diffs = filecmp.dircmp(source, dest)
        ignored = get_ignored_files(source, diffs.left_only)
        has_new_files = set(ignored) != set(diffs.left_only)
        return (has_new_files or diffs.right_only or
                diffs.common_funny or diffs.diff_files or
                diffs.funny_files)
    else:
        return not filecmp.cmp(source, dest)
test_driver.py 文件源码 项目:certbot 作者: nikoloskii 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _dirs_are_unequal(dir1, dir2):
    """Returns True if dir1 and dir2 are unequal"""
    dircmps = [filecmp.dircmp(dir1, dir2)]
    while len(dircmps):
        dircmp = dircmps.pop()
        if dircmp.left_only or dircmp.right_only:
            logger.error("The following files and directories are only "
                         "present in one directory")
            if dircmp.left_only:
                logger.error(dircmp.left_only)
            else:
                logger.error(dircmp.right_only)
            return True
        elif dircmp.common_funny or dircmp.funny_files:
            logger.error("The following files and directories could not be "
                         "compared:")
            if dircmp.common_funny:
                logger.error(dircmp.common_funny)
            else:
                logger.error(dircmp.funny_files)
            return True
        elif dircmp.diff_files:
            logger.error("The following files differ:")
            logger.error(dircmp.diff_files)
            return True

        for subdir in dircmp.subdirs.itervalues():
            dircmps.append(subdir)

    return False
test_filecmp.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        d = filecmp.dircmp(self.dir, self.dir_same)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Check attributes for comparison of two different directories
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.left_list == ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == [])
        self.assertTrue(d.right_only == ['file2'])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == ['file2'])
test_filecmp.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        d = filecmp.dircmp(self.dir, self.dir_same)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Check attributes for comparison of two different directories
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.left_list == ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == [])
        self.assertTrue(d.right_only == ['file2'])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == ['file2'])
difference.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def report_difference(casedirpath):
    # get the directories to be compared
    refpath = os.path.join(casedirpath, "ref")
    outpath = os.path.join(casedirpath, "out")
    if not os.path.isdir(refpath):
        print "Test case has no reference directory"
        return
    if not os.path.isdir(refpath):
        print "Test case has no output directory"
        return

    # check for recursive subdirectories
    if len(filter(lambda fn: os.path.isdir(fn), os.listdir(refpath))) > 0:
        print "Reference directory contains a subdirectory"
        return
    if len(filter(lambda fn: os.path.isdir(fn), os.listdir(outpath))) > 0:
        print "Output directory contains a sub directory"
        return

    # verify list of filenames
    dircomp = filecmp.dircmp(outpath, refpath, ignore=['.DS_Store'])
    if (len(dircomp.left_only) > 0):
        print "Output contains " + str(len(dircomp.left_only)) + " extra file(s)"
    if (len(dircomp.right_only) > 0):
        print "Output misses " + str(len(dircomp.right_only)) + " file(s)"

    # compare common files
    matches, mismatches, errors = filecmp.cmpfiles(outpath, refpath, dircomp.common, shallow=False)
    for filename in matches:
        print "Output file matches: " + filename
    for filename in mismatches + errors:
        if equalfiles(os.path.join(outpath, filename), os.path.join(refpath, filename)):
            print "Output file matches: " + filename
        else:
            print "Output file differs: " + filename + "     <-------"

# -----------------------------------------------------------------

# get the command-line argument specifying the target directory, if any
difference.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def report_difference(casedirpath):
    # get the directories to be compared
    refpath = os.path.join(casedirpath, "ref")
    outpath = os.path.join(casedirpath, "out")
    if not os.path.isdir(refpath):
        print "Test case has no reference directory"
        return
    if not os.path.isdir(refpath):
        print "Test case has no output directory"
        return

    # check for recursive subdirectories
    if len(filter(lambda fn: os.path.isdir(fn), os.listdir(refpath))) > 0:
        print "Reference directory contains a subdirectory"
        return
    if len(filter(lambda fn: os.path.isdir(fn), os.listdir(outpath))) > 0:
        print "Output directory contains a sub directory"
        return

    # verify list of filenames
    dircomp = filecmp.dircmp(outpath, refpath, ignore=['.DS_Store'])
    if (len(dircomp.left_only) > 0):
        print "Output contains " + str(len(dircomp.left_only)) + " extra file(s)"
    if (len(dircomp.right_only) > 0):
        print "Output misses " + str(len(dircomp.right_only)) + " file(s)"

    # compare common files
    matches, mismatches, errors = filecmp.cmpfiles(outpath, refpath, dircomp.common, shallow=False)
    for filename in matches:
        print "Output file matches: " + filename
    for filename in mismatches + errors:
        if equalfiles(os.path.join(outpath, filename), os.path.join(refpath, filename)):
            print "Output file matches: " + filename
        else:
            print "Output file differs: " + filename + "     <-------"

# -----------------------------------------------------------------

# get the command-line argument specifying the target directory, if any
link_pyqt.py 文件源码 项目:tahoe-gui 作者: LeastAuthority 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def needs_update(source, dest):
    """Check if a file to be linked/copied needs to be updated."""
    if os.path.islink(dest):
        # No need to delete a link and relink -> skip this
        return False
    elif os.path.isdir(dest):
        diffs = filecmp.dircmp(source, dest)
        ignored = get_ignored_files(source, diffs.left_only)
        has_new_files = set(ignored) != set(diffs.left_only)
        return (has_new_files or diffs.right_only or
                diffs.common_funny or diffs.diff_files or
                diffs.funny_files)
    else:
        return not filecmp.cmp(source, dest)
test_filecmp.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        left_dir, right_dir = self.dir, self.dir_same
        d = filecmp.dircmp(left_dir, right_dir)
        self.assertEqual(d.left, left_dir)
        self.assertEqual(d.right, right_dir)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertEqual(d.common, ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, [])

        # Check attributes for comparison of two different directories
        left_dir, right_dir = self.dir, self.dir_diff
        d = filecmp.dircmp(left_dir, right_dir)
        self.assertEqual(d.left, left_dir)
        self.assertEqual(d.right, right_dir)
        self.assertEqual(d.left_list, ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertEqual(d.common, ['file'])
        self.assertEqual(d.left_only, [])
        self.assertEqual(d.right_only, ['file2'])
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertEqual(d.same_files, ['file'])
        self.assertEqual(d.diff_files, ['file2'])
project.py 文件源码 项目:swift-source-compat-suite 作者: apple 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def check_full_vs_incr(self, seq, sha, stdout=sys.stdout):
        full = self.saved_build_state_path(seq, 'full', sha)
        incr = self.saved_build_state_path(seq, 'incr', sha)
        common.debug_print("Comparing dirs %s vs. %s" % (os.path.relpath(full),
                                                         os.path.basename(incr)),
                           stderr=stdout)
        d = filecmp.dircmp(full, incr, self.ignored_differences())
        if not have_same_trees(full, incr, d):
            message = ("Dirs differ: %s vs. %s" %
                       (os.path.relpath(full),
                        os.path.basename(incr)))
            if self.expect_determinism():
                raise EarlyExit(ActionResult(Result.FAIL, message))
            else:
                common.debug_print(message, stderr=stdout)
project_future.py 文件源码 项目:swift-source-compat-suite 作者: apple 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def check_full_vs_incr(self, seq, sha, stdout=sys.stdout):
        full = self.saved_build_state_path(seq, 'full', sha)
        incr = self.saved_build_state_path(seq, 'incr', sha)
        common.debug_print("Comparing dirs %s vs. %s" % (os.path.relpath(full),
                                                         os.path.basename(incr)),
                           stderr=stdout)
        d = filecmp.dircmp(full, incr, self.ignored_differences())
        if not have_same_trees(full, incr, d):
            message = ("Dirs differ: %s vs. %s" %
                       (os.path.relpath(full),
                        os.path.basename(incr)))
            if self.expect_determinism():
                raise EarlyExit(ActionResult(Result.FAIL, message))
            else:
                common.debug_print(message, stderr=stdout)
manualtools.py 文件源码 项目:skaff 作者: jhxie 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def manpath_select(select: bool=True) -> Union[str, List[str]]:
    """
    Parses the output of the 'manpath' program and returns one of its non-empty
    results (non-empty directory) if 'select' is set to True; otherwise returns
    all the results un-altered.

    NOTE: A platform-dependent path separator will be appended to the result.
    """
    paths = None
    result_manpath = None

    with os.popen("manpath") as proc, TemporaryDirectory() as tmpdir:
        paths = proc.read().strip().split(os.pathsep)
        if select:
            for candidate in paths:
                # "Elect" the candidate directory with "rich" non-empty status
                if dircmp(candidate, tmpdir).left_only:
                    result_manpath = candidate
                    break

    if not paths:
        raise RuntimeError("Output of the 'manpath' program cannot be parsed")

    if select and not result_manpath:
        raise RuntimeError("All the directories in 'manpath' is empty")

    if select:
        if result_manpath.endswith(os.sep):
            return result_manpath
        else:
            return result_manpath + os.sep
    else:
        return [path + os.sep for path in paths if not path.endswith(os.sep)]
# -------------------------------- FUNCTIONS ----------------------------------
diff.py 文件源码 项目:copyright 作者: rsmz 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def diffdir(d1, d2):
    result = dircmp(d1, d2)
    return find_diff_files(result)
diff.py 文件源码 项目:copyright 作者: rsmz 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def find_diff_files(dcmp):
    '''Return list of differing or missing relative filenames.

    Args
    ----
    dcmp: class filecmp.dircmp
    '''
    # print('left ', dcmp.left_only)
    # print('right ', dcmp.right_only)
    # print('diff ', dcmp.diff_files)
    left_only = filter_files(dcmp.left_only, dcmp.left)
    right_only = filter_files(dcmp.right_only, dcmp.right)
    diff_files = filter_files(dcmp.diff_files, dcmp.right)
    result = left_only + right_only + diff_files

    for sub in dcmp.subdirs.values():
        result += find_diff_files(sub)

    return result

# copyright - Add or replace license boilerplate.
# Copyright (C) 2016 Remik Ziemlinski
# 
# copyright is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# copyright is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
test_filecmp.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        d = filecmp.dircmp(self.dir, self.dir_same)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Check attributes for comparison of two different directories
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.left_list == ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == [])
        self.assertTrue(d.right_only == ['file2'])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == ['file2'])
test_filecmp.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_report_partial_closure(self):
        left_dir, right_dir = self.dir, self.dir_same
        d = filecmp.dircmp(left_dir, right_dir)
        expected_report = [
            "diff {} {}".format(self.dir, self.dir_same),
            "Identical files : ['file']",
        ]
        self._assert_report(d.report_partial_closure, expected_report)
test_filecmp.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_report_full_closure(self):
        left_dir, right_dir = self.dir, self.dir_same
        d = filecmp.dircmp(left_dir, right_dir)
        expected_report = [
            "diff {} {}".format(self.dir, self.dir_same),
            "Identical files : ['file']",
        ]
        self._assert_report(d.report_full_closure, expected_report)
test_filecmp.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_dircmp(self):
        # Check attributes for comparison of two identical directories
        d = filecmp.dircmp(self.dir, self.dir_same)
        if self.caseinsensitive:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
        else:
            self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == d.right_only == [])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Check attributes for comparison of two different directories
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.left_list == ['file'])
        self.assertTrue(d.right_list == ['file', 'file2'])
        self.assertTrue(d.common == ['file'])
        self.assertTrue(d.left_only == [])
        self.assertTrue(d.right_only == ['file2'])
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == [])

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()
        d = filecmp.dircmp(self.dir, self.dir_diff)
        self.assertTrue(d.same_files == ['file'])
        self.assertTrue(d.diff_files == ['file2'])
test_command.py 文件源码 项目:USTC-Software-2017 作者: igemsoftware2017 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def assertDirsIdentical(self, dir1, dir2):
        result = filecmp.dircmp(dir1, dir2)

        if result.diff_files or result.left_only or result.right_only:
            raise AssertionError(
                "'%s' and '%s' is not exactly identical.\n"
                "Diff files: %r\n"
                "Left only:  %r\n"
                "Right only: %r\n" % (
                    dir1, dir2,
                    result.diff_files,
                    result.left_only,
                    result.right_only))


问题


面经


文章

微信
公众号

扫码关注公众号