Skip to content

Python script which checks if the files are equal totally or partially depending on target criteria

License

Notifications You must be signed in to change notification settings

PasaOpasen/files-equality-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

files-equality-checker

The purpose of this script is to perform many checks on the files that must be equal totally or partially depending on a target (configuration) criteria.

Now it supports next checks:

  • equality of binary files (requires installed requirements.txt)
  • equality of text files with usual diff output
  • equality of regions in text files (usually *.py files)

CLI

python fec.py --help
usage: fec.py [-h] [-r] CONFIG_FILE

Script which which checks if the files are equal totally or partially depending on target criteria

positional arguments:
  CONFIG_FILE           json file with the comparing configuration

optional arguments:
  -h, --help            show this help message and exit
  -r, --raise-on-errors
                        whether to raise an Exception when some differences are found (default: False)

Example

Text file:

#region RG 1
1
1
1
#endregion


# region RG 2
2
2
2
# endregion

#region RG 3

# region RG 3.1
3.1
#endregion

#region RG 3.2
3.2
#endregion

# endregion

Config file:

[
    {
        "source": "tests/data/regions.py",
        "dest": "tests/data/regions.py"
    },
    {
        "source": "tests/data/regions.py",
        "dest": "tests/data/regions.py",
        "regions": [
            {
                "in_source": "RG 1",
                "in_dest": "RG 1"
            },
            {
                "in_source": "RG 1",
                "in_dest": "RG 3"
            }
        ]
    },
    {
        "source": "tests/dir1",
        "dest": "tests/dir2",
        "file_regex": ".*\\.txt"
    }
]

Command:

python fec.py tests/data/config.json

Output:

Reading the config from tests/data/config.json...


Comparing tests/data/regions.py <---> tests/data/regions.py    OK
Comparing tests/data/regions.py <---> tests/data/regions.py
     Comparing regions 'RG 1' <---> 'RG 1'     OK
     Comparing regions 'RG 1' <---> 'RG 3'     FAILURE
        --- region 'RG 1' in tests/data/regions.py (chars [15:21])
        
        +++ region 'RG 3' in tests/data/regions.py (chars [80:144])
        
        @@ -1,3 +1,9 @@
        
        -1
        -1
        -1
        +
        +# region RG 3.1
        +3.1
        +#endregion
        +
        +#region RG 3.2
        +3.2
        +#endregion
        +
Comparing tests/dir1 <---> tests/dir2    ARE DIRS
>>> Comparing tests/dir1/file1.txt <---> tests/dir2/file1.txt    OK
>>> Comparing tests/dir1/dir-inner/file2.txt <---> tests/dir2/dir-inner/file2.txt    OK
>>> Comparing tests/dir1/dir-inner/file3.txt <---> tests/dir2/dir-inner/file3.txt    FAILURE
    no destination file

SOME DIFFS FOUND

About

Python script which checks if the files are equal totally or partially depending on target criteria

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published