autopilot.introspection.types
- Introspection Type details¶
Autopilot proxy type support.¶
This module defines the classes that are used for all attributes on proxy objects. All proxy objects contain attributes that transparently mirror the values present in the application under test. Autopilot takes care of keeping these values up to date.
Object attributes fall into two categories. Attributes that are a single
string, boolean, or integer property are sent directly across DBus. These are
called “plain” types, and are stored in autopilot as instnaces of the
PlainType
class. Attributes that are more complex (a rectangle, for
example) are called “complex” types, and are split into several component
values, sent across dbus, and are then reconstituted in autopilot into useful
objects.
-
class
autopilot.introspection.types.
PlainType
[source]¶ Plain type support in autopilot proxy objects.
Instances of this class will be used for all plain attrubites. The word “plain” in this context means anything that’s marshalled as a string, boolean or integer type across dbus.
Instances of these classes can be used just like the underlying type. For example, given an object property called ‘length’ that is marshalled over dbus as an integer value, the following will be true:
>>> isinstance(object.length, PlainType) True >>> isinstance(object.length, int) True >>> print(object.length) 123 >>> print(object.length + 32) 155
However, a special case exists for boolean values: because you cannot subclass from the ‘bool’ type, the following check will fail (
object.visible
is a boolean property):>>> isinstance(object.visible, bool) False
However boolean values will behave exactly as you expect them to.
-
class
autopilot.introspection.types.
Rectangle
(*args, **kwargs)[source]¶ The RectangleType class represents a rectangle in cartesian space.
To construct a rectangle, pass the x, y, width and height parameters in to the class constructor:
my_rect = Rectangle(12,13,100,150)
These attributes can be accessed either using named attributes, or via sequence indexes:
>>>my_rect = Rectangle(12,13,100,150) >>> my_rect.x == my_rect[0] == 12 True >>> my_rect.y == my_rect[1] == 13 True >>> my_rect.w == my_rect[2] == 100 True >>> my_rect.h == my_rect[3] == 150 True
You may also access the width and height values using the
width
andheight
properties:>>> my_rect.width == my_rect.w True >>> my_rect.height == my_rect.h True
Rectangles can be compared using
==
and!=
, either to another Rectangle instance, or to any mutable sequence type:>>> my_rect == [12, 13, 100, 150] True >>> my_rect != Rectangle(1,2,3,4) True
-
class
autopilot.introspection.types.
Point
(*args, **kwargs)[source]¶ The Point class represents a 2D point in cartesian space.
To construct a Point, pass in the x, y parameters to the class constructor:
>>> my_point = Point(50,100)
These attributes can be accessed either using named attributes, or via sequence indexes:
>>> my_point.x == my_point[0] == 50 True >>> my_point.y == my_point[1] == 100 True
Point instances can be compared using
==
and!=
, either to another Point instance, or to any mutable sequence type with the correct number of items:>>> my_point == [50, 100] True >>> my_point != Point(5, 10) True
-
class
autopilot.introspection.types.
Size
(*args, **kwargs)[source]¶ The Size class represents a 2D size in cartesian space.
To construct a Size, pass in the width, height parameters to the class constructor:
>>> my_size = Size(50,100)
These attributes can be accessed either using named attributes, or via sequence indexes:
>>> my_size.width == my_size.w == my_size[0] == 50 True >>> my_size.height == my_size.h == my_size[1] == 100 True
Size instances can be compared using
==
and!=
, either to another Size instance, or to any mutable sequence type with the correct number of items:>>> my_size == [50, 100] True >>> my_size != Size(5, 10) True
-
class
autopilot.introspection.types.
DateTime
(*args, **kwargs)[source]¶ The DateTime class represents a date and time in the UTC timezone.
DateTime is constructed by passing a unix timestamp in to the constructor. The incoming timestamp is assumed to be in UTC.
Note
This class expects the passed in timestamp to be in UTC but will display the resulting date and time in local time (using the local timezone).
This is done to mimic the behaviour of most applications which will display date and time in local time by default
Timestamps are expressed as the number of seconds since 1970-01-01T00:00:00 in the UTC timezone:
>>> my_dt = DateTime(1377209927)
This timestamp can always be accessed either using index access or via a named property:
>>> my_dt[0] == my_dt.timestamp == 1377209927 True
DateTime objects also expose the usual named properties you would expect on a date/time object:
>>> my_dt.year 2013 >>> my_dt.month 8 >>> my_dt.day 22 >>> my_dt.hour 22 >>> my_dt.minute 18 >>> my_dt.second 47
Two DateTime objects can be compared for equality:
>>> my_dt == DateTime(1377209927) True
You can also compare a DateTime with any mutable sequence type containing the timestamp (although this probably isn’t very useful for test authors):
>>> my_dt == [1377209927] True
Finally, you can also compare a DateTime instance with a python datetime instance:
>>> my_datetime = datetime.datetime.utcfromtimestamp(1377209927) True
Note
Autopilot supports dates beyond 2038 on 32-bit platforms. To achieve this the underlying mechanisms require to work with timezone aware datetime objects.
This means that the following won’t always be true (due to the naive timestamp not having the correct daylight-savings time details):
>>> # This time stamp is within DST in the 'Europe/London' timezone >>> dst_ts = 1405382400 >>> os.environ['TZ'] ='Europe/London' >>> time.tzset() >>> datetime.fromtimestamp(dst_ts).hour == DateTime(dst_ts).hour False
But this will work:
>>> from dateutil.tz import gettz >>> datetime.fromtimestamp( dst_ts, gettz()).hour == DateTime(dst_ts).hour True
And this will always work to:
>>> dt1 = DateTime(nz_dst_timestamp) >>> dt2 = datetime( dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute, dt1.second ) >>> dt1 == dt2 True
Note
DateTime.timestamp() will not always equal the passed in timestamp. To paraphrase a message from [http://bugs.python.org/msg229393] “datetime.timestamp is supposed to be inverse of datetime.fromtimestamp(), but since the later is not monotonic, no such inverse exists in the strict mathematical sense.”
DateTime instances can be converted to datetime instances:
>>> isinstance(my_dt.datetime, datetime.datetime) True
-
class
autopilot.introspection.types.
Time
(*args, **kwargs)[source]¶ The Time class represents a time, without a date component.
You can construct a Time instnace by passing the hours, minutes, seconds, and milliseconds to the class constructor:
>>> my_time = Time(12, 34, 01, 23)
The values passed in must be valid for their positions (ie..- 0-23 for hours, 0-59 for minutes and seconds, and 0-999 for milliseconds). Passing invalid values will cause a ValueError to be raised.
The hours, minutes, seconds, and milliseconds can be accessed using either index access or named properties:
>>> my_time.hours == my_time[0] == 12 True >>> my_time.minutes == my_time[1] == 34 True >>> my_time.seconds == my_time[2] == 01 True >>> my_time.milliseconds == my_time[3] == 23 True
Time instances can be compared to other time instances, any mutable sequence containing four integers, or datetime.time instances:
>>> my_time == Time(12, 34, 01, 23) True >>> my_time == Time(1,2,3,4) False >>> my_time == [12, 34, 01, 23] True >>> my_time == datetime.time(12, 34, 01, 23000) True
Note that the Time class stores milliseconds, while the
datettime.time
class stores microseconds.Finally, you can get a
datetime.time
instance from a Time instance:>>> isinstance(my_time.time, datetime.time) True