File: test-unit.py

package info (click to toggle)
gimp 3.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 210,076 kB
  • sloc: ansic: 842,287; lisp: 10,761; python: 10,318; cpp: 7,238; perl: 4,355; sh: 1,043; xml: 963; yacc: 609; lex: 348; javascript: 150; makefile: 43
file content (85 lines) | stat: -rw-r--r-- 2,556 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3

N_DEFAULT_USER_UNITS=6

gimp_unit_defs = [
  # pseudo unit
  {
    'factor':       0.0,
    'digits':       0,
    'name':         "pixels",
    'symbol':       "px",
    'abbreviation': "px"
  },
  # standard units
  {
    'factor':       1.0,
    'digits':       2,
    'name':         "inches",
    'symbol':       "''",
    'abbreviation': "in"
  },
  {
    'factor':       25.4,
    'digits':       1,
    'name':         "millimeters",
    'symbol':       "mm",
    'abbreviation': "mm"
  },
  # professional units
  {
    'factor':       72.0,
    'digits':       0,
    'name':         "points",
    'symbol':       "pt",
    'abbreviation': "pt"
  },
  {
    'factor':       6.0,
    'digits':       1,
    'name':         "picas",
    'symbol':       "pc",
    'abbreviation': "pc"
  }
]

unit = Gimp.Unit.inch()
gimp_assert('Gimp.Unit.inch()', type(unit) == Gimp.Unit)

unit2 = Gimp.Unit.inch()
gimp_assert('Gimp.Unit.inch() always returns an unique object', unit == unit2)

for i in range(len(gimp_unit_defs)):
  unit = Gimp.Unit.get_by_id(i)
  unitdef = gimp_unit_defs[i]
  gimp_assert('Testing built-in unit {}'.format(i),
              type(unit) == Gimp.Unit                            and \
              unit.get_name() == unitdef['name']                 and \
              unit.get_symbol() == unitdef['symbol']             and \
              unit.get_abbreviation() == unitdef['abbreviation'] and \
              unit.get_factor() == unitdef['factor']             and \
              unit.get_digits() == unitdef['digits'])

  if i == Gimp.UnitID.INCH:
    gimp_assert('Gimp.Unit.inch() is the same as Gimp.Unit.get_by_id (Gimp.UnitID.INCH)',
                unit == unit2)

unit = Gimp.Unit.get_by_id(Gimp.UnitID.END)
n_user_units = 0
while unit is not None:
  n_user_units += 1
  unit = Gimp.Unit.get_by_id(Gimp.UnitID.END + n_user_units)
gimp_assert('Counting default user units', n_user_units == N_DEFAULT_USER_UNITS)

unit2 = Gimp.Unit.new ("name", 2.0, 1, "symbol", "abbreviation");
gimp_assert('Gimp.Unit.new()', type(unit2) == Gimp.Unit)

gimp_assert("Verifying the new user unit's ID", unit2.get_id() == Gimp.UnitID.END + n_user_units)
gimp_assert("Verifying the new user unit's unicity", unit2 == Gimp.Unit.get_by_id(Gimp.UnitID.END + n_user_units))

unit = Gimp.Unit.get_by_id(Gimp.UnitID.END)
n_user_units = 0
while unit is not None:
  n_user_units += 1
  unit = Gimp.Unit.get_by_id(Gimp.UnitID.END + n_user_units)
gimp_assert('Counting again user units', n_user_units == N_DEFAULT_USER_UNITS + 1)