How to use _append_child method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

geometry_writer.py

Source:geometry_writer.py Github

copy

Full Screen

...41 def addSnsDefaults(self):42 """43 Set the default properties for SNS geometries44 """45 defaults_element = self._append_child("defaults", self._root)46 self._append_child("length", defaults_element, unit="metre")47 self._append_child("angle", defaults_element, unit="degree")48 reference_element = self._append_child("reference-frame", defaults_element)49 self._append_child("along-beam", reference_element, axis="z")50 self._append_child("pointing-up", reference_element, axis="y")51 self._append_child("handedness", reference_element, axis="right")52 def addComment(self, comment):53 """54 Add a global comment to the XML file55 @param comment: comment to be added to the XML file56 """57 if comment is None:58 return59 child = self._document.createComment(str(comment))60 self._root.appendChild(child)61 def _append_child(self, element_name, element_parent, **kwargs):62 element = self._document.createElement(element_name)63 for item in kwargs:64 element.setAttribute(item, str(kwargs[item]))65 element_parent.appendChild(element)66 return element67 def addModerator(self, distance):68 """69 This adds the moderator position for the instrument70 """71 source = self._append_child("component", self._root, type="moderator")72 try:73 distance = float(distance)74 if distance > 0:75 distance *= -1.076 self._append_child("location", source, z=distance)77 except (Exception, StopIteration, Warning):78 print("PROBLEM with addModerator")79 child = self._append_child("type", self._root, name="moderator")80 child.setAttribute("is", "Source")81 def addSamplePosition(self, location=None, coord_type="cartesian"):82 """83 Adds the sample position to the file. The coordinates should be passed84 as a tuple of (x, y, z) or (r, t, p). Default location is (0, 0, 0) in85 cartesian coordinates.86 """87 sample = self._append_child("component", self._root, type="sample-position")88 if location is None:89 self._append_child("location", sample, x="0.0", y="0.0", z="0.0")90 else:91 if coord_type == "cartesian":92 self._append_child("location", sample,93 x=location[0],94 y=location[1],95 z=location[2])96 if coord_type == "spherical":97 self._append_child("location", sample,98 r=location[0],99 t=location[1],100 p=location[2])101 child = self._append_child("type", self._root, name="sample-position")102 child.setAttribute("is", "SamplePos")103 def addDetectorPixels(self, name, r=None, theta=None, phi=None, names=None, energy=None):104 self.list_func(r)105 self.list_func(theta)106 self.list_func(phi)107 self.list_func(names)108 self.list_func(energy)109 type_element = self._append_child("type", self._root, name=name)110 for i in range(len(r)):111 for j in range(len(r[i])):112 if str(r[i][j]) != "nan":113 basecomponent = self._append_child("component", type_element, type="pixel")114 location_element = self._append_child("location", basecomponent, r=str(r[i][j]),115 t=str(theta[i][j]), p=str(phi[i][j]), name=str(names[i][j]))116 self._append_child("facing", location_element, x="0.0", y="0.0", z="0.0")117 efixed_comp = self._append_child("parameter", basecomponent, name="Efixed")118 self._append_child("value", efixed_comp, val=str(energy[i][j]))119 def addDetectorPixelsIdList(self, name, r=None, names=None):120 self.list_func(r)121 self.list_func(names)122 component = self._append_child("idlist", self._root, idname=name)123 for i in range(len(r)):124 for j in range(len(r[i])):125 if str(r[i][j]) != "nan":126 self._append_child("id", component, val=str(names[i][j]))127 def addMonitors(self, distance=None, names=None):128 self.list_func(distance)129 self.list_func(names)130 # Add a list of monitors to the geometry.131 if len(distance) != len(names):132 raise IndexError("Distance and name list must be same size!")133 component = self._append_child("component", self._root, type="monitors", idlist="monitors")134 self._append_child("location", component)135 type_element = self._append_child("type", self._root, name="monitors")136 basecomponent = self._append_child("component", type_element, type="monitor")137 basecomponent.setAttribute("mark-as", "monitor")138 for i in range(len(distance)):139 self._append_child("location", basecomponent, z=distance[i], name=names[i])140 def addComponent(self, type_name, idlist=None, root=None, blank_location=True):141 """142 Add a component to the XML definition. A blank location is added.143 """144 if root is None:145 root = self._root146 comp = None147 if idlist is not None:148 comp = self._append_child("component", root, type=type_name, idlist=idlist)149 else:150 comp = self._append_child("component", root, type=type_name)151 l = comp152 if blank_location:153 l = self._append_child("location", comp)154 return l155 def makeTypeElement(self, name):156 """157 Return a simple type element.158 """159 return self._append_child("type", self._root, name=name)160 def makeDetectorElement(self, name, idlist_type=None, root=None):161 """162 Return a component element.163 """164 if root is not None:165 root_element = root166 else:167 root_element = self._root168 if idlist_type is not None:169 return self._append_child("component", root_element, type=name, idlist=idlist_type)170 else:171 return self._append_child("component", root_element, type=name)172 def makeIdListElement(self, name):173 return self._append_child("idlist", self._root, idname=name)174 def addDetector(self, x, y, z, rot_x, rot_y, rot_z, name, comp_type, usepolar=None):175 """176 Add a detector in a type element for the XML definition.177 """178 type_element = self._append_child("type", self._root, name=name)179 comp_element = self._append_child("component", type_element, type=comp_type)180 if usepolar is not None:181 self.addLocationPolar(comp_element, x, y, z)182 else:183 self.addLocation(comp_element, x, y, z, rot_x, rot_y, rot_z)184 def addSingleDetector(self, root, x, y, z, rot_x, rot_y, rot_z, name=None,185 _id=None, usepolar=None):186 """187 Add a single detector by explicit declaration. The rotation order is188 performed as follows: y, x, z.189 """190 if name is None:191 name = "bank"192 if usepolar is not None:193 self.addLocationPolar(root, x, y, z, name)194 else:195 self.addLocation(root, x, y, z, rot_x, rot_y, rot_z, name)196 def addLocation(self, root, x, y, z, rot_x, rot_y, rot_z, name=None):197 """198 Add a location element to a specific parent node given by root.199 """200 if name is not None:201 pos_loc = self._append_child("location", root, x=str(x), y=str(y), z=str(z), name=name)202 else:203 pos_loc = self._append_child("location", root, x=str(x), y=str(y), z=str(z))204 if rot_y is not None:205 r1 = self._append_child("rot", pos_loc, **{"val": str(rot_y), "axis-x": "0",206 "axis-y": "1", "axis-z": "0"})207 else:208 r1 = pos_loc209 if rot_x is not None:210 r2 = self._append_child("rot", r1, **{"val": str(rot_x), "axis-x": "1",211 "axis-y": "0", "axis-z": "0"})212 else:213 r2 = r1214 if rot_z is not None:215 self._append_child("rot", r2, **{"val": str(rot_z), "axis-x": "0",216 "axis-y": "0", "axis-z": "1"})217 def addLocationPolar(self, root, r, theta, phi, name=None):218 if name is not None:219 self._append_child("location", root, r=r, t=theta, p=phi, name=name)220 else:221 self._append_child("location", root, r=r, t=theta, p=phi)222 def addLocationRTP(self, root, r, t, p, rot_x, rot_y, rot_z, name=None):223 """224 Add a location element to a specific parent node given by root, using r, theta, phi coordinates.225 """226 float(r)227 float(t)228 float(p)229 if name is not None:230 pos_loc = self._append_child("location", root, r=r, t=t, p=p, name=name)231 else:232 pos_loc = self._append_child("location", root, r=r, t=t, p=p)233 # add rotx, roty, rotz234 # Regardless of what order rotx, roty and rotz is specified in the IDF,235 # the combined rotation is equals that obtained by applying rotx, then roty and finally rotz.236 if rot_x is not None:237 log = self._append_child("parameter", pos_loc, name="rotx")238 float(rot_x)239 self._append_child("value", log, val=rot_x)240 if rot_y is not None:241 log = self._append_child("parameter", pos_loc, name="roty")242 float(rot_y)243 self._append_child("value", log, val=rot_y)244 if rot_z is not None:245 log = self._append_child("parameter", pos_loc, name="rotz")246 float(rot_z)247 self._append_child("value", log, val=rot_z)248 def addNPack(self, name, num_tubes, tube_width, air_gap, type_name="tube"):249 """250 Add a block of N tubes in a pack. A name for the pack type needs251 to be specified as well as the number of tubes in the pack, the tube252 width and air gap. If there are going to be more than one type tube253 specified later, an optional type name can be given. The default tube254 type name will be tube.255 """256 type_element = self._append_child("type", self._root, name=name)257 self._append_child("properties", type_element)258 component = self._append_child("component", type_element, type=type_name)259 effective_tube_width = tube_width + air_gap260 pack_start = (effective_tube_width / 2.0) * (1 - num_tubes)261 for i in range(num_tubes):262 tube_name = "tube%d" % (i + 1)263 x = pack_start + (i * effective_tube_width)264 self._append_child("location", component, name=tube_name, x=str(x))265 def addPixelatedTube(self, name, num_pixels, tube_height,266 type_name="pixel"):267 """268 Add a tube of N pixels. If there are going to be more than one pixel269 type specified later, an optional type name can be given. The default270 pixel type name will be pixel.271 """272 type_element = self._append_child("type", self._root, outline="yes", name=name)273 self._append_child("properties", type_element)274 component = self._append_child("component", type_element, type=type_name)275 pixel_width = tube_height / num_pixels276 tube_start = (pixel_width / 2.0) * (1 - num_pixels)277 for i in range(num_pixels):278 pixel_name = "pixel%d" % (i + 1)279 y = tube_start + (i * pixel_width)280 self._append_child("location", component, name=pixel_name, y=str(y))281 def addCylinderPixel(self, name, center_bottom_base, axis, pixel_radius,282 pixel_height, is_type="detector"):283 """284 Add a cylindrical pixel. The center_bottom_base is a 3-tuple of radius,285 theta, phi. The axis is a 3-tuple of x, y, z.286 """287 type_element = self._append_child("type", self._root, **{"name": name, "is": is_type})288 cylinder = self._append_child("cylinder", type_element, id="cyl-approx")289 self._append_child("centre-of-bottom-base", cylinder,290 r=str(center_bottom_base[0]),291 t=str(center_bottom_base[1]),292 p=str(center_bottom_base[2]))293 self._append_child("axis", cylinder,294 x=str(axis[0]), y=str(axis[1]), z=str(axis[2]))295 self._append_child("radius", cylinder, val=str(pixel_radius))296 self._append_child("height", cylinder, val=str(pixel_height))297 self._append_child("algebra", type_element, val="cyl-approx")298 def addCuboidPixel(self, name, lfb_pt, lft_pt, lbb_pt, rfb_pt,299 is_type="detector"):300 """301 Add a cuboid pixel. The origin of the cuboid is assumed to be the302 center of the front face of the cuboid. The parameters lfb_pt, lft_pt,303 lbb_pt, rfb_pt are 3-tuple of x, y, z.304 """305 type_element = self._append_child("type", self._root, **{"name": name, "is": is_type})306 cuboid = self._append_child("cuboid", type_element, id="shape")307 self._append_child("left-front-bottom-point", cuboid, x=str(lfb_pt[0]),308 y=str(lfb_pt[1]), z=str(lfb_pt[2]))309 self._append_child("left-front-top-point", cuboid, x=str(lft_pt[0]),310 y=str(lft_pt[1]), z=str(lft_pt[2]))311 self._append_child("left-back-bottom-point", cuboid, x=str(lbb_pt[0]),312 y=str(lbb_pt[1]), z=str(lbb_pt[2]))313 self._append_child("right-front-bottom-point", cuboid, x=str(rfb_pt[0]),314 y=str(rfb_pt[1]), z=str(rfb_pt[2]))315 self._append_child("algebra", type_element, val="shape")316 def addDummyMonitor(self, radius, height):317 """318 Add a dummy monitor with some-shape.319 """320 type_element = self._append_child("type", self._root, **{"name": "monitor", "is": "detector"})321 cylinder = self._append_child("cylinder", type_element, id="cyl-approx")322 self._append_child("centre-of-bottom-base", cylinder, x="0.0", y="0.0", z="0.0")323 self._append_child("axis", cylinder, x="0.0", y="0.0", z="1.0")324 self._append_child("radius", cylinder, radius=str(radius))325 self._append_child("height", cylinder, height=str(height))326 self._append_child("algebra", type_element, val="cyl-approx")327 def addCuboidMonitor(self, width, height, depth):328 """329 Add a cuboid monitor330 """331 type_element = self._append_child("type", self._root, **{"name": "monitor", "is": "detector"})332 cuboid = self._append_child("cuboid", type_element, id="shape")333 self._append_child("left-front-bottom-point", cuboid, x=str(-width / 2), y=str(-height / 2), z=str(-depth / 2))334 self._append_child("left-front-top-point", cuboid, x=str(-width / 2), y=str(height / 2), z=str(-depth / 2))335 self._append_child("left-back-bottom-point", cuboid, x=str(-width / 2), y=str(-height / 2), z=str(depth / 2))336 self._append_child("right-front-bottom-point", cuboid, x=str(width / 2), y=str(-height / 2), z=str(-depth / 2))337 self._append_child("algebra", type_element, val="shape")338 def addDetectorIds(self, idname, idlist):339 """340 Add the detector IDs. A list is provided that must be divisible by 3.341 The list should be specified as [start1, end1, step1, start2, end2,342 step2, ...]. If no step is required, use None.343 """344 if len(idlist) % 3 != 0:345 raise IndexError("Please specify list as [start1, end1, step1, "346 + "start2, end2, step2, ...]. If no step is"347 + "required, use None.")348 num_ids = len(idlist) / 3349 id_element = self._append_child("idlist", self._root, idname=idname)350 for i in range(num_ids):351 if idlist[(i * 3) + 2] is None:352 self._append_child("id", id_element, start=str(idlist[(i * 3)]),353 end=str(idlist[(i * 3) + 1]))354 else:355 self._append_child("id", id_element, start=str(idlist[(i * 3)]),356 step=str(idlist[(i * 3) + 2]),357 end=str(idlist[(i * 3) + 1]))358 def addMonitorIds(self, ids=None):359 self.list_func(ids)360 # Add the monitor IDs.361 idElt = self._append_child("idlist", self._root, idname="monitors")362 for i in range(len(ids)):363 self._append_child("id", idElt, val=ids[i])364 def addDetectorParameters(self, component_name, *args):365 """366 Add detector parameters to a particular component name. Args is an367 arbitrary list of 3-tuples containing the following information:368 (parameter name, parameter value, parameter units).369 """370 complink = self._append_child("component-link", self._root, name=component_name)371 for arg in args:372 if len(arg) != 3:373 raise IndexError("Will not be able to parse:", arg)374 par = self._append_child("parameter", complink, name=arg[0])375 self._append_child("value", par, val=str(arg[1]), units=str(arg[2]))376 def list_func(self, items=None):377 if items is None:378 items = []...

Full Screen

Full Screen

annotation_utils.py

Source:annotation_utils.py Github

copy

Full Screen

...11#------------------------------------------------------12class PascalVOC_Writer(object):13 def __init__(self, dir=os.getcwd()):14 self.dir = dir15 def _append_child(self, newdoc, parent, child, value=None):16 if value is not None:17 if not isinstance(value, str):18 value = str(value)19 child.appendChild(newdoc.createTextNode(value))20 parent.appendChild(child)21 def write(self, fname, size, classes, boxes):22 width, height, depth = size23 newdoc = xml.dom.minidom.Document()24 elm_annotation = newdoc.createElement('annotaion')25 self._append_child(newdoc, newdoc, elm_annotation)26 self._append_child(newdoc, elm_annotation, newdoc.createElement('filename'), fname)27 elm_size = newdoc.createElement('size')28 self._append_child(newdoc, elm_annotation, elm_size)29 self._append_child(newdoc, elm_size, newdoc.createElement('depth'), depth)30 self._append_child(newdoc, elm_size, newdoc.createElement('width'), width)31 self._append_child(newdoc, elm_size, newdoc.createElement('height'), height)32 for classname, box in zip(classes, boxes):33 xmin, ymin, xmax, ymax = box34 elm_object = newdoc.createElement('object')35 self._append_child(newdoc, elm_annotation, elm_object)36 self._append_child(newdoc, elm_object, newdoc.createElement('name'), classname)37 self._append_child(newdoc, elm_object, newdoc.createElement('pose'), 'Unspecified')38 elm_bndbox= newdoc.createElement('bndbox')39 self._append_child(newdoc, elm_object, elm_bndbox)40 self._append_child(newdoc, elm_bndbox, newdoc.createElement('xmin'), xmin)41 self._append_child(newdoc, elm_bndbox, newdoc.createElement('ymin'), ymin)42 self._append_child(newdoc, elm_bndbox, newdoc.createElement('xmax'), xmax)43 self._append_child(newdoc, elm_bndbox, newdoc.createElement('ymax'), ymax)44 voc_xml = newdoc.toprettyxml()45 out_path = os.path.join(self.dir, fname+'.xml')46 with open(os.path.join(self.dir, fname+'.xml'), 'w') as f:47 f.write(voc_xml)48class PascalVoc_Object(object):49 def __init__(self, classname=None, pose=None, box=None):50 self.classname = classname51 self.pose = pose52 self.box = box53class PascalVOC_Reader(object):54 def __init__(self, dir=os.getcwd()):55 self.dir = dir56 self.data = dict()57 self._parse()...

Full Screen

Full Screen

append_dirs_to_path.py

Source:append_dirs_to_path.py Github

copy

Full Screen

1import sys2import os3def append_dirs_to_path():4 current_dir = os.path.dirname(os.path.abspath(__file__))5 _append_child(current_dir, 'pid_controller')6 _append_child(current_dir, 'adaptive_pid_controller')7 _append_child(current_dir, 'envs')8 _append_child(current_dir, 'interfaces')9def _append_child(directory, child):10 child = os.path.join(directory, child)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unittest-xml-reporting automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful