Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test suite to pytest #1335

Merged
merged 5 commits into from
May 23, 2024
Merged

Move test suite to pytest #1335

merged 5 commits into from
May 23, 2024

Conversation

tpaviot
Copy link
Owner

@tpaviot tpaviot commented May 23, 2024

No description provided.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

Comment on lines +91 to +98
for ed in t.edges():
is_bezier, bezier_curve, degree = edge_to_bezier(ed)
assert isinstance(is_bezier, bool)
if not is_bezier:
assert degree is None
assert bezier_curve is None
else:
assert isinstance(degree, int)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +94 to +98
if not is_bezier:
assert degree is None
assert bezier_curve is None
else:
assert isinstance(degree, int)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +54 to +56
for edge in topo.edges():
pnts = discretize_edge(edge)
assert pnts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +62 to +64
for wire in topo.wires():
pnts = discretize_wire(wire)
assert pnts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +69 to +71
for face in topo.faces():
i += 1
assert isinstance(face, TopoDS_Face)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines 256 to 259

QC = gccent.Outside(C)
P4 = gp_Pnt2d(-2, 7)
P5 = gp_Pnt2d(12, -3)
L = GccAna_Lin2d2Tan(P4, P5, precision.Confusion()).ThisSolution(1)

QL = gccent.Unqualified(L)
radius = 2.0
TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision.Confusion())

if TR.IsDone():
NbSol = TR.NbSolutions()
for k in range(1, NbSol + 1):
circ = TR.ThisSolution(k)
# find the solution circle
pnt1 = gp_Pnt2d()
parsol, pararg = TR.Tangency1(k, pnt1)
self.assertGreater(parsol, 0.0)
self.assertGreater(pararg, 0.0)
# find the first tangent point
pnt2 = gp_Pnt2d()
parsol, pararg = TR.Tangency2(k, pnt2)
self.assertGreater(parsol, 0.0)
self.assertGreater(pararg, 0.0)
# find the second tangent point

aLine = GCE2d_MakeSegment(L, -2, 20).Value()
self.assertIsInstance(aLine, Geom2d_TrimmedCurve)
if TR.IsDone():
NbSol = TR.NbSolutions()
for k in range(1, NbSol + 1):
circ = TR.ThisSolution(k)
aCircle = Geom2d_Circle(circ)
self.assertIsInstance(aCircle, Geom2d_Circle)
# find the solution circle (index, outvalue, outvalue, gp_Pnt2d)
pnt3 = gp_Pnt2d()
parsol, pararg = TR.Tangency1(k, pnt3)
self.assertGreater(parsol, 0.0)
self.assertGreater(pararg, 0.0)
# find the first tangent point
pnt4 = gp_Pnt2d()
parsol, pararg = TR.Tangency2(k, pnt4)
self.assertGreater(parsol, 0.0)
self.assertGreater(pararg, 0.0)

def test_surface_from_curves(self):
"""Test: surfaces from curves"""
array = [gp_Pnt(-4, 0, 2)]
array.append(gp_Pnt(-7, 2, 2))
array.append(gp_Pnt(-6, 3, 1))
array.append(gp_Pnt(-4, 3, -1))
array.append(gp_Pnt(-3, 5, -2))

aaa = point_list_to_TColgp_Array1OfPnt(array)
SPL1 = GeomAPI_PointsToBSpline(aaa).Curve()

a2 = [gp_Pnt(-4, 0, 2)]
a2.append(gp_Pnt(-2, 2, 0))
a2.append(gp_Pnt(2, 3, -1))
a2.append(gp_Pnt(3, 7, -2))
a2.append(gp_Pnt(4, 9, -1))
bbb = point_list_to_TColgp_Array1OfPnt(a2)
SPL2 = GeomAPI_PointsToBSpline(bbb).Curve()

aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)

SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle)

SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle)

aBSplineSurface1 = aGeomFill1.Surface()
self.assertTrue(aBSplineSurface1 is not None)
aBSplineSurface2 = aGeomFill2.Surface()
self.assertTrue(aBSplineSurface2 is not None)
aBSplineSurface3 = aGeomFill3.Surface()
self.assertTrue(aBSplineSurface3 is not None)

def test_pipes(self):
"""Test: pipes"""
a1 = [gp_Pnt(-4, 0, 2)]
a1.append(gp_Pnt(-5, 1, 0))
a1.append(gp_Pnt(-6, 2, -2))
a1.append(gp_Pnt(-5, 4, -7))
a1.append(gp_Pnt(-3, 5, -12))

xxx = point_list_to_TColgp_Array1OfPnt(a1)
SPL1 = GeomAPI_PointsToBSpline(xxx).Curve()

aPipe = GeomFill_Pipe(SPL1, True)
aPipe.Perform(False, False)
aSurface = aPipe.Surface()
self.assertIsNotNone(aSurface)

P = ICQ.Point(i)
assert isinstance(P, gp_Pnt)
# pstring = "P%i" % i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +335 to +337
for P in array:
i = i + 1
make_vertex(P)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +338 to +341
for j in range(harray.Lower(), harray.Upper() + 1):
i = i + 1
P = harray.Value(j)
make_vertex(P)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +343 to +346
for j in range(harray2.Lower(), harray2.Upper() + 1):
i = i + 1
P = harray2.Value(j)
make_vertex(P)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines 397 to 411
if TR.IsDone():
NbSol = TR.NbSolutions()
for k in range(1, NbSol + 1):
circ = TR.ThisSolution(k)
# find the solution circle
pnt1 = gp_Pnt2d()
parsol, pararg = TR.Tangency1(k, pnt1)
assert parsol > 0.0
assert pararg > 0.0
# find the first tangent point
pnt2 = gp_Pnt2d()
parsol, pararg = TR.Tangency2(k, pnt2)
assert parsol > 0.0
assert pararg > 0.0
# find the second tangent point
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

@tpaviot tpaviot merged commit 23e7132 into master May 23, 2024
0 of 11 checks passed
@tpaviot tpaviot deleted the review/pytst branch May 23, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant