cli-test-framework 0.2.1__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {cli_test_framework-0.2.1/src/cli_test_framework.egg-info → cli_test_framework-0.2.3}/PKG-INFO +1 -1
  2. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/setup.py +47 -47
  3. cli_test_framework-0.2.3/src/cli_test_framework/__init__.py +21 -0
  4. cli_test_framework-0.2.3/src/cli_test_framework/cli.py +132 -0
  5. cli_test_framework-0.2.3/src/cli_test_framework/commands/__init__.py +9 -0
  6. cli_test_framework-0.2.3/src/cli_test_framework/commands/compare.py +180 -0
  7. cli_test_framework-0.2.3/src/cli_test_framework/core/__init__.py +15 -0
  8. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/core/assertions.py +31 -31
  9. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/__init__.py +9 -0
  10. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/base_comparator.py +107 -0
  11. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/binary_comparator.py +242 -0
  12. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/csv_comparator.py +140 -0
  13. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/factory.py +141 -0
  14. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/h5_comparator.py +423 -0
  15. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/json_comparator.py +326 -0
  16. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/result.py +191 -0
  17. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/text_comparator.py +177 -0
  18. cli_test_framework-0.2.3/src/cli_test_framework/file_comparator/xml_comparator.py +150 -0
  19. cli_test_framework-0.2.3/src/cli_test_framework/runners/__init__.py +13 -0
  20. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/runners/yaml_runner.py +92 -92
  21. cli_test_framework-0.2.3/src/cli_test_framework/utils/__init__.py +11 -0
  22. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/utils/report_generator.py +67 -67
  23. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3/src/cli_test_framework.egg-info}/PKG-INFO +1 -1
  24. cli_test_framework-0.2.3/src/cli_test_framework.egg-info/SOURCES.txt +52 -0
  25. cli_test_framework-0.2.3/src/cli_test_framework.egg-info/top_level.txt +1 -0
  26. cli_test_framework-0.2.1/src/cli_test_framework.egg-info/SOURCES.txt +0 -38
  27. cli_test_framework-0.2.1/src/cli_test_framework.egg-info/top_level.txt +0 -3
  28. cli_test_framework-0.2.1/src/core/__init__.py +0 -4
  29. cli_test_framework-0.2.1/src/runners/__init__.py +0 -3
  30. cli_test_framework-0.2.1/src/utils/__init__.py +0 -3
  31. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/CHANGELOG.md +0 -0
  32. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/MANIFEST.in +0 -0
  33. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/README.md +0 -0
  34. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/docs/user_manual.md +0 -0
  35. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/pyproject.toml +0 -0
  36. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/setup.cfg +0 -0
  37. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/core/base_runner.py +0 -0
  38. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/core/parallel_runner.py +0 -0
  39. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/core/process_worker.py +0 -0
  40. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/core/test_case.py +0 -0
  41. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/runners/json_runner.py +0 -0
  42. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/runners/parallel_json_runner.py +0 -0
  43. {cli_test_framework-0.2.1/src → cli_test_framework-0.2.3/src/cli_test_framework}/utils/path_resolver.py +0 -0
  44. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/src/cli_test_framework.egg-info/dependency_links.txt +0 -0
  45. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/src/cli_test_framework.egg-info/entry_points.txt +0 -0
  46. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/src/cli_test_framework.egg-info/requires.txt +0 -0
  47. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/__init__.py +0 -0
  48. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/__pycache__/__init__.cpython-312.pyc +0 -0
  49. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/__pycache__/test_parallel_runner.cpython-312-pytest-7.4.4.pyc +0 -0
  50. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/fixtures/test_cases.json +0 -0
  51. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/fixtures/test_cases.yaml +0 -0
  52. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/fixtures/test_cases1.json +0 -0
  53. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/performance_test.py +0 -0
  54. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test1.py +0 -0
  55. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test_comprehensive_space.py +0 -0
  56. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test_parallel_runner.py +0 -0
  57. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test_parallel_space.py +0 -0
  58. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test_report.txt +0 -0
  59. {cli_test_framework-0.2.1 → cli_test_framework-0.2.3}/tests/test_runners.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli-test-framework
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A small command line testing framework in Python with file comparison capabilities.
5
5
  Home-page: https://github.com/yourusername/cli-test-framework
6
6
  Author: Xiaotong Wang
@@ -1,48 +1,48 @@
1
- from setuptools import setup, find_packages
2
- import os
3
-
4
- # Read the contents of the README file
5
- this_directory = os.path.abspath(os.path.dirname(__file__))
6
- with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
7
- long_description = f.read()
8
-
9
- setup(
10
- name="cli-test-framework",
11
- version="0.2.1",
12
- author="Xiaotong Wang",
13
- author_email="xiaotongwang98@gmail.com",
14
- description="A small command line testing framework in Python with file comparison capabilities.",
15
- long_description=long_description,
16
- long_description_content_type="text/markdown",
17
- url="https://github.com/yourusername/cli-test-framework",
18
- packages=find_packages(where="src"),
19
- package_dir={"": "src"},
20
- install_requires=[
21
- "dukpy==0.5.0",
22
- "h5py>=3.8.0",
23
- "numpy>=2.0.1",
24
- "setuptools>=75.8.0",
25
- "wheel>=0.45.1"
26
- ],
27
- entry_points={
28
- 'console_scripts': [
29
- 'cli-test=cli_test_framework.cli:main',
30
- 'compare-files=cli_test_framework.commands.compare:main',
31
- ],
32
- },
33
- classifiers=[
34
- "Programming Language :: Python :: 3",
35
- "License :: OSI Approved :: MIT License",
36
- "Operating System :: OS Independent",
37
- "Development Status :: 4 - Beta",
38
- "Intended Audience :: Developers",
39
- "Topic :: Software Development :: Testing",
40
- "Topic :: Software Development :: Libraries :: Python Modules",
41
- ],
42
- python_requires='>=3.6',
43
- project_urls={
44
- 'Documentation': 'https://github.com/yourusername/cli-test-framework/docs/user_manual.md',
45
- 'Source': 'https://github.com/yourusername/cli-test-framework',
46
- 'Tracker': 'https://github.com/yourusername/cli-test-framework/issues',
47
- },
1
+ from setuptools import setup, find_packages
2
+ import os
3
+
4
+ # Read the contents of the README file
5
+ this_directory = os.path.abspath(os.path.dirname(__file__))
6
+ with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
7
+ long_description = f.read()
8
+
9
+ setup(
10
+ name="cli-test-framework",
11
+ version="0.2.3",
12
+ author="Xiaotong Wang",
13
+ author_email="xiaotongwang98@gmail.com",
14
+ description="A small command line testing framework in Python with file comparison capabilities.",
15
+ long_description=long_description,
16
+ long_description_content_type="text/markdown",
17
+ url="https://github.com/yourusername/cli-test-framework",
18
+ packages=find_packages(where="src"),
19
+ package_dir={"": "src"},
20
+ install_requires=[
21
+ "dukpy==0.5.0",
22
+ "h5py>=3.8.0",
23
+ "numpy>=2.0.1",
24
+ "setuptools>=75.8.0",
25
+ "wheel>=0.45.1"
26
+ ],
27
+ entry_points={
28
+ 'console_scripts': [
29
+ 'cli-test=cli_test_framework.cli:main',
30
+ 'compare-files=cli_test_framework.commands.compare:main',
31
+ ],
32
+ },
33
+ classifiers=[
34
+ "Programming Language :: Python :: 3",
35
+ "License :: OSI Approved :: MIT License",
36
+ "Operating System :: OS Independent",
37
+ "Development Status :: 4 - Beta",
38
+ "Intended Audience :: Developers",
39
+ "Topic :: Software Development :: Testing",
40
+ "Topic :: Software Development :: Libraries :: Python Modules",
41
+ ],
42
+ python_requires='>=3.6',
43
+ project_urls={
44
+ 'Documentation': 'https://github.com/yourusername/cli-test-framework/docs/user_manual.md',
45
+ 'Source': 'https://github.com/yourusername/cli-test-framework',
46
+ 'Tracker': 'https://github.com/yourusername/cli-test-framework/issues',
47
+ },
48
48
  )
@@ -0,0 +1,21 @@
1
+ """
2
+ CLI Test Framework - A powerful command-line testing framework
3
+
4
+ This package provides tools for testing command-line applications and scripts
5
+ with support for parallel execution and advanced file comparison capabilities.
6
+ """
7
+
8
+ __version__ = "0.2.3"
9
+ __author__ = "Xiaotong Wang"
10
+ __email__ = "xiaotongwang98@gmail.com"
11
+
12
+ # Import main classes for convenient access
13
+ from .runners.json_runner import JSONRunner
14
+ from .runners.parallel_json_runner import ParallelJSONRunner
15
+ from .runners.yaml_runner import YAMLRunner
16
+
17
+ __all__ = [
18
+ 'JSONRunner',
19
+ 'ParallelJSONRunner',
20
+ 'YAMLRunner',
21
+ ]
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ CLI Test Framework - Command Line Interface
6
+
7
+ This module provides the main command-line interface for the CLI Testing Framework.
8
+ """
9
+
10
+ import argparse
11
+ import sys
12
+ import os
13
+ from pathlib import Path
14
+
15
+ from .runners import JSONRunner, ParallelJSONRunner, YAMLRunner
16
+
17
+
18
+ def create_parser():
19
+ """Create and configure the argument parser"""
20
+ parser = argparse.ArgumentParser(
21
+ description="CLI Testing Framework - A powerful tool for testing command-line applications",
22
+ formatter_class=argparse.RawDescriptionHelpFormatter,
23
+ epilog="""
24
+ Examples:
25
+ cli-test run test_cases.json
26
+ cli-test run test_cases.json --parallel --workers 4
27
+ cli-test run test_cases.yaml --workspace /path/to/project
28
+ """
29
+ )
30
+
31
+ subparsers = parser.add_subparsers(dest='command', help='Available commands')
32
+
33
+ # Run command
34
+ run_parser = subparsers.add_parser('run', help='Run test cases from a configuration file')
35
+ run_parser.add_argument('config_file', help='Path to the test configuration file (JSON or YAML)')
36
+ run_parser.add_argument('--workspace', '-w', help='Working directory for test execution')
37
+ run_parser.add_argument('--parallel', '-p', action='store_true', help='Run tests in parallel')
38
+ run_parser.add_argument('--workers', type=int, help='Number of parallel workers (default: CPU count)')
39
+ run_parser.add_argument('--execution-mode', choices=['thread', 'process'], default='thread',
40
+ help='Parallel execution mode (default: thread)')
41
+ run_parser.add_argument('--output-format', choices=['text', 'json', 'html'], default='text',
42
+ help='Output format for test results')
43
+ run_parser.add_argument('--verbose', '-v', action='store_true', help='Enable verbose output')
44
+ run_parser.add_argument('--debug', action='store_true', help='Enable debug mode')
45
+
46
+ return parser
47
+
48
+
49
+ def run_tests(args):
50
+ """Run tests based on command line arguments"""
51
+ config_file = Path(args.config_file)
52
+
53
+ if not config_file.exists():
54
+ print(f"Error: Configuration file not found: {config_file}")
55
+ return False
56
+
57
+ # Determine file type
58
+ file_ext = config_file.suffix.lower()
59
+
60
+ try:
61
+ if args.parallel:
62
+ # Use parallel runner
63
+ runner = ParallelJSONRunner(
64
+ config_file=str(config_file),
65
+ workspace=args.workspace,
66
+ max_workers=args.workers,
67
+ execution_mode=args.execution_mode
68
+ )
69
+ else:
70
+ # Use appropriate single-threaded runner
71
+ if file_ext in ['.json']:
72
+ runner = JSONRunner(
73
+ config_file=str(config_file),
74
+ workspace=args.workspace
75
+ )
76
+ elif file_ext in ['.yaml', '.yml']:
77
+ runner = YAMLRunner(
78
+ config_file=str(config_file),
79
+ workspace=args.workspace
80
+ )
81
+ else:
82
+ print(f"Error: Unsupported configuration file format: {file_ext}")
83
+ return False
84
+
85
+ # Run tests
86
+ print(f"Running tests from: {config_file}")
87
+ if args.parallel:
88
+ print(f"Parallel mode: {args.execution_mode}, workers: {args.workers or 'auto'}")
89
+
90
+ success = runner.run_tests()
91
+
92
+ # Output results
93
+ if hasattr(runner, 'results'):
94
+ results = runner.results
95
+ print(f"\nTest Results:")
96
+ print(f"Total tests: {results.get('total_tests', 0)}")
97
+ print(f"Passed: {results.get('passed', 0)}")
98
+ print(f"Failed: {results.get('failed', 0)}")
99
+
100
+ if args.verbose and 'details' in results:
101
+ print("\nDetailed Results:")
102
+ for result in results['details']:
103
+ status_symbol = "✓" if result['status'] == 'passed' else "✗"
104
+ print(f" {status_symbol} {result['name']}: {result['status']}")
105
+ if result['status'] == 'failed' and result.get('message'):
106
+ print(f" Error: {result['message']}")
107
+
108
+ return success
109
+
110
+ except Exception as e:
111
+ print(f"Error running tests: {e}")
112
+ if args.debug:
113
+ import traceback
114
+ traceback.print_exc()
115
+ return False
116
+
117
+
118
+ def main():
119
+ """Main entry point for the CLI"""
120
+ parser = create_parser()
121
+ args = parser.parse_args()
122
+
123
+ if args.command == 'run':
124
+ success = run_tests(args)
125
+ sys.exit(0 if success else 1)
126
+ else:
127
+ parser.print_help()
128
+ sys.exit(1)
129
+
130
+
131
+ if __name__ == '__main__':
132
+ main()
@@ -0,0 +1,9 @@
1
+ """
2
+ Command-line commands for the CLI Testing Framework
3
+ """
4
+
5
+ from . import compare
6
+
7
+ __all__ = [
8
+ 'compare'
9
+ ]
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ @file compare.py
6
+ @brief Command for comparing files in cli-test-framework
7
+ @author Xiaotong Wang
8
+ @date 2024
9
+ """
10
+
11
+ import sys
12
+ import os
13
+ import argparse
14
+ import logging
15
+ from pathlib import Path
16
+ from ..file_comparator.factory import ComparatorFactory
17
+ from ..file_comparator.result import ComparisonResult
18
+
19
+ def configure_logging():
20
+ """Configure logging settings for the application"""
21
+ logger = logging.getLogger("cli_test_framework.file_comparator")
22
+ logger.setLevel(logging.INFO)
23
+
24
+ ch = logging.StreamHandler()
25
+ ch.setLevel(logging.INFO)
26
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
27
+ ch.setFormatter(formatter)
28
+ logger.addHandler(ch)
29
+
30
+ return logger
31
+
32
+ def parse_arguments():
33
+ """Parse command line arguments"""
34
+ parser = argparse.ArgumentParser(description="Compare two files.")
35
+ parser.add_argument("file1", help="Path to the first file")
36
+ parser.add_argument("file2", help="Path to the second file")
37
+ parser.add_argument("--start-line", type=int, default=1, help="Starting line number (1-based)")
38
+ parser.add_argument("--end-line", type=int, help="Ending line number (1-based)")
39
+ parser.add_argument("--start-column", type=int, default=1, help="Starting column number (1-based)")
40
+ parser.add_argument("--end-column", type=int, help="Ending column number (1-based)")
41
+ parser.add_argument("--file-type", help="Type of the files to compare", default="auto")
42
+ parser.add_argument("--encoding", default="utf-8", help="File encoding for text files")
43
+ parser.add_argument("--chunk-size", type=int, default=8192, help="Chunk size for binary comparison")
44
+ parser.add_argument("--output-format", choices=["text", "json", "html"], default="text",
45
+ help="Output format for the comparison result")
46
+ parser.add_argument("--verbose", "-v", action="store_true", help="Enable verbose output")
47
+ parser.add_argument("--debug", action="store_true", help="Enable debug mode with detailed logging")
48
+ parser.add_argument("--similarity", action="store_true",
49
+ help="When comparing binary files, compute and show similarity index")
50
+ parser.add_argument("--num-threads", type=int, default=4, help="Number of threads for parallel processing")
51
+
52
+ # JSON comparison options
53
+ json_group = parser.add_argument_group('JSON comparison options')
54
+ json_group.add_argument("--json-compare-mode", choices=["exact", "key-based"], default="exact",
55
+ help="JSON comparison mode: exact (default) or key-based")
56
+ json_group.add_argument("--json-key-field", help="Key field(s) to use for key-based JSON comparison")
57
+
58
+ # H5 comparison options
59
+ h5_group = parser.add_argument_group('HDF5 comparison options')
60
+ h5_group.add_argument("--h5-table", help="Comma-separated list of table names to compare in HDF5 files")
61
+ h5_group.add_argument("--h5-table-regex", help="Regular expression pattern to match table names in HDF5 files")
62
+ h5_group.add_argument("--h5-structure-only", action="store_true",
63
+ help="Only compare HDF5 file structure without comparing content")
64
+ h5_group.add_argument("--h5-show-content-diff", action="store_true",
65
+ help="Show detailed content differences when content differs")
66
+ h5_group.add_argument("--h5-rtol", type=float, default=1e-5,
67
+ help="Relative tolerance for numerical comparison in HDF5 files")
68
+ h5_group.add_argument("--h5-atol", type=float, default=1e-8,
69
+ help="Absolute tolerance for numerical comparison in HDF5 files")
70
+
71
+ return parser.parse_args()
72
+
73
+ def detect_file_type(file_path):
74
+ """Detect the type of file based on its extension"""
75
+ ext = file_path.suffix.lower()
76
+ if ext in ['.txt', '.py', '.md', '.json', '.xml', '.html', '.css', '.js']:
77
+ return 'text'
78
+ elif ext == '.json':
79
+ return 'json'
80
+ elif ext in ['.h5', '.hdf5']:
81
+ return 'h5'
82
+ else:
83
+ return 'binary'
84
+
85
+ def format_result(result, output_format):
86
+ """Format the comparison result according to the specified output format"""
87
+ if output_format == "json":
88
+ return result.to_json()
89
+ elif output_format == "html":
90
+ return result.to_html()
91
+ else:
92
+ return str(result)
93
+
94
+ def main():
95
+ """Main entry point for the compare-files command"""
96
+ logger = configure_logging()
97
+
98
+ try:
99
+ args = parse_arguments()
100
+
101
+ if args.debug:
102
+ logger.setLevel(logging.DEBUG)
103
+ logger.debug("Debug mode enabled")
104
+
105
+ # Adjust for 0-based indexing
106
+ start_line = max(0, args.start_line - 1)
107
+ end_line = None if args.end_line is None else max(0, args.end_line - 1)
108
+ start_column = max(0, args.start_column - 1)
109
+ end_column = None if args.end_column is None else max(0, args.end_column - 1)
110
+
111
+ # Resolve file paths
112
+ file1_path = Path(args.file1).resolve()
113
+ file2_path = Path(args.file2).resolve()
114
+
115
+ if not file1_path.exists():
116
+ raise ValueError(f"File not found: {file1_path}")
117
+ if not file2_path.exists():
118
+ raise ValueError(f"File not found: {file2_path}")
119
+
120
+ # Determine file type
121
+ file_type = args.file_type
122
+ if file_type == "auto":
123
+ file_type = detect_file_type(file1_path)
124
+ logger.info(f"Auto-detected file type: {file_type}")
125
+
126
+ # Prepare comparator kwargs
127
+ comparator_kwargs = {
128
+ "encoding": args.encoding,
129
+ "chunk_size": args.chunk_size,
130
+ "verbose": args.verbose or args.debug,
131
+ "num_threads": args.num_threads
132
+ }
133
+
134
+ # Add file type specific arguments
135
+ if file_type == "json":
136
+ comparator_kwargs["compare_mode"] = args.json_compare_mode
137
+ if args.json_key_field:
138
+ key_fields = [field.strip() for field in args.json_key_field.split(',')]
139
+ comparator_kwargs["key_field"] = key_fields[0] if len(key_fields) == 1 else key_fields
140
+
141
+ if file_type == "h5":
142
+ if args.h5_table:
143
+ tables = [table.strip() for table in args.h5_table.split(',')]
144
+ comparator_kwargs["tables"] = tables
145
+ if args.h5_table_regex:
146
+ comparator_kwargs["table_regex"] = args.h5_table_regex
147
+ comparator_kwargs["structure_only"] = args.h5_structure_only
148
+ comparator_kwargs["show_content_diff"] = args.h5_show_content_diff
149
+ comparator_kwargs["rtol"] = args.h5_rtol
150
+ comparator_kwargs["atol"] = args.h5_atol
151
+
152
+ if file_type == "binary":
153
+ comparator_kwargs["similarity"] = args.similarity
154
+
155
+ # Create comparator and perform comparison
156
+ comparator = ComparatorFactory.create_comparator(file_type, **comparator_kwargs)
157
+ result = comparator.compare_files(
158
+ file1_path,
159
+ file2_path,
160
+ start_line,
161
+ end_line,
162
+ start_column,
163
+ end_column
164
+ )
165
+
166
+ # Output result
167
+ output = format_result(result, args.output_format)
168
+ print(output)
169
+
170
+ sys.exit(0 if result.identical else 1)
171
+
172
+ except ValueError as ve:
173
+ logger.error(f"ValueError: {ve}")
174
+ sys.exit(1)
175
+ except Exception as e:
176
+ logger.exception(f"An unexpected error occurred")
177
+ sys.exit(1)
178
+
179
+ if __name__ == "__main__":
180
+ main()
@@ -0,0 +1,15 @@
1
+ """
2
+ Core components for the CLI Testing Framework
3
+ """
4
+
5
+ from .base_runner import BaseRunner
6
+ from .parallel_runner import ParallelRunner
7
+ from .test_case import TestCase
8
+ from .assertions import Assertions
9
+
10
+ __all__ = [
11
+ 'BaseRunner',
12
+ 'ParallelRunner',
13
+ 'TestCase',
14
+ 'Assertions'
15
+ ]
@@ -1,32 +1,32 @@
1
- import re
2
- from typing import Any, Pattern
3
-
4
- class Assertions:
5
- @staticmethod
6
- def equals(actual: Any, expected: Any, message: str = "") -> bool:
7
- if actual != expected:
8
- raise AssertionError(f"{message} Expected: {expected}, but got: {actual}")
9
- return True
10
-
11
- @staticmethod
12
- def contains(container: str, item: str, message: str = "") -> bool:
13
- """
14
- Check if the item is contained within the container string.
15
- This method returns True if the item is found anywhere within the container,
16
- even if the container contains other information.
17
- """
18
- if item not in container:
19
- raise AssertionError(f"{message} Expected to contain: {item}")
20
- return True
21
-
22
- @staticmethod
23
- def matches(text: str, pattern: str, message: str = "") -> bool:
24
- if not re.search(pattern, text):
25
- raise AssertionError(f"{message} Text does not match pattern: {pattern}")
26
- return True
27
-
28
- @staticmethod
29
- def return_code_equals(actual: int, expected: int, message: str = "") -> bool:
30
- if actual != expected:
31
- raise AssertionError(f"{message} Expected return code: {expected}, got: {actual}")
1
+ import re
2
+ from typing import Any, Pattern
3
+
4
+ class Assertions:
5
+ @staticmethod
6
+ def equals(actual: Any, expected: Any, message: str = "") -> bool:
7
+ if actual != expected:
8
+ raise AssertionError(f"{message} Expected: {expected}, but got: {actual}")
9
+ return True
10
+
11
+ @staticmethod
12
+ def contains(container: str, item: str, message: str = "") -> bool:
13
+ """
14
+ Check if the item is contained within the container string.
15
+ This method returns True if the item is found anywhere within the container,
16
+ even if the container contains other information.
17
+ """
18
+ if item not in container:
19
+ raise AssertionError(f"{message} Expected to contain: {item}")
20
+ return True
21
+
22
+ @staticmethod
23
+ def matches(text: str, pattern: str, message: str = "") -> bool:
24
+ if not re.search(pattern, text):
25
+ raise AssertionError(f"{message} Text does not match pattern: {pattern}")
26
+ return True
27
+
28
+ @staticmethod
29
+ def return_code_equals(actual: int, expected: int, message: str = "") -> bool:
30
+ if actual != expected:
31
+ raise AssertionError(f"{message} Expected return code: {expected}, got: {actual}")
32
32
  return True
@@ -0,0 +1,9 @@
1
+ """
2
+ File comparison module for cli-test-framework.
3
+ This module provides functionality for comparing different types of files.
4
+ """
5
+
6
+ from .factory import ComparatorFactory
7
+ from .result import ComparisonResult
8
+
9
+ __all__ = ['ComparatorFactory', 'ComparisonResult']
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ @file base_comparator.py
6
+ @brief Base abstract class for file comparison operations
7
+ @author Xiaotong Wang
8
+ @date 2025
9
+ """
10
+
11
+ from abc import ABC, abstractmethod
12
+ import logging
13
+ from pathlib import Path
14
+ from .result import ComparisonResult, Difference
15
+
16
+ class BaseComparator(ABC):
17
+ """
18
+ @brief Base abstract class for all file comparators
19
+ @details This class defines the interface and common functionality for all file comparators.
20
+ It provides basic file comparison operations and logging capabilities.
21
+ """
22
+
23
+ def __init__(self, encoding="utf-8", chunk_size=8192, verbose=False):
24
+ """
25
+ @brief Initialize the base comparator
26
+ @param encoding str: File encoding to use (default: "utf-8")
27
+ @param chunk_size int: Size of chunks for reading large files (default: 8192)
28
+ @param verbose bool: Enable verbose logging (default: False)
29
+ """
30
+ self.encoding = encoding
31
+ self.chunk_size = chunk_size
32
+ self.logger = logging.getLogger(f"file_comparator.{self.__class__.__name__}")
33
+ if verbose:
34
+ self.logger.setLevel(logging.DEBUG)
35
+
36
+ @abstractmethod
37
+ def read_content(self, file_path, start_line=0, end_line=None, start_column=0, end_column=None):
38
+ """
39
+ @brief Read file content with specified range
40
+ @param file_path Path: Path to the file to read
41
+ @param start_line int: Starting line number (0-based)
42
+ @param end_line int: Ending line number (0-based, None for end of file)
43
+ @param start_column int: Starting column number (0-based)
44
+ @param end_column int: Ending column number (0-based, None for end of line)
45
+ @return object: File content in a format suitable for comparison
46
+ """
47
+ pass
48
+
49
+ @abstractmethod
50
+ def compare_content(self, content1, content2):
51
+ """
52
+ @brief Compare two content objects and return comparison details
53
+ @param content1 object: First content object to compare
54
+ @param content2 object: Second content object to compare
55
+ @return tuple: (bool, list) - (identical, differences)
56
+ """
57
+ pass
58
+
59
+ def compare_files(self, file1, file2, start_line=0, end_line=None, start_column=0, end_column=None):
60
+ """
61
+ @brief Compare two files with the specified parameters
62
+ @param file1 Path: Path to the first file
63
+ @param file2 Path: Path to the second file
64
+ @param start_line int: Starting line number (0-based)
65
+ @param end_line int: Ending line number (0-based, None for end of file)
66
+ @param start_column int: Starting column number (0-based)
67
+ @param end_column int: Ending column number (0-based, None for end of line)
68
+ @return ComparisonResult: Result object containing comparison details
69
+ """
70
+ result = ComparisonResult(
71
+ file1=str(file1),
72
+ file2=str(file2),
73
+ start_line=start_line,
74
+ end_line=end_line,
75
+ start_column=start_column,
76
+ end_column=end_column
77
+ )
78
+
79
+ try:
80
+ self.logger.info(f"Comparing files: {file1} and {file2}")
81
+
82
+ # Record file metadata
83
+ file1_path = Path(file1)
84
+ file2_path = Path(file2)
85
+ result.file1_size = file1_path.stat().st_size
86
+ result.file2_size = file2_path.stat().st_size
87
+
88
+ # Read content with specified ranges
89
+ self.logger.debug(f"Reading content from files")
90
+ content1 = self.read_content(file1, start_line, end_line, start_column, end_column)
91
+ content2 = self.read_content(file2, start_line, end_line, start_column, end_column)
92
+
93
+ # Compare content
94
+ self.logger.debug(f"Comparing content")
95
+ identical, differences = self.compare_content(content1, content2)
96
+
97
+ # Update result
98
+ result.identical = identical
99
+ result.differences = differences
100
+
101
+ return result
102
+
103
+ except Exception as e:
104
+ self.logger.error(f"Error during comparison: {str(e)}")
105
+ result.error = str(e)
106
+ result.identical = False
107
+ return result