Convert tests, couple corrections.

pull/22/head
tatarize 2018-09-29 20:36:17 -07:00 zatwierdzone przez GitHub
rodzic 61cf537864
commit f168c0fdf3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
22 zmienionych plików z 1397 dodań i 352 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
from pyembroidery.EmbConstant import *
from .EmbFunctions import *
READ_FILE_IN_TEXT_MODE = True

Wyświetl plik

@ -1,4 +1,4 @@
from .EmbConstant import *
from .EmbFunctions import *
from .WriteHelper import write_string_utf8
from .PecGraphics import get_graphic_as_string
import math

Wyświetl plik

@ -67,7 +67,7 @@ def dst_read_stitches(f, out):
dx = decode_dx(byte[0], byte[1], byte[2])
dy = decode_dy(byte[0], byte[1], byte[2])
if byte[2] & 0b11110011 == 0b11110011:
out.stop(dx, dy)
out.end(dx, dy)
elif byte[2] & 0b11000011 == 0b11000011:
out.color_change(dx, dy)
elif byte[2] & 0b01000011 == 0b01000011:

Wyświetl plik

@ -65,123 +65,3 @@ CONTINGENCY_SEQUIN_UTILIZE = 0xF5
CONTINGENCY_SEQUIN_JUMP = 0xF6
CONTINGENCY_SEQUIN_STITCH = 0xF7
CONTINGENCY_SEQUIN_REMOVE = 0xF8
def encode_thread_change(command, thread=None, needle=None, order=None):
if thread is None:
thread = 0
else:
thread += 1
thread &= 0xFF
if needle is None:
needle = 0
else:
needle += 1
needle &= 0xFF
if order is None:
order = 0
else:
order += 1
order &= 0xFF
command &= COMMAND_MASK
return command | (order << 24) | (needle << 16) | (thread << 8)
def decode_thread_change(command):
flag = command & COMMAND_MASK
thread = command & THREAD_MASK
thread >>= 8
thread -= 1
needle = command & NEEDLE_MASK
needle >>= 16
needle -= 1
order = command & ORDER_MASK
order >>= 24
order -= 1
return flag, thread, needle, order
def get_command_dictionary():
return {
"NO_COMMAND": NO_COMMAND,
"STITCH": STITCH,
"JUMP": JUMP,
"TRIM": TRIM,
"STOP": STOP,
"END": END,
"SLOW": SLOW,
"FAST": FAST,
"COLOR_CHANGE": COLOR_CHANGE,
"NEEDLE_SET": NEEDLE_SET,
"SET_CHANGE_SEQUENCE": SET_CHANGE_SEQUENCE,
"SEQUIN_MODE": SEQUIN_MODE,
"SEQUIN_EJECT": SEQUIN_EJECT,
"SEW_TO": SEW_TO,
"NEEDLE_AT": NEEDLE_AT,
"STITCH_BREAK": STITCH_BREAK,
"SEQUENCE_BREAK": SEQUENCE_BREAK,
"COLOR_BREAK": COLOR_BREAK,
"TIE_ON": TIE_ON,
"TIE_OFF": TIE_OFF,
"FRAME_EJECT": FRAME_EJECT,
"MATRIX_TRANSLATE": MATRIX_TRANSLATE,
"MATRIX_SCALE_ORIGIN": MATRIX_SCALE_ORIGIN,
"MATRIX_ROTATE_ORIGIN": MATRIX_ROTATE_ORIGIN,
"MATRIX_SCALE": MATRIX_SCALE,
"MATRIX_ROTATE": MATRIX_ROTATE,
"MATRIX_RESET": MATRIX_RESET,
"CONTINGENCY_TIE_ON_THREE_SMALL": CONTINGENCY_TIE_ON_THREE_SMALL,
"CONTINGENCY_TIE_OFF_THREE_SMALL": CONTINGENCY_TIE_OFF_THREE_SMALL,
"CONTINGENCY_TIE_ON_NONE": CONTINGENCY_TIE_ON_NONE,
"CONTINGENCY_TIE_OFF_NONE": CONTINGENCY_TIE_OFF_NONE,
"OPTION_MAX_STITCH_LENGTH": OPTION_MAX_STITCH_LENGTH,
"OPTION_MAX_JUMP_LENGTH": OPTION_MAX_JUMP_LENGTH,
"OPTION_IMPLICIT_TRIM": OPTION_IMPLICIT_TRIM,
"OPTION_EXPLICIT_TRIM": OPTION_EXPLICIT_TRIM,
"CONTINGENCY_LONG_STITCH_NONE": CONTINGENCY_LONG_STITCH_NONE,
"CONTINGENCY_LONG_STITCH_JUMP_NEEDLE": CONTINGENCY_LONG_STITCH_JUMP_NEEDLE,
"CONTINGENCY_LONG_STITCH_SEW_TO": CONTINGENCY_LONG_STITCH_SEW_TO,
}
def get_common_name_dictionary():
return {
NO_COMMAND: "NO_COMMAND",
STITCH: "STITCH",
JUMP: "JUMP",
TRIM: "TRIM",
STOP: "STOP",
END: "END",
SLOW: "SLOW",
FAST: "FAST",
COLOR_CHANGE: "COLOR_CHANGE",
NEEDLE_SET: "NEEDLE_SET",
SET_CHANGE_SEQUENCE: "SET_CHANGE_SEQUENCE",
SEQUIN_MODE: "SEQUIN_MODE",
SEQUIN_EJECT: "SEQUIN_EJECT",
SEW_TO: "SEW_TO",
NEEDLE_AT: "NEEDLE_AT",
STITCH_BREAK: "STITCH_BREAK",
SEQUENCE_BREAK: "SEQUENCE_BREAK",
COLOR_BREAK: "COLOR_BREAK",
TIE_ON: "TIE_ON",
TIE_OFF: "TIE_OFF",
FRAME_EJECT: "FRAME_EJECT",
MATRIX_TRANSLATE: "MATRIX_TRANSLATE",
MATRIX_SCALE: "MATRIX_SCALE",
MATRIX_ROTATE: "MATRIX_ROTATE",
MATRIX_SCALE_ORIGIN: "MATRIX_SCALE_ORIGIN",
MATRIX_ROTATE_ORIGIN: "MATRIX_ROTATE_ORIGIN",
MATRIX_RESET: "MATRIX_RESET",
CONTINGENCY_TIE_ON_THREE_SMALL: "CONTINGENCY_TIE_ON_THREE_SMALL",
CONTINGENCY_TIE_OFF_THREE_SMALL: "CONTINGENCY_TIE_OFF_THREE_SMALL",
CONTINGENCY_TIE_ON_NONE: "CONTINGENCY_TIE_ON_NONE",
CONTINGENCY_TIE_OFF_NONE: "CONTINGENCY_TIE_OFF_NONE",
OPTION_MAX_STITCH_LENGTH: "OPTION_MAX_STITCH_LENGTH",
OPTION_MAX_JUMP_LENGTH: "OPTION_MAX_JUMP_LENGTH",
OPTION_IMPLICIT_TRIM: "OPTION_IMPLICIT_TRIM",
OPTION_EXPLICIT_TRIM: "OPTION_EXPLICIT_TRIM",
CONTINGENCY_LONG_STITCH_NONE: "CONTINGENCY_LONG_STITCH_NONE",
CONTINGENCY_LONG_STITCH_JUMP_NEEDLE: "CONTINGENCY_LONG_STITCH_JUMP_NEEDLE",
CONTINGENCY_LONG_STITCH_SEW_TO: "CONTINGENCY_LONG_STITCH_SEW_TO"
}

Wyświetl plik

@ -1,6 +1,6 @@
import math
from .EmbConstant import *
from .EmbFunctions import *
from .EmbMatrix import EmbMatrix
@ -11,7 +11,7 @@ class Transcoder:
self.max_stitch = settings.get("max_stitch", float('inf'))
self.max_jump = settings.get("max_jump", float('inf'))
self.full_jump = settings.get("full_jump", False)
self.needle_count = settings.get("needle_count", 1)
self.needle_count = settings.get("needle_count", 5)
self.thread_change_command = settings.get("thread_change_command", COLOR_CHANGE)
strip_sequins = settings.get("strip_sequins", True)
# deprecated, use sequin_contingency.
@ -153,7 +153,7 @@ class Transcoder:
current[3] = self.source_pattern.get_thread_or_filler(thread)
if needle != -1:
current[2] = needle
# TODO: account for contingency where threadset has repeated
# TODO: account for contingency where threadset repeats
# threads and not explicit values set within the commands.
thread_index = 0

Wyświetl plik

@ -0,0 +1,121 @@
from .EmbConstant import *
def encode_thread_change(command, thread=None, needle=None, order=None):
if thread is None:
thread = 0
else:
thread += 1
thread &= 0xFF
if needle is None:
needle = 0
else:
needle += 1
needle &= 0xFF
if order is None:
order = 0
else:
order += 1
order &= 0xFF
command &= COMMAND_MASK
return command | (order << 24) | (needle << 16) | (thread << 8)
def decode_thread_change(command):
flag = command & COMMAND_MASK
thread = command & THREAD_MASK
thread >>= 8
thread -= 1
needle = command & NEEDLE_MASK
needle >>= 16
needle -= 1
order = command & ORDER_MASK
order >>= 24
order -= 1
return flag, thread, needle, order
def get_command_dictionary():
return {
"NO_COMMAND": NO_COMMAND,
"STITCH": STITCH,
"JUMP": JUMP,
"TRIM": TRIM,
"STOP": STOP,
"END": END,
"SLOW": SLOW,
"FAST": FAST,
"COLOR_CHANGE": COLOR_CHANGE,
"NEEDLE_SET": NEEDLE_SET,
"SET_CHANGE_SEQUENCE": SET_CHANGE_SEQUENCE,
"SEQUIN_MODE": SEQUIN_MODE,
"SEQUIN_EJECT": SEQUIN_EJECT,
"SEW_TO": SEW_TO,
"NEEDLE_AT": NEEDLE_AT,
"STITCH_BREAK": STITCH_BREAK,
"SEQUENCE_BREAK": SEQUENCE_BREAK,
"COLOR_BREAK": COLOR_BREAK,
"TIE_ON": TIE_ON,
"TIE_OFF": TIE_OFF,
"FRAME_EJECT": FRAME_EJECT,
"MATRIX_TRANSLATE": MATRIX_TRANSLATE,
"MATRIX_SCALE_ORIGIN": MATRIX_SCALE_ORIGIN,
"MATRIX_ROTATE_ORIGIN": MATRIX_ROTATE_ORIGIN,
"MATRIX_SCALE": MATRIX_SCALE,
"MATRIX_ROTATE": MATRIX_ROTATE,
"MATRIX_RESET": MATRIX_RESET,
"CONTINGENCY_TIE_ON_THREE_SMALL": CONTINGENCY_TIE_ON_THREE_SMALL,
"CONTINGENCY_TIE_OFF_THREE_SMALL": CONTINGENCY_TIE_OFF_THREE_SMALL,
"CONTINGENCY_TIE_ON_NONE": CONTINGENCY_TIE_ON_NONE,
"CONTINGENCY_TIE_OFF_NONE": CONTINGENCY_TIE_OFF_NONE,
"OPTION_MAX_STITCH_LENGTH": OPTION_MAX_STITCH_LENGTH,
"OPTION_MAX_JUMP_LENGTH": OPTION_MAX_JUMP_LENGTH,
"OPTION_IMPLICIT_TRIM": OPTION_IMPLICIT_TRIM,
"OPTION_EXPLICIT_TRIM": OPTION_EXPLICIT_TRIM,
"CONTINGENCY_LONG_STITCH_NONE": CONTINGENCY_LONG_STITCH_NONE,
"CONTINGENCY_LONG_STITCH_JUMP_NEEDLE": CONTINGENCY_LONG_STITCH_JUMP_NEEDLE,
"CONTINGENCY_LONG_STITCH_SEW_TO": CONTINGENCY_LONG_STITCH_SEW_TO,
}
def get_common_name_dictionary():
return {
NO_COMMAND: "NO_COMMAND",
STITCH: "STITCH",
JUMP: "JUMP",
TRIM: "TRIM",
STOP: "STOP",
END: "END",
SLOW: "SLOW",
FAST: "FAST",
COLOR_CHANGE: "COLOR_CHANGE",
NEEDLE_SET: "NEEDLE_SET",
SET_CHANGE_SEQUENCE: "SET_CHANGE_SEQUENCE",
SEQUIN_MODE: "SEQUIN_MODE",
SEQUIN_EJECT: "SEQUIN_EJECT",
SEW_TO: "SEW_TO",
NEEDLE_AT: "NEEDLE_AT",
STITCH_BREAK: "STITCH_BREAK",
SEQUENCE_BREAK: "SEQUENCE_BREAK",
COLOR_BREAK: "COLOR_BREAK",
TIE_ON: "TIE_ON",
TIE_OFF: "TIE_OFF",
FRAME_EJECT: "FRAME_EJECT",
MATRIX_TRANSLATE: "MATRIX_TRANSLATE",
MATRIX_SCALE: "MATRIX_SCALE",
MATRIX_ROTATE: "MATRIX_ROTATE",
MATRIX_SCALE_ORIGIN: "MATRIX_SCALE_ORIGIN",
MATRIX_ROTATE_ORIGIN: "MATRIX_ROTATE_ORIGIN",
MATRIX_RESET: "MATRIX_RESET",
CONTINGENCY_TIE_ON_THREE_SMALL: "CONTINGENCY_TIE_ON_THREE_SMALL",
CONTINGENCY_TIE_OFF_THREE_SMALL: "CONTINGENCY_TIE_OFF_THREE_SMALL",
CONTINGENCY_TIE_ON_NONE: "CONTINGENCY_TIE_ON_NONE",
CONTINGENCY_TIE_OFF_NONE: "CONTINGENCY_TIE_OFF_NONE",
OPTION_MAX_STITCH_LENGTH: "OPTION_MAX_STITCH_LENGTH",
OPTION_MAX_JUMP_LENGTH: "OPTION_MAX_JUMP_LENGTH",
OPTION_IMPLICIT_TRIM: "OPTION_IMPLICIT_TRIM",
OPTION_EXPLICIT_TRIM: "OPTION_EXPLICIT_TRIM",
CONTINGENCY_LONG_STITCH_NONE: "CONTINGENCY_LONG_STITCH_NONE",
CONTINGENCY_LONG_STITCH_JUMP_NEEDLE: "CONTINGENCY_LONG_STITCH_JUMP_NEEDLE",
CONTINGENCY_LONG_STITCH_SEW_TO: "CONTINGENCY_LONG_STITCH_SEW_TO"
}

Wyświetl plik

@ -1,6 +1,6 @@
from .EmbThread import EmbThread
from .EmbEncoder import Transcoder as Normalizer
from .EmbConstant import *
from .EmbFunctions import *
class EmbPattern:

Wyświetl plik

@ -30,7 +30,8 @@ def read_exp_stitches(f, out):
continue
elif control == 0x01: # Colorchange
out.color_change()
out.move(x, y)
if x != 0 or y != 0:
out.move(x, y)
continue
break # Uncaught Control
out.end()

Wyświetl plik

@ -1,4 +1,4 @@
from .EmbConstant import *
from .EmbFunctions import *
from .WriteHelper import write_int_16le, write_int_32le
THREAD_CHANGE_COMMAND = NEEDLE_SET
@ -80,7 +80,8 @@ def write(pattern, f, settings=None):
elif data == NEEDLE_SET:
decoded = decode_thread_change(stitch[2])
needle = decoded[2]
needle %= 15
if needle >= 15:
needle = (needle % 15) + 1
cmd |= 0x08
cmd += needle
f.write(bytes(bytearray([cmd, delta_y, delta_x])))

Wyświetl plik

@ -3,6 +3,7 @@ name = "pyembroidery"
# items available at the top level (e.g. pyembroidery.read)
from .PyEmbroidery import *
from .EmbConstant import *
from .EmbFunctions import *
from .EmbPattern import EmbPattern
from .EmbMatrix import EmbMatrix

Wyświetl plik

@ -0,0 +1,81 @@
from pyembroidery import *
def get_big_pattern():
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "grey")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "gold")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "ivory")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "khaki")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "oldlace")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "olive")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "pink")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "purple")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "tan")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "violet")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "white")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "salmon")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "lime")
return pattern
def get_shift_pattern():
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "grey")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "gold")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "ivory")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "khaki")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "oldlace")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "olive")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "pink")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "purple")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "tan")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "violet")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "white")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "salmon")
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 22.5)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "lime")
return pattern
def get_simple_pattern():
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
return pattern

Wyświetl plik

@ -0,0 +1,123 @@
from __future__ import print_function
import unittest
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_csv_to_u01(self):
file1 = "convert_u01.csv"
file2 = "converted_csv.u01"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->u01: ", t_pattern.stitches)
def test_convert_csv_to_csv(self):
file1 = "convert_csv.csv"
file2 = "converted_csv.csv"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->csv: ", t_pattern.stitches)
def test_convert_csv_to_exp(self):
file1 = "convert_exp.csv"
file2 = "converted_csv.exp"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->exp: ", t_pattern.stitches)
def test_convert_csv_to_pes(self):
file1 = "convert_pes.csv"
file2 = "converted_csv.pes"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->pes: ", t_pattern.stitches)
def test_convert_csv_to_jef(self):
file1 = "convert_jef.csv"
file2 = "converted_csv.jef"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->jef: ", t_pattern.stitches)
def test_convert_csv_to_pec(self):
file1 = "convert_pec.csv"
file2 = "converted_csv.pec"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->pec: ", t_pattern.stitches)
def test_convert_csv_to_vp3(self):
file1 = "convert_vp3.csv"
file2 = "converted_csv.vp3"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->vp3: ", t_pattern.stitches)
def test_convert_csv_to_dst(self):
file1 = "convert_dst.csv"
file2 = "converted_csv.dst"
write_csv(get_big_pattern(), file1)
f_pattern = read_csv(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("csv->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,122 @@
from __future__ import print_function
import unittest
from pyembroidery import *
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_dst_to_u01(self):
file1 = "convert_u01.dst"
file2 = "converted_dst.u01"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->u01: ", t_pattern.stitches)
def test_convert_dst_to_csv(self):
file1 = "convert_csv.dst"
file2 = "converted_dst.csv"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->csv: ", t_pattern.stitches)
def test_convert_dst_to_exp(self):
file1 = "convert_exp.dst"
file2 = "converted_dst.exp"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->exp: ", t_pattern.stitches)
def test_convert_dst_to_pes(self):
file1 = "convert_pes.dst"
file2 = "converted_dst.pes"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->pes: ", t_pattern.stitches)
def test_convert_dst_to_jef(self):
file1 = "convert_jef.dst"
file2 = "converted_dst.jef"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->jef: ", t_pattern.stitches)
def test_convert_dst_to_pec(self):
file1 = "convert_pec.dst"
file2 = "converted_dst.pec"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->pec: ", t_pattern.stitches)
def test_convert_dst_to_vp3(self):
file1 = "convert_vp3.dst"
file2 = "converted_dst.vp3"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->vp3: ", t_pattern.stitches)
def test_convert_dst_to_dst(self):
file1 = "convert_dst.dst"
file2 = "converted_dst.dst"
write_dst(get_big_pattern(), file1)
f_pattern = read_dst(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("dst->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,124 @@
from __future__ import print_function
import unittest
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_exp_to_u01(self):
file1 = "convert_u01.exp"
file2 = "converted_exp.u01"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->u01: ", t_pattern.stitches)
def test_convert_exp_to_csv(self):
file1 = "convert_csv.exp"
file2 = "converted_exp.csv"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->csv: ", t_pattern.stitches)
def test_convert_exp_to_exp(self):
file1 = "convert_exp.exp"
file2 = "converted_exp.exp"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->exp: ", t_pattern.stitches)
def test_convert_exp_to_pes(self):
file1 = "convert_pes.exp"
file2 = "converted_exp.pes"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->pes: ", t_pattern.stitches)
def test_convert_exp_to_jef(self):
file1 = "convert_jef.exp"
file2 = "converted_exp.jef"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->jef: ", t_pattern.stitches)
def test_convert_exp_to_pec(self):
file1 = "convert_pec.exp"
file2 = "converted_exp.pec"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
f_pattern = f_pattern.get_stable_pattern()
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->pec: ", t_pattern.stitches)
def test_convert_exp_to_vp3(self):
file1 = "convert_vp3.exp"
file2 = "converted_exp.vp3"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->vp3: ", t_pattern.stitches)
def test_convert_exp_to_dst(self):
file1 = "convert_dst.exp"
file2 = "converted_exp.dst"
write_exp(get_big_pattern(), file1)
f_pattern = read_exp(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("exp->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,123 @@
from __future__ import print_function
import unittest
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_jef_to_u01(self):
file1 = "convert_u01.jef"
file2 = "converted_jef.u01"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->u01: ", t_pattern.stitches)
def test_convert_jef_to_csv(self):
file1 = "convert_csv.jef"
file2 = "converted_jef.csv"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->csv: ", t_pattern.stitches)
def test_convert_jef_to_exp(self):
file1 = "convert_exp.jef"
file2 = "converted_jef.exp"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->exp: ", t_pattern.stitches)
def test_convert_jef_to_pes(self):
file1 = "convert_pes.jef"
file2 = "converted_jef.pes"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->pes: ", t_pattern.stitches)
def test_convert_jef_to_jef(self):
file1 = "convert_jef.jef"
file2 = "converted_jef.jef"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->jef: ", t_pattern.stitches)
def test_convert_jef_to_pec(self):
file1 = "convert_pec.jef"
file2 = "converted_jef.pec"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->pec: ", t_pattern.stitches)
def test_convert_jef_to_vp3(self):
file1 = "convert_vp3.jef"
file2 = "converted_jef.vp3"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->vp3: ", t_pattern.stitches)
def test_convert_jef_to_dst(self):
file1 = "convert_dst.jef"
file2 = "converted_jef.dst"
write_jef(get_big_pattern(), file1)
f_pattern = read_jef(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("jef->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,123 @@
from __future__ import print_function
import unittest
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_pec_to_u01(self):
file1 = "convert_u01.pec"
file2 = "converted_pec.u01"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->u01: ", t_pattern.stitches)
def test_convert_pec_to_csv(self):
file1 = "convert_csv.pec"
file2 = "converted_pec.csv"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->csv: ", t_pattern.stitches)
def test_convert_pec_to_exp(self):
file1 = "convert_exp.pec"
file2 = "converted_pec.exp"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->exp: ", t_pattern.stitches)
def test_convert_pec_to_pes(self):
file1 = "convert_pes.pec"
file2 = "converted_pec.pes"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->pes: ", t_pattern.stitches)
def test_convert_pec_to_jef(self):
file1 = "convert_jef.pec"
file2 = "converted_pec.jef"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->jef: ", t_pattern.stitches)
def test_convert_pec_to_pec(self):
file1 = "convert_pec.pec"
file2 = "converted_pec.pec"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->pec: ", t_pattern.stitches)
def test_convert_pec_to_vp3(self):
file1 = "convert_vp3.pec"
file2 = "converted_pec.vp3"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->vp3: ", t_pattern.stitches)
def test_convert_pec_to_dst(self):
file1 = "convert_dst.pec"
file2 = "converted_pec.dst"
write_pec(get_big_pattern(), file1)
f_pattern = read_pec(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pec->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,122 @@
from __future__ import print_function
import unittest
from pyembroidery import *
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_pes_to_u01(self):
file1 = "convert_u01.pes"
file2 = "converted_pes.u01"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->u01: ", t_pattern.stitches)
def test_convert_pes_to_csv(self):
file1 = "convert_csv.pes"
file2 = "converted_pes.csv"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->csv: ", t_pattern.stitches)
def test_convert_pes_to_exp(self):
file1 = "convert_exp.pes"
file2 = "converted_pes.exp"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->exp: ", t_pattern.stitches)
def test_convert_pes_to_pes(self):
file1 = "convert_pes.pes"
file2 = "converted_pes.pes"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->pes: ", t_pattern.stitches)
def test_convert_pes_to_jef(self):
file1 = "convert_jef.pes"
file2 = "converted_pes.jef"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->jef: ", t_pattern.stitches)
def test_convert_pes_to_pec(self):
file1 = "convert_pec.pes"
file2 = "converted_pes.pec"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->pec: ", t_pattern.stitches)
def test_convert_pes_to_vp3(self):
file1 = "convert_vp3.pes"
file2 = "converted_pes.vp3"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->vp3: ", t_pattern.stitches)
def test_convert_pes_to_dst(self):
file1 = "convert_dst.pes"
file2 = "converted_pes.dst"
write_pes(get_big_pattern(), file1)
f_pattern = read_pes(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,122 @@
from __future__ import print_function
import unittest
from pyembroidery import *
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_u01_to_u01(self):
file1 = "convert_u01.u01"
file2 = "converted_u01.u01"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->u01: ", t_pattern.stitches)
def test_convert_u01_to_csv(self):
file1 = "convert_csv.u01"
file2 = "converted_u01.csv"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->csv: ", t_pattern.stitches)
def test_convert_u01_to_exp(self):
file1 = "convert_exp.u01"
file2 = "converted_u01.exp"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->exp: ", t_pattern.stitches)
def test_convert_u01_to_pes(self):
file1 = "convert_pes.u01"
file2 = "converted_u01.pes"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->pes: ", t_pattern.stitches)
def test_convert_u01_to_jef(self):
file1 = "convert_jef.u01"
file2 = "converted_u01.jef"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->jef: ", t_pattern.stitches)
def test_convert_u01_to_pec(self):
file1 = "convert_pec.u01"
file2 = "converted_u01.pec"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->pec: ", t_pattern.stitches)
def test_convert_u01_to_vp3(self):
file1 = "convert_vp3.u01"
file2 = "converted_u01.vp3"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->vp3: ", t_pattern.stitches)
def test_convert_u01_to_dst(self):
file1 = "convert_dst.u01"
file2 = "converted_u01.dst"
write_u01(get_big_pattern(), file1)
f_pattern = read_u01(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("u01->dst: ", t_pattern.stitches)

Wyświetl plik

@ -0,0 +1,123 @@
from __future__ import print_function
import unittest
from pattern_for_tests import *
class TestConverts(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_convert_vp3_to_u01(self):
file1 = "convert_u01.vp3"
file2 = "converted_vp3.u01"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_u01(f_pattern, file2)
t_pattern = read_u01(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->u01: ", t_pattern.stitches)
def test_convert_vp3_to_csv(self):
file1 = "convert_csv.vp3"
file2 = "converted_vp3.csv"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_csv(f_pattern, file2)
t_pattern = read_csv(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->csv: ", t_pattern.stitches)
def test_convert_vp3_to_exp(self):
file1 = "convert_exp.vp3"
file2 = "converted_vp3.exp"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_exp(f_pattern, file2)
t_pattern = read_exp(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->exp: ", t_pattern.stitches)
def test_convert_vp3_to_pes(self):
file1 = "convert_pes.vp3"
file2 = "converted_vp3.pes"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_pes(f_pattern, file2)
t_pattern = read_pes(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->pes: ", t_pattern.stitches)
def test_convert_vp3_to_jef(self):
file1 = "convert_jef.vp3"
file2 = "converted_vp3.jef"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_jef(f_pattern, file2)
t_pattern = read_jef(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->jef: ", t_pattern.stitches)
def test_convert_vp3_to_pec(self):
file1 = "convert_pec.vp3"
file2 = "converted_vp3.pec"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_pec(f_pattern, file2)
t_pattern = read_pec(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->pec: ", t_pattern.stitches)
def test_convert_vp3_to_vp3(self):
file1 = "convert_vp3.vp3"
file2 = "converted_vp3.vp3"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_vp3(f_pattern, file2)
t_pattern = read_vp3(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->vp3: ", t_pattern.stitches)
def test_convert_vp3_to_dst(self):
file1 = "convert_dst.vp3"
file2 = "converted_vp3.dst"
write_vp3(get_big_pattern(), file1)
f_pattern = read_vp3(file1)
write_dst(f_pattern, file2)
t_pattern = read_dst(file2)
self.assertIsNotNone(t_pattern)
self.assertEqual(t_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(t_pattern.count_stitch_commands(STITCH), 16 * 5)
self.position_equals(t_pattern.stitches, 0, -1)
print("vp3->dst: ", t_pattern.stitches)

Wyświetl plik

@ -1,7 +1,8 @@
from __future__ import print_function
import unittest
from pyembroidery import *
from pattern_for_tests import *
class TestEmbpattern(unittest.TestCase):
@ -9,20 +10,12 @@ class TestEmbpattern(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_write_dst_read_dst(self):
def test_needle_count_limit(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_dst(pattern, "file.dst")
dst_pattern = read_dst("file.dst")
self.assertEqual(dst_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(dst_pattern)
self.assertEqual(dst_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(dst_pattern.stitches, 0, -1)
print("dst: ", dst_pattern.stitches)
def test_write_dst_read_dst_long_jump(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 200)], "red")
@ -45,111 +38,8 @@ class TestEmbpattern(unittest.TestCase):
self.assertEqual(dst_pattern.stitches[1][1], 100)
print("dst: ", dst_pattern.stitches)
def test_write_exp_read_exp(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_exp(pattern, "file.exp")
exp_pattern = read_exp("file.exp")
self.assertEqual(exp_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(exp_pattern)
self.assertEqual(exp_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(exp_pattern.stitches, 0, -1)
print("exp: ", exp_pattern.stitches)
def test_write_vp3_read_vp3(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_vp3(pattern, "file.vp3")
vp3_pattern = read_vp3("file.vp3")
self.assertEqual(vp3_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(vp3_pattern)
self.assertEqual(vp3_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(vp3_pattern.stitches, 0, -1)
print("vp3: ", vp3_pattern.stitches)
def test_write_jef_read_jef(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_jef(pattern, "file.jef")
jef_pattern = read_jef("file.jef")
self.assertEqual(jef_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(jef_pattern)
self.assertEqual(jef_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(jef_pattern.stitches, 0, -1)
print("jef: ", jef_pattern.stitches)
def test_write_pec_read_pec(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_pec(pattern, "file.pec")
pec_pattern = read_pec("file.pec")
self.assertEqual(pec_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(pec_pattern)
self.assertEqual(pec_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(pec_pattern.stitches, 0, -1)
print("pec: ", pec_pattern.stitches)
def test_write_pes_read_pes(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_pes(pattern, "file.pes")
pes_pattern = read_pes("file.pes")
self.assertEqual(pes_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertIsNotNone(pes_pattern)
self.assertEqual(pes_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(pes_pattern.stitches, 0, -1)
print("pes: ", pes_pattern.stitches)
def test_write_u01_read_u01(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_u01(pattern, "file.u01")
u01_pattern = read_u01("file.u01")
self.assertEqual(u01_pattern.count_stitch_commands(NEEDLE_SET), 3)
self.assertIsNotNone(u01_pattern)
self.assertEqual(u01_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(u01_pattern.stitches, 0, -1)
print("u01: ", u01_pattern.stitches)
def test_write_csv_read_csv(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_csv(pattern, "file.csv")
csv_pattern = read_csv("file.csv")
self.assertIsNotNone(csv_pattern)
self.assertEqual(csv_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertEqual(csv_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(csv_pattern.stitches, 0, -1)
print("csv: ", csv_pattern.stitches)
def test_write_csv_read_csv_raw(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_csv(pattern, "file.csv", {"encode": False})
write_csv(get_simple_pattern(), "file.csv", {"encode": False})
csv_pattern = read_csv("file.csv")
self.assertIsNotNone(csv_pattern)
self.assertEqual(csv_pattern.count_stitch_commands(COLOR_BREAK), 3)
@ -158,121 +48,17 @@ class TestEmbpattern(unittest.TestCase):
print("csv: ", csv_pattern.stitches)
def test_write_csv_read_csv_needle(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "green")
write_csv(pattern, "file2.csv", {"thread_change_command": NEEDLE_SET})
write_csv(get_simple_pattern(), "file2.csv", {"thread_change_command": NEEDLE_SET})
csv_pattern = read_csv("file2.csv")
self.assertIsNotNone(csv_pattern)
self.assertEqual(csv_pattern.count_stitch_commands(NEEDLE_SET), 3)
self.assertEqual(csv_pattern.count_stitch_commands(STITCH), 15)
print("csv: ", csv_pattern.stitches)
write_csv(pattern, "file3.csv", {"thread_change_command": COLOR_CHANGE})
def test_write_csv_read_csv_color(self):
write_csv(get_simple_pattern(), "file3.csv", {"thread_change_command": COLOR_CHANGE})
csv_pattern = read_csv("file3.csv")
self.assertEqual(csv_pattern.count_stitch_commands(COLOR_CHANGE), 2)
self.assertEqual(csv_pattern.count_stitch_commands(STITCH), 15)
self.position_equals(csv_pattern.stitches, 0, -1)
print("csv: ", csv_pattern.stitches)
def test_matrix(self):
matrix = EmbMatrix()
matrix.post_rotate(90, 100, 100)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 150)
self.assertAlmostEqual(p[1], 50)
def test_matrix_2(self):
matrix = EmbMatrix()
matrix.reset()
matrix.post_scale(2, 2, 50, 50)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 50)
self.assertAlmostEqual(p[1], 50)
p = matrix.point_in_matrix_space(25, 25)
self.assertAlmostEqual(p[0], 0)
self.assertAlmostEqual(p[1], 0)
matrix.post_rotate(45, 50, 50)
p = matrix.point_in_matrix_space(25, 25)
self.assertAlmostEqual(p[0], 50)
def test_matrix_3(self):
matrix = EmbMatrix()
matrix.reset()
matrix.post_scale(0.5, 0.5)
p = matrix.point_in_matrix_space(100, 100)
self.assertAlmostEqual(p[0], 50)
self.assertAlmostEqual(p[1], 50)
matrix.reset()
matrix.post_scale(2, 2, 100, 100)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 0)
self.assertAlmostEqual(p[1], 0)
def test_matrix_rotate(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("rotate:", pattern.stitches)
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[6][1])
self.assertAlmostEqual(pattern.stitches[10][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[10][1], pattern.stitches[12][1])
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[12][1])
write_svg(pattern, "file.svg")
def test_matrix_translate(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_TRANSLATE, -20, -40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("translate:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[12][1])
write_svg(pattern, "file2.svg")
def test_matrix_translate_rotate(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_command(MATRIX_ROTATE, -90)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "aqua")
pattern = pattern.get_normalized_pattern()
print("transrot:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertEqual(pattern.count_stitch_commands(MATRIX_ROTATE), 0)
self.assertAlmostEqual(pattern.stitches[12][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[12][1], pattern.stitches[6][1])
write_svg(pattern, "file3.svg")
def test_matrix_translate_scale(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_SCALE, 2, 2)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("transcale:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertEqual(pattern.count_stitch_commands(MATRIX_SCALE), 0)
self.assertAlmostEqual(pattern.stitches[12][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[12][1], pattern.stitches[6][1])
write_svg(pattern, "file4.svg")

108
test/test_matrix.py 100644
Wyświetl plik

@ -0,0 +1,108 @@
from __future__ import print_function
import unittest
from pyembroidery import *
class TestMatrix(unittest.TestCase):
def test_matrix(self):
matrix = EmbMatrix()
matrix.post_rotate(90, 100, 100)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 150)
self.assertAlmostEqual(p[1], 50)
def test_matrix_2(self):
matrix = EmbMatrix()
matrix.reset()
matrix.post_scale(2, 2, 50, 50)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 50)
self.assertAlmostEqual(p[1], 50)
p = matrix.point_in_matrix_space(25, 25)
self.assertAlmostEqual(p[0], 0)
self.assertAlmostEqual(p[1], 0)
matrix.post_rotate(45, 50, 50)
p = matrix.point_in_matrix_space(25, 25)
self.assertAlmostEqual(p[0], 50)
def test_matrix_3(self):
matrix = EmbMatrix()
matrix.reset()
matrix.post_scale(0.5, 0.5)
p = matrix.point_in_matrix_space(100, 100)
self.assertAlmostEqual(p[0], 50)
self.assertAlmostEqual(p[1], 50)
matrix.reset()
matrix.post_scale(2, 2, 100, 100)
p = matrix.point_in_matrix_space(50, 50)
self.assertAlmostEqual(p[0], 0)
self.assertAlmostEqual(p[1], 0)
def test_matrix_rotate(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("rotate:", pattern.stitches)
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[6][1])
self.assertAlmostEqual(pattern.stitches[10][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[10][1], pattern.stitches[12][1])
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[12][1])
write_svg(pattern, "file.svg")
def test_matrix_translate(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_TRANSLATE, -20, -40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("translate:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertAlmostEqual(pattern.stitches[4][0], pattern.stitches[12][0])
self.assertAlmostEqual(pattern.stitches[4][1], pattern.stitches[12][1])
write_svg(pattern, "file2.svg")
def test_matrix_translate_rotate(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_command(MATRIX_ROTATE, -90)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "aqua")
pattern = pattern.get_normalized_pattern()
print("transrot:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertEqual(pattern.count_stitch_commands(MATRIX_ROTATE), 0)
self.assertAlmostEqual(pattern.stitches[12][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[12][1], pattern.stitches[6][1])
write_svg(pattern, "file3.svg")
def test_matrix_translate_scale(self):
pattern = EmbPattern()
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "red")
pattern.add_command(MATRIX_TRANSLATE, 20, 40)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "blue")
pattern.add_command(MATRIX_SCALE, 2, 2)
pattern.add_block([(10, 10), (10, 110), (110, 110), (110, 10), (10, 10)], "aqua")
pattern = pattern.get_normalized_pattern()
print("transcale:", pattern.stitches)
self.assertIsNotNone(pattern.stitches)
self.assertEqual(pattern.count_stitch_commands(MATRIX_TRANSLATE), 0)
self.assertEqual(pattern.count_stitch_commands(MATRIX_SCALE), 0)
self.assertAlmostEqual(pattern.stitches[12][0], pattern.stitches[6][0])
self.assertAlmostEqual(pattern.stitches[12][1], pattern.stitches[6][1])
write_svg(pattern, "file4.svg")

Wyświetl plik

@ -0,0 +1,84 @@
from __future__ import print_function
import unittest
from pyembroidery import *
from pattern_for_tests import *
class TestWrites(unittest.TestCase):
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][:1], stitches[k][:1])
def test_write_dst_read_dst(self):
write_dst(get_big_pattern(), "file.dst")
dst_pattern = read_dst("file.dst")
self.assertEqual(dst_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(dst_pattern)
self.assertEqual(dst_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(dst_pattern.stitches, 0, -1)
print("dst: ", dst_pattern.stitches)
def test_write_exp_read_exp(self):
write_exp(get_big_pattern(), "file.exp")
exp_pattern = read_exp("file.exp")
self.assertEqual(exp_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(exp_pattern)
self.assertEqual(exp_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(exp_pattern.stitches, 0, -1)
print("exp: ", exp_pattern.stitches)
def test_write_vp3_read_vp3(self):
write_vp3(get_big_pattern(), "file.vp3")
vp3_pattern = read_vp3("file.vp3")
self.assertEqual(vp3_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(vp3_pattern)
self.assertEqual(vp3_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(vp3_pattern.stitches, 0, -1)
print("vp3: ", vp3_pattern.stitches)
def test_write_jef_read_jef(self):
write_jef(get_big_pattern(), "file.jef")
jef_pattern = read_jef("file.jef")
self.assertEqual(jef_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(jef_pattern)
self.assertEqual(jef_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(jef_pattern.stitches, 0, -1)
print("jef: ", jef_pattern.stitches)
def test_write_pec_read_pec(self):
write_pec(get_big_pattern(), "file.pec")
pec_pattern = read_pec("file.pec")
self.assertEqual(pec_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(pec_pattern)
self.assertEqual(pec_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(pec_pattern.stitches, 0, -1)
print("pec: ", pec_pattern.stitches)
def test_write_pes_read_pes(self):
write_pes(get_big_pattern(), "file.pes")
pes_pattern = read_pes("file.pes")
self.assertEqual(pes_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertIsNotNone(pes_pattern)
self.assertEqual(pes_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(pes_pattern.stitches, 0, -1)
print("pes: ", pes_pattern.stitches)
def test_write_u01_read_u01(self):
write_u01(get_big_pattern(), "file.u01")
u01_pattern = read_u01("file.u01")
self.assertEqual(u01_pattern.count_stitch_commands(NEEDLE_SET), 16)
self.assertIsNotNone(u01_pattern)
self.assertEqual(u01_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(u01_pattern.stitches, 0, -1)
print("u01: ", u01_pattern.stitches)
def test_write_csv_read_csv(self):
write_csv(get_big_pattern(), "file.csv")
csv_pattern = read_csv("file.csv")
self.assertIsNotNone(csv_pattern)
self.assertEqual(csv_pattern.count_stitch_commands(COLOR_CHANGE), 15)
self.assertEqual(csv_pattern.count_stitch_commands(STITCH), 5 * 16)
self.position_equals(csv_pattern.stitches, 0, -1)
print("csv: ", csv_pattern.stitches)