Skip to content

Commit 8be7997

Browse files
committed
updates to handle relative pathing for imports so that importing under pytest, internal calls and the library all work together.
includes some mocking around tests so that ocp_vscode.show isn't executing
1 parent 12dec85 commit 8be7997

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

build.bat

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
setlocal
3+
4+
5+
SET PROJECT_NAME=fb-library
6+
7+
SET /P PYTEST_CHOSEN=Do you want to run pytest --cov ([Y]/N)?
8+
IF /I "%PYTEST_CHOSEN%" NEQ "N" GOTO TEST
9+
GOTO BUILD
10+
11+
:TEST
12+
pytest --cov
13+
14+
SET /P PYTEST_CLEAN=Based on the pytest results, proceed with the build? ([Y]/N)?
15+
IF /I "%PYTEST_CLEAN%" NEQ "N" GOTO BUILD
16+
17+
GOTO END
18+
19+
:BUILD
20+
py -m pip uninstall -y %PROJECT_NAME%
21+
22+
py -m build
23+
py -m pip install -e .
24+
25+
:TESTLOCAL
26+
python -c "exec(\"from fb_library import dovetail_subpart, click_fit, Point, shifted_midpoint\nprint(shifted_midpoint(Point(0,0), Point(10,10),0))\")"
27+
:END
28+
endlocal

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fb-library"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
authors = [
55
{ name="x0pherl"},
66
]

src/fb_library/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from .point import Point, midpoint, shifted_midpoint
12
from .click_fit import divot
23
from .dovetail import (
4+
dovetail_subpart,
5+
dovetail_subpart_outline,
36
dovetail_split_line,
47
DovetailPart,
58
)
6-
from .point import Point, midpoint, shifted_midpoint

src/fb_library/dovetail.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
loft,
2323
make_face,
2424
)
25-
from point import (
25+
from fb_library import (
2626
Point,
2727
midpoint,
2828
shifted_midpoint,
@@ -35,7 +35,7 @@ class DovetailPart(Enum):
3535
SOCKET = 2
3636

3737

38-
def subpart_outline(
38+
def dovetail_subpart_outline(
3939
part: Part,
4040
start: Point,
4141
end: Point,
@@ -123,7 +123,7 @@ def subpart_outline(
123123
return bottom_tail_line.line
124124

125125

126-
def subpart(
126+
def dovetail_subpart(
127127
part: Part,
128128
start: Point,
129129
end: Point,
@@ -156,7 +156,7 @@ def subpart(
156156
with BuildSketch(Plane.XY.offset(part.bounding_box().min.Z)):
157157
with BuildLine():
158158
add(
159-
subpart_outline(
159+
dovetail_subpart_outline(
160160
part=part,
161161
start=start,
162162
end=end,
@@ -174,7 +174,7 @@ def subpart(
174174
with BuildSketch(Plane.XY.offset(part.bounding_box().max.Z)):
175175
with BuildLine():
176176
add(
177-
subpart_outline(
177+
dovetail_subpart_outline(
178178
part=part,
179179
start=start,
180180
end=end,
@@ -308,15 +308,15 @@ def dovetail_split_line(
308308
with BuildPart() as test:
309309
Box(10, 50, 2, align=(Align.CENTER, Align.CENTER, Align.MIN))
310310
show(
311-
subpart(
311+
dovetail_subpart(
312312
test.part,
313313
Point(-5, 0),
314314
Point(5, 0),
315315
scarf_distance=0.5,
316316
section=DovetailPart.TAIL,
317317
tilt=20,
318318
),
319-
subpart(
319+
dovetail_subpart(
320320
test.part,
321321
Point(-5, 0),
322322
Point(5, 0),

tests/conftest.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
os.path.join(os.path.dirname(__file__), "../src/fb_library")
99
),
1010
)
11+
sys.path.insert(
12+
0,
13+
os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")),
14+
)

tests/test_click_fit.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ def test_divot(self):
2020

2121
def test_direct_run(self):
2222

23-
loader = SourceFileLoader("__main__", "src/fb_library/click_fit.py")
24-
loader.exec_module(
25-
module_from_spec(spec_from_loader(loader.name, loader))
26-
)
23+
with (
24+
patch("build123d.export_stl"),
25+
patch("pathlib.Path.mkdir"),
26+
patch("pathlib.Path.exists"),
27+
patch("pathlib.Path.is_dir"),
28+
patch("ocp_vscode.show"),
29+
patch("ocp_vscode.save_screenshot"),
30+
):
31+
loader = SourceFileLoader(
32+
"__main__", "src/fb_library/click_fit.py"
33+
)
34+
loader.exec_module(
35+
module_from_spec(spec_from_loader(loader.name, loader))
36+
)

0 commit comments

Comments
 (0)