Skip to content

Commit 36c25da

Browse files
committed
Correct final JefReader issues.
1 parent 6208a25 commit 36c25da

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

pyembroidery/JefReader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def read(f, out, settings=None):
6161
for i in range(0, count_colors):
6262
index = abs(read_int_32le(f))
6363
if index == 0:
64-
out.add_thread(None)
65-
out.add_thread(jef_threads[index % len(jef_threads)])
64+
out.threadlist.append(None)
65+
else:
66+
out.add_thread(jef_threads[index % len(jef_threads)])
6667

6768
print(out.threadlist)
6869
f.seek(stitch_offset, 0)

test/test_convert_jef.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,32 @@ def test_convert_jef_to_xxx(self):
170170
self.addCleanup(os.remove, file1)
171171
self.addCleanup(os.remove, file2)
172172

173-
def test_jef_stop_write(self):
174-
file2 = "stop2.jef"
175-
write_jef(get_simple_stop(), file2)
176-
s_pattern = read_jef(file2)
173+
def test_jef_stop_write_simple(self):
174+
file = "stop.jef"
175+
write_jef(get_simple_stop(), file)
176+
s_pattern = read_jef(file)
177177
self.assertEqual(s_pattern.count_stitch_commands(STOP), 1)
178178
self.assertEqual(s_pattern.count_color_changes(), 0)
179+
self.addCleanup(os.remove, file)
179180

180-
file1 = "stop.jef"
181+
def test_jef_stop_write_large(self):
182+
file = "stop2.jef"
181183
pattern = get_shift_stop_pattern()
182-
write_jef(pattern, file1)
183-
f_pattern = read_jef(file1)
184+
n_pattern = pattern.get_normalized_pattern()
185+
self.assertEqual(n_pattern.count_stitch_commands(COLOR_CHANGE), 15)
186+
self.assertEqual(n_pattern.count_stitch_commands(STITCH), 16 * 5)
187+
self.assertEqual(n_pattern.count_stitch_commands(STOP), 5)
188+
189+
write_jef(pattern, file)
190+
f_pattern = read_jef(file)
184191
self.assertIsNotNone(f_pattern)
185192

186-
with open(file1, "rb") as f:
193+
with open(file, "rb") as f:
187194
f.seek(0x18)
188195
colors = f.read(1)
189196
self.assertEqual(ord(colors), f_pattern.count_color_changes() + f_pattern.count_stitch_commands(STOP) + 1)
190197

191-
self.assertEqual(f_pattern.count_stitch_commands(COLOR_CHANGE), 12)
198+
self.assertEqual(f_pattern.count_stitch_commands(COLOR_CHANGE), 15)
192199
self.assertEqual(f_pattern.count_stitch_commands(STITCH), 16 * 5)
193-
self.assertEqual(f_pattern.count_stitch_commands(STOP), 6)
194-
self.position_equals(f_pattern.stitches, 0, -1)
195-
self.addCleanup(os.remove, file1)
196-
self.addCleanup(os.remove, file2)
200+
self.assertEqual(f_pattern.count_stitch_commands(STOP), 5)
201+
self.addCleanup(os.remove, file)

test/test_read_hus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestReadHus(unittest.TestCase):
1010

1111
def test_fake_compression(self):
1212
for i in range(10):
13-
s = random.randint(10, 1000)
13+
s = random.randint(10, 1000) # May fail if larger.
1414
test_bytes = bytearray(random.getrandbits(8) for _ in range(s))
1515
compressed_bytes = EmbCompress.compress(test_bytes)
1616
uncompressed = bytearray(EmbCompress.expand(compressed_bytes, len(test_bytes)))

0 commit comments

Comments
 (0)