Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

tests: add sample-based tests for AnnotateColorSaturation.get_color()

Changeset 898b93f24b70

Parent 906be3f1a494

by Yuya Nishihara

Changes to one file · Browse files at 898b93f24b70 Showing diff from parent 906be3f1a494 Diff from another changeset...

Change 1 of 1 Show Entire File tests/​colormap_test.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@@ -0,0 +1,48 @@
+"""Test for tortoisehg.util.colormap""" +import sys +from nose.tools import * +from tortoisehg.util import colormap + +def fakectx(userhash, date, tz=0): + # AnnotateColorSaturation uses hash() for mapping user to hue + class user(object): + def __hash__(self): + return userhash + class ctx(object): + def user(self): + return user() + def date(self): + return (float(date), tz) + def __repr__(self): + return '<fakectx:userhash=%x,date=%d,%d>' % (userhash, date, tz) + return ctx() + +def test_user_hue(): + """Is a user mapped to his own color (hue)?""" + cm = colormap.AnnotateColorSaturation() + + samples = {0x0: '#ffaaaa', 0x1: '#ffaac9', 0x2: '#ffaae9', 0x3: '#f4aaff', + 0x4: '#d4aaff', 0x5: '#b4aaff', 0x6: '#aabfff', 0x7: '#aadfff', + 0x8: '#aaffff', 0x9: '#aaffdf', 0xa: '#aaffbf', 0xb: '#b4ffaa', + 0xc: '#d4ffaa', 0xd: '#f4ffaa', 0xe: '#ffe9aa', 0xf: '#ffc9aa'} + for i, c in sorted(samples.iteritems(), key=lambda a: a[0]): + assert_equals(c, cm.get_color(fakectx(sys.maxint / 16 * i, 0), 0)) + +SECS_PER_DAY = 24 * 60 * 60 + +def test_age_saturation(): + """Is an age mapped to its saturation?""" + cm = colormap.AnnotateColorSaturation() + + samples = {0: '#ffaaaa', 50: '#ffd4d4', 100: '#ffe2e2', 150: '#ffe9e9', + 200: '#ffeeee', 250: '#fff0f0', 300: '#fff2f2', 350: '#fff4f4', + 400: '#fff5f5', 450: '#fff6f6', 500: '#fff7f7', 550: '#fff7f7'} + for i, c in sorted(samples.iteritems(), key=lambda a: a[0]): + assert_equals(c, cm.get_color(fakectx(0, 0), float(i * SECS_PER_DAY))) + +def test_age_calc(): + """Color shouldn't depend on the date but the age""" + cm = colormap.AnnotateColorSaturation() + age = 50 * SECS_PER_DAY + for d in (0, SECS_PER_DAY, 365 * SECS_PER_DAY): + assert_equals('#ffd4d4', cm.get_color(fakectx(0, d), d + age))