-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool "diff" for Linux and Unix (#3501)
* Update __init__.py * Add files via upload * Update diff.py
- Loading branch information
1 parent
b3e1f46
commit 681f5bd
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
from pathlib import PurePath | ||
from typing import Optional | ||
|
||
from lisa.executable import Tool | ||
|
||
|
||
class Diff(Tool): | ||
""" | ||
Diff is a tool class for comparing files or directories using the 'diff' command. | ||
Attributes: | ||
command (str): The command to be executed, which is 'diff'. | ||
can_install (bool): Indicates whether the tool can be installed. | ||
Always False for this tool. | ||
Methods: | ||
_check_exists() -> bool: | ||
Checks if the tool exists. Always returns True for this tool. | ||
comparefiles( | ||
timeout: int = 600 | ||
Compares two files or directories. | ||
Args: | ||
src (PurePath): The source file or directory. | ||
dest (PurePath): The destination file or directory. | ||
cwd (Optional[PurePath]): The current working directory for the command. | ||
Defaults to None. | ||
sudo (bool): Whether to run the command with sudo. Defaults to False. | ||
timeout (int): The timeout for the command in seconds. Defaults to 600. | ||
Returns: | ||
str: The output of the diff command. | ||
Raises: | ||
AssertionError: If the exit code of the diff command is not 0 or 1. | ||
""" | ||
|
||
@property | ||
def command(self) -> str: | ||
return "diff" | ||
|
||
@property | ||
def can_install(self) -> bool: | ||
return False | ||
|
||
def comparefiles( | ||
self, | ||
src: PurePath, | ||
dest: PurePath, | ||
cwd: Optional[PurePath] = None, | ||
sudo: bool = False, | ||
timeout: int = 600, | ||
) -> str: | ||
cmd = f"{self.node.get_str_path(src)} {self.node.get_str_path(dest)}" | ||
result = self.run( | ||
cmd, | ||
force_run=True, | ||
sudo=sudo, | ||
cwd=cwd, | ||
shell=True, | ||
timeout=timeout, | ||
) | ||
# Diff generated difference between FILE1 FILE2 or DIR1 DIR2 or DIR FILE | ||
# for FILE DIR | ||
# EXit status is 0 if inputs are the same. 1 if different, 2 if trouble | ||
result.assert_exit_code([0, 1], f"Diff Error: {result.stderr}") | ||
return result.stdout |