Skip to content

Commit

Permalink
QGIS and Python installed correctly, test fails on comparing files.
Browse files Browse the repository at this point in the history
TESTED WITH DIFFERENT VERSION OF PYTHON TEST FILE AND DIFFLIB LINE BY LINE SHOWS NO DIFFERENCES BUT FILECMP FAILS
--------------------------------------------------------------------------

Run export QGIS_PREFIX_PATH="/usr"
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-8.2.2, pluggy-1.5.0
PyQt6 6.7.0 -- Qt runtime 6.7.1 -- Qt compiled 6.7.1
rootdir: /home/runner/work/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP
plugins: qt-4.4.0
collected 5 items

test/test_qgis_color_func.py ....F                                       [100%]

=================================== FAILURES ===================================
_______________________________ test_OutputFile ________________________________

    def test_OutputFile():
        """
        Check if the output table is created correctly.
        Compare it with reference file.
        """
        # Get the GRASS color table
        GRASStable_path = getCORINEtable()
    
        # Create a temporary qml file
        tempdir = tempfile.mkdtemp()
        Tempfile = os.path.join(tempdir, "tempfile.qml")
    
        # Convert the GRASS color table to QGIS format
        convert_color_table_grass_to_qgis(GRASStable_path, Tempfile)
    
        # Normalize line endings of the generated QML file
        with open(Tempfile, 'r') as f:
            content = f.read()
        normalized_content = normalize_line_endings(content)
        write_with_lf_line_endings(normalized_content, Tempfile)
    
        # Check if the output table is created correctly
        script_dir = Path(__file__).resolve().parent
    
        # Construct the path to the target directory
        target_dir = script_dir.parent / "test" / "reference"
    
        # Specify the filename you want to access
        filename = "corine.qml"
    
        # Create the full path to the file
        CORINE_file_path = target_dir / filename
    
        with open(Tempfile, 'r') as gen_file:
            gen_content = gen_file.read()
        with open(CORINE_file_path, 'r') as ref_file:
            ref_content = ref_file.read()
    
        # Compare content line by line
        gen_lines = gen_content.splitlines(keepends=True)
        ref_lines = ref_content.splitlines(keepends=True)
        diff = difflib.unified_diff(gen_lines, ref_lines, fromfile='generated', tofile='reference')
        diff_str = ''.join(diff)
        if diff_str:
            print("Differences found:\n", diff_str)
        else:
            print("No differences found.")
    
>       assert filecmp.cmp(Tempfile, CORINE_file_path, shallow=False)
E       AssertionError: assert False
E        +  where False = <function cmp at 0x7f578b87dea0>('/tmp/tmp53igm9nx/tempfile.qml', PosixPath('/home/runner/work/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP/test/reference/corine.qml'), shallow=False)
E        +    where <function cmp at 0x7f578b87dea0> = filecmp.cmp

test/test_qgis_color_func.py:199: AssertionError
----------------------------- Captured stdout call -----------------------------
No differences found.
=========================== short test summary info ============================
FAILED test/test_qgis_color_func.py::test_OutputFile - AssertionError: assert False
 +  where False = <function cmp at 0x7f578b87dea0>('/tmp/tmp53igm9nx/tempfile.qml', PosixPath('/home/runner/work/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP/GRASS-GIS-Q-GIS-color-table-conversion-BACKUP/test/reference/corine.qml'), shallow=False)
 +    where <function cmp at 0x7f578b87dea0> = filecmp.cmp
========================= 1 failed, 4 passed in 0.46s ==========================
Error: Process completed with exit code 1.
  • Loading branch information
jehlijos authored Jun 20, 2024
1 parent 16ef238 commit d6ce38b
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions .github/workflows/test_qgis_color_func.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ jobs:
test:
runs-on: ubuntu-latest

env:
QGIS_VERSION: '3.34'
QGIS_PREFIX_PATH: '/usr'
PYTHONPATH: '${PYTHONPATH}:${QGIS_PREFIX_PATH}/share/qgis/python'

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -19,21 +14,23 @@ jobs:
run: |
sudo add-apt-repository -y ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install -y qgis python3-qgis qgis-plugin-grass
python3 -m pip install --upgrade pip
pip install pytest pytest-qt PyQt5
sudo apt-get install -y qgis python3.10 python3.10-dev python3-pip
sudo apt-get install -y qgis-plugin-grass
python3.10 -m pip install --upgrade pip
python3.10 -m pip install pytest pytest-qt PyQt6
sudo apt-get install -y gdb
- name: Set up QGIS environment variables
run: |
export PYTHONPATH="${PYTHONPATH}:${QGIS_PREFIX_PATH}/share/qgis/python"
echo "QGIS_PREFIX_PATH=/usr" >> $GITHUB_ENV
echo "PYTHONPATH=/usr/share/qgis/python:$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
echo "QGIS_DEBUG=0" >> $GITHUB_ENV
echo "QGIS_LOG_FILE=/dev/null" >> $GITHUB_ENV
- name: Run tests
run: |
export QGIS_PREFIX_PATH="/usr"
export LD_LIBRARY_PATH="${QGIS_PREFIX_PATH}/lib"
export PYTHONPATH="/usr/share/qgis/python:$GITHUB_WORKSPACE"
export LD_LIBRARY_PATH="/usr/lib"
export QGIS_DEBUG=0
export QGIS_LOG_FILE=/dev/null
- name: Initialize QGIS
run: python3 -c "from qgis.core import QgsApplication; QgsApplication.setPrefixPath('${QGIS_PREFIX_PATH}', True); QgsApplication.initQgis()"

- name: Run tests
run: pytest test/test_qgis_color_func.py
pytest test/test_qgis_color_func.py

0 comments on commit d6ce38b

Please sign in to comment.