Skip to content

Commit 0238794

Browse files
committed
fix python tests
1 parent ef50777 commit 0238794

File tree

5 files changed

+25
-37
lines changed

5 files changed

+25
-37
lines changed

PhotoshopAPI/src/LayeredFile/LayerTypes/MaskDataMixin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ struct MaskMixin
302302
if (this->has_mask())
303303
{
304304
m_MaskData.value()->setCenterX(static_cast<float>(position.x));
305-
m_MaskData.value()->setCenterX(static_cast<float>(position.y));
305+
m_MaskData.value()->setCenterY(static_cast<float>(position.y));
306306
}
307307
}
308308

python/psapi-test/test_mask_mixin.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_add_mask(self):
1818

1919
self.assertEqual(layer.mask_width(), npy_load[0].shape[1])
2020
self.assertEqual(layer.mask_height(), npy_load[0].shape[0])
21-
self.assertEqual(layer.mask_position, psapi.geometry.Point2D(0, 0))
21+
self.assertEqual(layer.mask_position, psapi.geometry.Point2D(layer.mask_width() / 2, layer.mask_height() / 2))
2222

2323
def test_has_mask(self):
2424
npy_load = np.load(self.bin_data_path)
@@ -67,10 +67,10 @@ def test_mask_default_color(self):
6767
layer.mask_relative_to_layer = 0
6868
self.assertEqual(layer.mask_relative_to_layer, 0)
6969

70-
with self.assertRaises(ValueError):
70+
with self.assertRaises(TypeError):
7171
layer.mask_default_color = 256
7272

73-
with self.assertRaises(ValueError):
73+
with self.assertRaises(TypeError):
7474
layer.mask_default_color = -1
7575

7676
def test_mask_density(self):
@@ -83,10 +83,10 @@ def test_mask_density(self):
8383
layer.mask_density = 0
8484
self.assertEqual(layer.mask_density, 0)
8585

86-
with self.assertRaises(ValueError):
86+
with self.assertRaises(TypeError):
8787
layer.mask_density = 256
8888

89-
with self.assertRaises(ValueError):
89+
with self.assertRaises(TypeError):
9090
layer.mask_density = -1
9191

9292
def test_mask_feather(self):

python/psapi-test/test_smartobjectlayer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_get_original_image_data(self):
100100
"""
101101
file, layer = self._construct_layer_and_file("ImageStackerImage_lowres.png", psapi.enum.LinkedLayerType.data)
102102

103-
original_data = layer.original_image_data()
103+
original_data = layer.get_original_image_data()
104104
self.assertIn(0, original_data)
105105
self.assertIn(1, original_data)
106106
self.assertIn(2, original_data)

python/src/Implementation/ImageLayer.h

+12-24
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromNpArray(
3636
int width,
3737
int height,
3838
const Enum::BlendMode blend_mode,
39-
int pos_x,
40-
int pos_y,
39+
float pos_x,
40+
float pos_y,
4141
float opacity,
4242
const Enum::Compression compression,
4343
const Enum::ColorMode color_mode,
@@ -48,10 +48,6 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromNpArray(
4848
typename Layer<T>::Params params;
4949
// Do some preliminary checks since python has no concept of e.g. unsigned integers (without ctypes)
5050
// so we must ensure the range ourselves
51-
if (layer_name.size() > 255)
52-
{
53-
throw py::value_error("layer_name parameter cannot exceed a length of 255");
54-
}
5551
if (layer_mask.has_value())
5652
{
5753
if (static_cast<uint64_t>(width) * height != layer_mask.value().size())
@@ -79,8 +75,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromNpArray(
7975

8076
params.name = layer_name;
8177
params.blendmode = blend_mode;
82-
params.center_x = pos_x;
83-
params.center_y = pos_y;
78+
params.center_x = static_cast<int32_t>(pos_x);
79+
params.center_y = static_cast<int32_t>(pos_y);
8480
params.width = width;
8581
params.height = height;
8682
params.opacity = static_cast<uint8_t>(opacity * 255);
@@ -104,8 +100,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIDMapping(
104100
int width,
105101
int height,
106102
const Enum::BlendMode blend_mode,
107-
int pos_x,
108-
int pos_y,
103+
float pos_x,
104+
float pos_y,
109105
float opacity,
110106
const Enum::Compression compression,
111107
const Enum::ColorMode color_mode,
@@ -116,10 +112,6 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIDMapping(
116112
typename Layer<T>::Params params;
117113
// Do some preliminary checks since python has no concept of e.g. unsigned integers (without ctypes)
118114
// so we must ensure the range ourselves
119-
if (layer_name.size() > 255)
120-
{
121-
throw py::value_error("layer_name parameter cannot exceed a length of 255");
122-
}
123115
if (layer_mask.has_value())
124116
{
125117
if (static_cast<uint64_t>(width) * height != layer_mask.value().size())
@@ -150,8 +142,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIDMapping(
150142

151143
params.name = layer_name;
152144
params.blendmode = blend_mode;
153-
params.center_x = pos_x;
154-
params.center_y = pos_y;
145+
params.center_x = static_cast<int32_t>(pos_x);
146+
params.center_y = static_cast<int32_t>(pos_y);
155147
params.width = width;
156148
params.height = height;
157149
params.opacity = static_cast<uint8_t>(opacity * 255);
@@ -175,8 +167,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIntMapping(
175167
int width,
176168
int height,
177169
const Enum::BlendMode blend_mode,
178-
int pos_x,
179-
int pos_y,
170+
float pos_x,
171+
float pos_y,
180172
float opacity,
181173
const Enum::Compression compression,
182174
const Enum::ColorMode color_mode,
@@ -187,10 +179,6 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIntMapping(
187179
typename Layer<T>::Params params;
188180
// Do some preliminary checks since python has no concept of e.g. unsigned integers (without ctypes)
189181
// so we must ensure the range ourselves
190-
if (layer_name.size() > 255)
191-
{
192-
throw py::value_error("layer_name parameter cannot exceed a length of 255");
193-
}
194182
if (layer_mask.has_value())
195183
{
196184
if (static_cast<uint64_t>(width) * height != layer_mask.value().size())
@@ -220,8 +208,8 @@ std::shared_ptr<ImageLayer<T>> createImageLayerFromIntMapping(
220208

221209
params.name = layer_name;
222210
params.blendmode = blend_mode;
223-
params.center_x = pos_x;
224-
params.center_y = pos_y;
211+
params.center_x = static_cast<int32_t>(pos_x);
212+
params.center_y = static_cast<int32_t>(pos_y);
225213
params.width = width;
226214
params.height = height;
227215
params.opacity = static_cast<uint8_t>(opacity * 255);

python/src/Layers/DeclareImageLayer.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ void declare_image_layer(py::module& m, const std::string& extension) {
160160
:param pos_x:
161161
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
162162
For group layers this is only relevant for the layer mask and can be left out otherwise
163-
:type pos_x: int
163+
:type pos_x: float
164164
165165
:param pos_y:
166166
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
167167
For group layers this is only relevant for the layer mask and can be left out otherwise
168-
:type pos_y: int
168+
:type pos_y: float
169169
170170
:param opacity: The opacity of the layer from 0-1. Defaults to 1.0
171171
:type opacity: float
@@ -251,12 +251,12 @@ void declare_image_layer(py::module& m, const std::string& extension) {
251251
:param pos_x:
252252
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
253253
For group layers this is only relevant for the layer mask and can be left out otherwise
254-
:type pos_x: int
254+
:type pos_x: float
255255
256256
:param pos_y:
257257
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
258258
For group layers this is only relevant for the layer mask and can be left out otherwise
259-
:type pos_y: int
259+
:type pos_y: float
260260
261261
:param opacity: The opacity of the layer from 0-1. Defaults to 1.0
262262
:type opacity: float
@@ -342,12 +342,12 @@ void declare_image_layer(py::module& m, const std::string& extension) {
342342
:param pos_x:
343343
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
344344
For group layers this is only relevant for the layer mask and can be left out otherwise
345-
:type pos_x: int
345+
:type pos_x: float
346346
347347
:param pos_y:
348348
Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered.
349349
For group layers this is only relevant for the layer mask and can be left out otherwise
350-
:type pos_y: int
350+
:type pos_y: float
351351
352352
:param opacity: The opacity of the layer from 0-1. Defaults to 1.0
353353
:type opacity: float

0 commit comments

Comments
 (0)