Add a script to check invalid screenshot(s).
This commit is contained in:
committed by
Benoit Marty
parent
ca7dcee7b2
commit
1b3bf575b1
12
.github/workflows/quality.yml
vendored
12
.github/workflows/quality.yml
vendored
@@ -21,6 +21,18 @@ jobs:
|
||||
- name: Run code quality check suite
|
||||
run: ./tools/check/check_code_quality.sh
|
||||
|
||||
checkScreesnhot:
|
||||
name: Search for invalid screenshot files
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
- name: Search for invalid screenshot files
|
||||
run: ./tools/test/checkInvalidScreenshots.py
|
||||
|
||||
check:
|
||||
name: Project Check Suite
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
46
tools/test/checkInvalidScreenshots.py
Executable file
46
tools/test/checkInvalidScreenshots.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (c) 2024 New Vector Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
from util import compare
|
||||
|
||||
|
||||
def checkInvalidScreenshots(reference):
|
||||
__doc__ = "Detect invalid screenshot, by comparing to an invalid reference."
|
||||
path_of_screenshots = "tests/uitests/src/test/snapshots/images/"
|
||||
files = os.listdir(path_of_screenshots)
|
||||
counter = 0
|
||||
for file in files:
|
||||
if not compare(reference, path_of_screenshots + file):
|
||||
print("Invalid screenshot detected: " + file)
|
||||
counter += 1
|
||||
return counter
|
||||
|
||||
|
||||
def main():
|
||||
invalid_screenshot_reference_path = "tools/test/invalid_screenshot.png"
|
||||
result = checkInvalidScreenshots(invalid_screenshot_reference_path)
|
||||
if result > 0:
|
||||
print("%d invalid screenshot(s) detected" % result)
|
||||
print("Please check that the Preview is OK in Android Studio. You may want to use a Fake Composable for the screenshot to render correctly.")
|
||||
exit(1)
|
||||
else:
|
||||
print("No invalid screenshot detected!")
|
||||
exit(0)
|
||||
|
||||
|
||||
main()
|
||||
@@ -3,6 +3,7 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from util import compare
|
||||
|
||||
# Read all arguments and return a list of them, this are the languages list.
|
||||
def readArguments():
|
||||
@@ -40,20 +41,6 @@ def detectLanguages():
|
||||
return languages
|
||||
|
||||
|
||||
def compare(file1, file2):
|
||||
__doc__ = "Compare two files, return True if different, False if identical."
|
||||
# Compare file size
|
||||
file1_stats = os.stat(file1)
|
||||
file2_stats = os.stat(file2)
|
||||
if file1_stats.st_size != file2_stats.st_size:
|
||||
return True
|
||||
# Compare file content
|
||||
with open(file1, "rb") as f1, open(file2, "rb") as f2:
|
||||
content1 = f1.read()
|
||||
content2 = f2.read()
|
||||
return content1 != content2
|
||||
|
||||
|
||||
def deleteDuplicatedScreenshots(lang):
|
||||
__doc__ = "Delete screenshots identical to the English version for a language"
|
||||
print("Deleting screenshots identical to the English version for language %s..." % lang)
|
||||
|
||||
BIN
tools/test/invalid_screenshot.png
Normal file
BIN
tools/test/invalid_screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
31
tools/test/util.py
Normal file
31
tools/test/util.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (c) 2024 New Vector Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def compare(file1, file2):
|
||||
__doc__ = "Compare two files, return True if different, False if identical."
|
||||
# Compare file size
|
||||
file1_stats = os.stat(file1)
|
||||
file2_stats = os.stat(file2)
|
||||
if file1_stats.st_size != file2_stats.st_size:
|
||||
return True
|
||||
# Compare file content
|
||||
with open(file1, "rb") as f1, open(file2, "rb") as f2:
|
||||
content1 = f1.read()
|
||||
content2 = f2.read()
|
||||
return content1 != content2
|
||||
Reference in New Issue
Block a user