Skip to content
This repository has been archived by the owner on Jan 11, 2018. It is now read-only.

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
There's an issue with not getting the right domain when I run
tests locally vs. on circleci.  This addresses this and also updates
the test

Also removed some unused code to get some more test cov
  • Loading branch information
d3ming committed Apr 20, 2016
1 parent 6ee9e59 commit 3d716d7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
7 changes: 5 additions & 2 deletions tagcompare/capture.py
Expand Up @@ -184,9 +184,12 @@ def __write_html(self, tag_html, output_path):
class CaptureManager(object):
MAX_REMOTE_JOBS = 6

def __init__(self):
def __init__(self, domain=None):
self.domain = domain
if not self.domain:
self.domain = settings.DEFAULT.domain
self.logger = logger.Logger(name="capture", writefile=True).get()
self.placelocal_api = placelocal.PlaceLocalApi()
self.placelocal_api = placelocal.PlaceLocalApi(domain=self.domain)

def _capture_tags_for_configs(self, cids, pathbuilder,
configs,
Expand Down
16 changes: 7 additions & 9 deletions tagcompare/image.py
Expand Up @@ -30,7 +30,8 @@ def generate_diff_img(file1, file2, diff_img_path):
diff_img_path.
"""
import subprocess
subprocess.call(["compare", "-compose", "src", file1, file2, diff_img_path])
subprocess.call(
["compare", "-compose", "src", file1, file2, diff_img_path])
LOGGER.debug("diff image saved in build directory")
return

Expand Down Expand Up @@ -101,12 +102,7 @@ def crop(img_file, cropbox, backup=False):

def normalize_img(img_file, greyscale=False):
img = Image.open(img_file)
if not greyscale:
return img

# TODO: Figure out ways to make font issues more prominent
# greyscale
return img.convert('LA')
return img


def blank_compare_matrix(num_configs, width, height):
Expand All @@ -129,7 +125,8 @@ def _get_color_distance(px1, px2):
return math.sqrt(sum([abs(a - b) ** 2 for (a, b) in zip(px1, px2)]))


# In R8G8B8A8 space, this is white vs. black, so all distances must be at most this.
# In R8G8B8A8 space, this is white vs. black, so all distances must be at
# most this.
_DIST_MAX = 2 * 256


Expand Down Expand Up @@ -174,4 +171,5 @@ def draw_visual_diff(canvas, img1, img2, position, cfgstring, overlay_mask):
canvas.paste(normalized_distances, position, overlay_mask)
# and finally label what the comparison is for.
draw = ImageDraw.Draw(canvas)
draw.text(xy=(position[0] + 3, position[1] + 3), fill=(0, 0, 255), text=cfgstring)
draw.text(xy=(position[0] + 3, position[1] + 3),
fill=(0, 0, 255), text=cfgstring)
4 changes: 0 additions & 4 deletions tagcompare/logger.py
Expand Up @@ -5,10 +5,6 @@
import time


def set_level_from_settings():
logging.getLogger("tagcompare").setLevel(settings.DEFAULT.loglevel)


def generate_timestamp():
return time.strftime("%Y%m%d-%H%M%S")

Expand Down
8 changes: 4 additions & 4 deletions tagcompare/test/test_capture.py
Expand Up @@ -35,18 +35,18 @@ def test_capture_configs():
adtypes = ["iframe"]

pb = output.create(build="capture_test")
cm = capture.CaptureManager()
cm = capture.CaptureManager(domain="www.placelocal.com")
errors = cm._capture_tags_for_configs(cids=cids, pathbuilder=pb,
configs=configs,
tagsizes=adsizes, tagtypes=adtypes,
capture_existing=True)
'''There should be a SEVERE error like:
'''There should be two SEVERE error like:
'http://fonts.googleapis.com/css?family=[object+Object]... Failed to load
'''
assert errors
assert len(errors) == 1, "There should be one error!"
assert len(errors) == 2, "There should be two errors!"
assert errors[0]['level'] == 'SEVERE'
pb.rmbuild()
assert "http://fonts.googleapis.com" in str(errors[0]['message'])


def test_capture_tag():
Expand Down

0 comments on commit 3d716d7

Please sign in to comment.