Where to put regression tests?

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8544
Joined: Thu Dec 27, 2018 12:28 pm

Where to put regression tests?

Post by Roy_043 »

I'd like to add two regression tests for the Draft_Offset command. Can I add them to test_modification.py or should I create a new file similar to Mod/Part/parttests/regression_tests.py?

Related PR: https://github.com/FreeCAD/FreeCAD/pull/7670

Provisional code:

Code: Select all

import Draft
import Part
from FreeCAD import Vector
import unittest

operation = "Draft Offset: Closed wire with reversed edge"
# _msg("  Test '{}'".format(operation))

a = Vector(0, 0, 0)
b = Vector(10, 0, 0)
c = Vector(10, 4, 0)
d = Vector(0, 4, 0)

edges = [Part.makeLine(a, b),
         Part.makeLine(b, c),
         Part.makeLine(c, d),
         Part.makeLine(a, d)]
wire = Part.Wire(edges)

obj = App.ActiveDocument.addObject("Part::Feature")
obj.Shape = wire

offset = Vector(0, -1, 0)
new = Draft.offset(obj, offset, copy=True)
App.ActiveDocument.recompute()

unittest.TestCase().assertTrue(len(new.Points) == 4, "'{}' failed".format(operation))


#######################

import Draft
import Part
from FreeCAD import Vector
import unittest

operation = "Draft Offset: Rectangle with face"
# _msg("  Test '{}'".format(operation))

rect = Draft.make_rectangle(10, 4)
rect.MakeFace = True
App.ActiveDocument.recompute()

offset = Vector(0, -1, 0)
new = Draft.offset(rect, offset, copy=True)
App.ActiveDocument.recompute()

new_is_ok = (new.Shape.CenterOfGravity == Vector(5, 2, 0)
             and new.Length == 12
             and new.Height == 6)

unittest.TestCase().assertTrue(new_is_ok, "'{}' failed".format(operation))
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Where to put regression tests?

Post by yorik »

Roy_043 wrote: Thu Nov 03, 2022 10:38 am Can I add them to test_modification.py
I would say yes, unless the file becomes too big then it's better to split
Post Reply