From 797c14ff273495ac221fade6bf2aa66b37158349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 20 Jan 2023 11:28:46 +0100 Subject: [PATCH] TST: add test for convert_value --- src/caoscrawler/identifiable_adapters.py | 5 +++-- unittests/test_identifiable_adapters.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index da8ebaf2..40c80154 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -27,6 +27,7 @@ from __future__ import annotations import yaml from datetime import datetime +from typing import Any from .identifiable import Identifiable import caosdb as db import logging @@ -35,14 +36,14 @@ from .utils import has_parent logger = logging.getLogger(__name__) -def convert_value(value): +def convert_value(value: Any): """ Returns a string representation of the value that is suitable to be used in the query looking for the identified record. Parameters ---------- - value : the value that shall be returned and potentially converted. + value : Any type, the value that shall be returned and potentially converted. Returns ------- diff --git a/unittests/test_identifiable_adapters.py b/unittests/test_identifiable_adapters.py index 06ea8cdf..c3b44e1c 100644 --- a/unittests/test_identifiable_adapters.py +++ b/unittests/test_identifiable_adapters.py @@ -30,7 +30,7 @@ test identifiable_adapters module import os from datetime import datetime from caoscrawler.identifiable_adapters import ( - CaosDBIdentifiableAdapter, IdentifiableAdapter) + CaosDBIdentifiableAdapter, convert_value, IdentifiableAdapter) from caoscrawler.identifiable import Identifiable import caosdb as db @@ -99,3 +99,12 @@ def test_load_from_yaml_file(): assert project_i is not None assert project_i.get_property("project_id") is not None assert project_i.get_property("title") is not None + + +def test_convert_value(): + # test that string representation of objects stay unchanged. No stripping or so. + class A(): + def __repr__(self): + return " a " + + assert convert_value(A()) == " a " -- GitLab