Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Automated testing and System test #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
Expand All @@ -28,5 +29,29 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1729100864382</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
116 changes: 116 additions & 0 deletions Automation_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import subprocess
import os
import pytest

# Define base directory and paths to your test files
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
EXCEL_DIFF_JAR_PATH = os.path.join(BASE_DIR, "excel-diff-checker-1/apps/excel-diff-checker.jar")
BASE_FILE_PATH = os.path.join(BASE_DIR, "Input/file.xlsx")
DIFF_FILE_PATH = os.path.join(BASE_DIR, "Input/file_diff.xlsx")
EMPTY_FILE_PATH = os.path.join(BASE_DIR, "Input/file_empty.xlsx")
IDENTICAL_FILE_PATH = os.path.join(BASE_DIR, "Input/file_identical.xlsx")
LARGE_FILE_PATH = os.path.join(BASE_DIR, "Input/large_file.xlsx")

# Helper function to construct the output file path
def get_output_file_path(base_file, target_file):
base_name = os.path.splitext(os.path.basename(base_file))[0]
target_name = os.path.splitext(os.path.basename(target_file))[0]
output_file_name = f"{base_name} vs {target_name}.xlsx"
return os.path.join(BASE_DIR, output_file_name)

# Helper function to run the excel-diff-checker command
def run_diff_checker(base_file, target_file, options=None):
command = f"java -jar {EXCEL_DIFF_JAR_PATH} -b {base_file} -t {target_file}"
if options:
command += " " + options
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout, result.stderr

@pytest.fixture # Reference https://docs.pytest.org/en/stable/explanation/fixtures.html
def clean_up():
yield
# Clean up generated output files after tests
for base_file in [BASE_FILE_PATH, DIFF_FILE_PATH, EMPTY_FILE_PATH, IDENTICAL_FILE_PATH, LARGE_FILE_PATH]:
for target_file in [DIFF_FILE_PATH, EMPTY_FILE_PATH, IDENTICAL_FILE_PATH, LARGE_FILE_PATH]:
output_file_path = get_output_file_path(base_file, target_file)
if os.path.exists(output_file_path):
os.remove(output_file_path)

# Test case F-1: Basic Functionality Test
def test_basic_functionality(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH)
OUTPUT_FILE_PATH = get_output_file_path(BASE_FILE_PATH, DIFF_FILE_PATH)
assert os.path.exists(OUTPUT_FILE_PATH), "Output file was not generated."
assert "Diff" in stdout, "No differences found in the output."
assert "Diff at Row[3]" in stdout, "Expected specific difference in age not found."

# Test case F-2: Identical File Diff Check
def test_identical_files(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, IDENTICAL_FILE_PATH)
OUTPUT_FILE_PATH = get_output_file_path(BASE_FILE_PATH, IDENTICAL_FILE_PATH)
assert not os.path.exists(OUTPUT_FILE_PATH), "No output file should be generated for identical files."
assert "No diff found!" in stdout, "Unexpected output for identical files."

# Test case F-3: Diffs in Comments/Notes
def test_diffs_in_comments(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH)
assert "Diff at Row[3] of Sheet[Sheet1]" in stdout, "Differences not correctly reported in comments."

# Test case F-4: Cell Difference Detection
def test_cell_difference_detection(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH)
assert "Diff at Row[3]" in stdout, "Cell differences were not detected properly."

# Test case F-5: Empty File Comparison
def test_empty_file_comparison(clean_up):
stdout, stderr = run_diff_checker(EMPTY_FILE_PATH, EMPTY_FILE_PATH)
OUTPUT_FILE_PATH = get_output_file_path(EMPTY_FILE_PATH, EMPTY_FILE_PATH)
assert not os.path.exists(OUTPUT_FILE_PATH), "No output file should be generated for empty files."
assert "No diff found!" in stdout, "Unexpected output for empty file comparison."

# Test case F-6: Specific Sheet Comparison (Option -s)
def test_specific_sheet_comparison(clean_up):
options = "-s Sheet1"
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH, options)
OUTPUT_FILE_PATH = get_output_file_path(BASE_FILE_PATH, DIFF_FILE_PATH)
assert os.path.exists(OUTPUT_FILE_PATH), "Output file was not generated for specific sheet comparison."
assert "Diff" in stdout, "No differences found in the output for specific sheet comparison."
assert "Diff at Row[3]" in stdout, "Expected specific difference in age not found."

# Test case F-7: Mixed Data Types
def test_mixed_data_types(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH)
OUTPUT_FILE_PATH = get_output_file_path(BASE_FILE_PATH, DIFF_FILE_PATH)
assert os.path.exists(OUTPUT_FILE_PATH), "Output file was not generated for mixed data type comparison."
assert "Diff" in stdout, "No differences found in the output for mixed data types."
assert "Diff at Row[3]" in stdout, "Expected name not found in the differences."

# Test case F-8: Redundant Row Removal
def test_redundant_row_removal(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH)
assert "Diff at Row" in stdout, "Redundant row differences not handled properly."

# Test case F-9: Large File Comparison
def test_large_file_comparison(clean_up):
stdout, stderr = run_diff_checker(BASE_FILE_PATH, LARGE_FILE_PATH)
OUTPUT_FILE_PATH = get_output_file_path(BASE_FILE_PATH, LARGE_FILE_PATH)
assert os.path.exists(OUTPUT_FILE_PATH), "Output file was not generated for large file comparison."
assert "Diff" in stdout, "No differences found in the output for large file comparison."

# Test case F-10: Use of 'r' Option
def test_use_of_r_option(clean_up):
options = "-r"
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH, options)
assert "Diff at Cell" in stdout, "Differences not reported correctly when using 'r' option."
assert not os.path.exists(get_output_file_path(BASE_FILE_PATH, DIFF_FILE_PATH)), "No output file should be generated with 'r' option."

# Test case F-11: Non-Existent Sheet Name
def test_non_existent_sheet_name(clean_up):
options = "-s NonExistentSheet"
stdout, stderr = run_diff_checker(BASE_FILE_PATH, DIFF_FILE_PATH, options)
assert "doesn't exist in both workbooks" in stdout, "Non-existent sheet name was not handled properly."

# Test case F-12: Invalid File Path
def test_file_not_found(clean_up):
stdout, stderr = run_diff_checker("invalid_path.xlsx", DIFF_FILE_PATH)
assert "The system cannot find the file specified" in stdout or "The system cannot find the file specified" in stderr, "No error message for missing file."
14 changes: 14 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Excel Diff Checker Tester:
Testing suite for the Excel Diff Checker tool.

Requirements:
Python 3.x
pytest
Java Runtime Environment (JRE)

Running tests:
To use the testing suite, make sure that the tool is included in the same folder as this script in a folder named "excel-diff-checker-1". As an example, a version of the tool is included in this repository.
After acquiring this repository and installing requirements, run pytest Automation_script.py.

Use of AI:
GPT-4o and GPT-4o mini were used for debugging and adding functional comments.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.abhi.poi.excel;


import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.FileInputStream;
import java.util.concurrent.Callable;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class ExcelDiffCheckerIntegrationTest {

private XSSFWorkbook workbookOne;
private XSSFWorkbook workbookTwo;

// Test setup with existing file paths
@BeforeEach
void setUp() throws Exception {
workbookOne = new XSSFWorkbook(new FileInputStream("C:\\Users\\anujr\\Downloads\\excel1.xlsx"));
workbookTwo = new XSSFWorkbook(new FileInputStream("C:\\Users\\anujr\\Downloads\\excel2.xlsx"));
}

// Test calling two Excel files
@Test
void testSheetProcessorTask() throws Exception {
XSSFSheet sheetOne = workbookOne.getSheetAt(0);
XSSFSheet sheetTwo = workbookTwo.getSheetAt(0);

// Create a task for processing the sheets
Callable<CallableValue> sheetTask = new SheetProcessorTask(sheetOne, sheetTwo, false);

// Execute the task
CallableValue taskResult = sheetTask.call();

// Assert that the result is not null
assertNotNull(taskResult);

System.out.println("Test passed successfully!");


// Additional assertions can be made on taskResult to check for expected behavior
// For example:
// assertTrue(taskResult.getDiffFlag(), "Differences should be detected");
}
}