2018-05-09 09:50:13 +02:00
|
|
|
# coding: utf-8
|
2018-05-07 11:20:11 +02:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from yoga.model import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class Test_model_helpers(object):
|
|
|
|
def test_normalize_path(self):
|
2021-03-29 13:57:02 +02:00
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("./images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path(".\\images\\texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("./images\\texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path(".\\images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("../images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("..\\images\\texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("./images/subfolder/../texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("./images/sub1\\sub2/../../texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("./images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("/images/texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("C:\\images\\texture.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "images/texture.png"
|
|
|
|
)
|
2018-05-07 11:20:11 +02:00
|
|
|
|
2021-03-29 13:57:02 +02:00
|
|
|
assert (
|
2021-06-23 11:17:26 +02:00
|
|
|
helpers.normalize_path("somE_valid-caractères of files.png")
|
2021-03-29 13:57:02 +02:00
|
|
|
== "some_valid-caracteres of files.png"
|
|
|
|
)
|
2018-05-07 11:20:11 +02:00
|
|
|
|
2018-05-15 10:58:40 +02:00
|
|
|
def test_normalize_paths(self):
|
2021-03-29 13:57:02 +02:00
|
|
|
paths = helpers.normalize_paths(
|
|
|
|
{
|
|
|
|
"./images\\texture-1.png": True,
|
|
|
|
"images/texture-2.png": True,
|
|
|
|
}
|
|
|
|
)
|
2018-05-15 10:58:40 +02:00
|
|
|
assert "images/texture-1.png" in paths
|
|
|
|
assert "images/texture-2.png" in paths
|
2018-05-07 11:20:11 +02:00
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2021-03-29 13:57:02 +02:00
|
|
|
helpers.normalize_paths(
|
|
|
|
{
|
|
|
|
"images/texture.png": True,
|
|
|
|
"./images/texture.png": True,
|
|
|
|
}
|
|
|
|
)
|
2018-05-07 11:20:11 +02:00
|
|
|
|
2018-05-15 10:58:40 +02:00
|
|
|
def test_find_valid_path(self):
|
2021-03-29 13:57:02 +02:00
|
|
|
paths = dict(
|
|
|
|
{
|
|
|
|
"images/texture.png": True,
|
|
|
|
"images/texture.jpg": True,
|
|
|
|
"other_images/texture.jpg": True,
|
|
|
|
"texture.gif": True,
|
|
|
|
}
|
|
|
|
)
|
2018-05-07 11:20:11 +02:00
|
|
|
|
2021-03-29 13:57:02 +02:00
|
|
|
assert (
|
|
|
|
helpers.find_valid_path("images/texture.png", paths)
|
|
|
|
== "images/texture.png"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
helpers.find_valid_path("images/texture.jpg", paths)
|
|
|
|
== "images/texture.jpg"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
helpers.find_valid_path("texture.png", paths)
|
|
|
|
== "images/texture.png"
|
|
|
|
)
|
2018-05-07 11:20:11 +02:00
|
|
|
|
2021-03-29 13:57:02 +02:00
|
|
|
assert helpers.find_valid_path("texture.jpg", paths) is None
|
|
|
|
assert helpers.find_valid_path("non-existing.png", paths) is None
|
|
|
|
assert helpers.find_valid_path("exture.png", paths) is None
|