cyphesis/rulesets/basic/scripts/test_python_api.py

101 lines
3.3 KiB
Python
Raw Permalink Normal View History

2018-10-11 22:48:46 +02:00
# This file is distributed under the terms of the GNU General Public license.
# Copyright (C) 2006 Al Riddoch (See the file COPYING for details).
2017-03-19 21:36:52 +01:00
import sys
import atlas
import Vector3D
import Point3D
def default(mapeditor):
2018-05-02 15:27:55 +02:00
print("Test logging")
sys.stdout.write("Test stdout\n")
sys.stderr.write("Test stderr\n")
2018-05-02 15:27:55 +02:00
print("Test operation")
2018-10-11 22:48:46 +02:00
operation = atlas.Operation("move")
assert (len(operation) == 0)
operation = atlas.Operation("move", atlas.Entity("1"))
assert (len(operation) == 1)
assert (operation[0].id == "1")
operation = atlas.Operation("move", atlas.Entity("2"), atlas.Entity("3"))
assert (len(operation) == 2)
assert (operation[0].id == "2")
assert (operation[1].id == "3")
operation = atlas.Operation("move", atlas.Entity("4"), atlas.Entity("5"), atlas.Entity("6"))
assert (len(operation) == 3)
assert (operation[0].id == "4")
assert (operation[1].id == "5")
assert (operation[2].id == "6")
operation = atlas.Operation("move", atlas.Entity("7"), to="8", from_="9")
assert (len(operation) == 1)
assert (operation[0].id == "7")
assert (operation.to == "8")
assert (operation.from_ == "9")
2018-10-11 22:48:46 +02:00
assert (operation.get_serialno() != 452)
assert (operation.get_refno() != 567)
assert (operation.get_from() != "10")
assert (operation.get_to() != "11")
assert (operation.get_seconds() != 577)
assert (operation.get_future_seconds() != 345)
2018-10-11 22:48:46 +02:00
operation.set_serialno(452)
operation.set_refno(567)
operation.set_from("10")
operation.set_to("11")
operation.set_seconds(577.5)
operation.set_future_seconds(345.5)
operation.set_args([atlas.Operation("set")])
2018-10-11 22:48:46 +02:00
assert (operation.get_serialno() == 452)
assert (operation.get_refno() == 567)
assert (operation.get_from() == "10")
assert (operation.get_to() == "11")
assert (operation.get_seconds() == 577.5)
assert (operation.get_future_seconds() == 345.5)
assert (len(operation.get_args()) == 1)
2018-05-02 15:27:55 +02:00
print("Test location")
2018-10-11 22:48:46 +02:00
a = 1
if atlas.isLocation(a):
2018-05-02 15:27:55 +02:00
raise AssertionError("atlas.isLocation returned true on an integer")
2018-11-03 16:43:33 +01:00
location = rules.Location()
if not atlas.isLocation(location):
2018-05-02 15:27:55 +02:00
raise AasertionError("atlas.isLocation returned false on a Location")
# FIXME No current way to create an entity
2018-11-03 16:43:33 +01:00
# location=rules.Location('23')
# location=rules.Location('42', Vector3D(1,0,0))
2018-05-02 15:27:55 +02:00
print("Test entity")
2018-10-11 22:48:46 +02:00
entity = atlas.Entity()
entity = atlas.Entity("1")
assert (entity.id == "1")
# FIXME other methods
2018-05-02 15:27:55 +02:00
print("Test message")
2018-10-11 22:48:46 +02:00
message = atlas.Oplist()
assert (len(message) == 0)
message.append(atlas.Operation("move"))
2018-10-11 22:48:46 +02:00
assert (len(message) == 1)
message = atlas.Oplist(atlas.Operation("move"))
assert (len(message) == 1)
# FIXME other methods
2018-05-02 15:27:55 +02:00
print("Test vector")
2018-10-11 22:48:46 +02:00
vector = Vector3D.Vector3D()
vector = Vector3D.Vector3D([0, 0, 1])
vector = Vector3D.Vector3D([0.1, 0.1, 1.1])
vector = Vector3D.Vector3D(0, 0, 1)
vector = Vector3D.Vector3D(0.1, 0.1, 1.1)
# FIXME other methods
2018-05-02 15:27:55 +02:00
print("Test point")
2018-10-11 22:48:46 +02:00
vector = Point3D.Point3D()
vector = Point3D.Point3D([0, 0, 1])
vector = Point3D.Point3D([0.1, 0.1, 1.1])
vector = Point3D.Point3D(0, 0, 1)
vector = Point3D.Point3D(0.1, 0.1, 1.1)
# FIXME other methods