Commit 7e9039f6 authored by njean42's avatar njean42
Browse files

Testing tool for code changes and between versions.

parent b908d390
......@@ -61,10 +61,12 @@ If you successfully use *Kumiko* on any other platform, please let us know!
# Usage
# Usage & Testing
See the [usage doc](doc/ for details on how to use the *Kumiko* tools.
Also check the [testing doc](doc/ if you want to test modified version of the code.
# Numbering
# Testing Kumiko
Small changes in code often lead to many and unexpected panels to be detected differently.
To have an overview of the consequences of code changes, a testing tool is provided.
Basically switch to `kumiko` top-level directory and run:
This will run *Kumiko*, your modified version, on all the comic page templates provided under `./tests/images/`.
But it will also run *Kumiko*'s previous version on the same files and calculate the differences!
# Results
An HTML file is generated under `./tests/results/` that you can open locally (add `--browser firefox` to open it automatically).
It will show you all the differences between the previous git version and yours!
Take a look at the [differences between *Kumiko* v1.0 and v1.1](
#!/usr/bin/env python
import os, subprocess, json, argparse
from kumikolib import Kumiko,Panel
class Tester:
files = []
git_repo = ''
git_versions = [
def __init__(self, options):
self.savedir = os.path.join('tests','results')
if not os.path.isdir(self.savedir):
raise Exception("'%s' is not a directory" % self.savedir)
self.options = {
'browser': options['browser'] if 'browser' in options and options['browser'] else False
def run_all(self):
for git_version in self.git_versions:
def run(self, git_version):
print('\n########## Finding speech bubbles with kumiko version',git_version,'##########')
kumiko_bin = './kumiko'
if git_version != 'current':
tempgit = '/tmp/kumikogit'['rm','-rf',tempgit])['git', 'clone', self.git_repo, tempgit], capture_output=True)['git', 'checkout', git_version], cwd=tempgit, capture_output=True)
kumiko_bin = os.path.join(tempgit,'kumiko')['mkdir','-p',self.savedir])
if len(self.files) == 0:
for d in os.scandir('tests/images'):
if d.is_dir():
self.files.sort(key=lambda d:
for f in self.files:
print("##### Kumiko-cutting",,"#####")
f_savedir = os.path.join(self.savedir,git_version,os.path.basename(f))['mkdir','-p',f_savedir])
jsonfile = os.path.join(self.savedir,git_version,os.path.basename(f)+'.json')[kumiko_bin, '-i', f, '-o', jsonfile, '--debug-dir', f_savedir, '--progress'])
def compare_all(self):
self.max_diffs = 20
for i in range(len(self.git_versions)-1):
v1 = self.git_versions[i]
v2 = self.git_versions[i+1]
print('\n########## Comparing kumiko results between versions',v1,'and',v2,'##########')
files_diff = {}
for f in self.files:
if len(files_diff) > 20:
print('The maximum number of differences in files (20) has been reached, stopping')
with open(os.path.join(self.savedir,v1,os.path.basename(f)+'.json')) as fh:
json1 = json.load(fh)
with open(os.path.join(self.savedir,v2,os.path.basename(f)+'.json')) as fh:
json2 = json.load(fh)
for p in range(len(json1)): # for each page
# check both images' filename and size, should be the same
if json1[p]['filename'] != json2[p]['filename']:
print('error, filenames are not the same',json1[p]['filename'],json2[p]['filename'])
if json1[p]['size'] != json2[p]['size']:
print('error, filenames are not the same',json1[p]['size'],json2[p]['size'])
is_diff = False
if len(json1[p]['panels']) != len(json2[p]['panels']):
is_diff = True
gutterThreshold = Kumiko.getGutterThreshold(json1[p]['size'])
for pan in range(len(json1[p]['panels'])):
p1 = Panel(json1[p]['panels'][pan], gutterThreshold)
p2 = Panel(json2[p]['panels'][pan], gutterThreshold)
if p1 != p2:
is_diff = True
if is_diff:
files_diff[json1[p]['filename']] = [[json1[p]],[json2[p]]]
html_diff_file = os.path.join(self.savedir,'diff-'+v1+'-'+v2+'.html')
diff_file = open(html_diff_file, 'w')
for img in files_diff:
if self.options['browser']:[self.options['browser'],html_diff_file])
class HTML:
header = """<!DOCTYPE html>
<meta charset="utf-8">
<script type="text/javascript" src="../../jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../reader.js"></script>
<link rel="stylesheet" media="all" href="../../style.css" />
<style type="text/css">
h2 { text-align: center; }
.sidebyside { display: flex; justify-content: space-around; }
.sidebyside > div { width: 45%; }
.version { text-align: center; }
.kumiko-reader { height: 90vh; }
<h1>Comparing Kumiko results</h1>
def nbdiffs(files_diff):
return "<p>{0} differences found in files</p>".format(len(files_diff))
panelId = 0
def side_by_side_panels(img,jsons,v1,v2):
oneside = """
<div id="page{0}" class="kumiko-reader"></div>
<script type="text/javascript">
var reader = new Reader({{
container: $('#page{1}'),
comicsJson: {2},
imageURLs: ['{3}']
html = '<h2>{0}</h2><div class="sidebyside"><div class="version">{1}</div><div class="version">{2}</div></div><div class="sidebyside">'.format(img,v1,v2)
for js in jsons:
html += oneside.format(HTML.panelId,HTML.panelId,json.dumps(js),'../../'+img)
HTML.panelId += 1
html += '</div>'
return html
footer = """
parser = argparse.ArgumentParser(description='Kumiko Tester')
parser.add_argument('--browser', nargs=1, help='Opens given browser to view the differences when ready', choices=['firefox','konqueror','chromium'])
parser.add_argument('action', nargs='?', help="Just 'run' (compute information about files), 'compare' two versions of the code, or both", choices=['run','compare','run_compare'], default='run_compare')
args = parser.parse_args()
tester = Tester({
'browser': args.browser[0] if args.browser != None else False,
if args.action in ['run','run_compare']:
if args.action in ['compare','run_compare']:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment