* add : BOTH_COLOR_COMPLEMENT_WARNING added.

* add : INVALID_COLOR_TYPE_ERROR added. (#134)

* add : COLOR_NOT_FOUND_WARNING added. (#134)

* cahnge : INVALID_COLOR_TYPE_ERROR -> INVALID_COLOR_TYPE_WARNING.

* change : warning -> error.

* test : tests added.

* fix : minor typo in error message fixed.

* edit : INVALID_COLOR_TYPE_ERROR edited.

* edit : BOTH_COLOR_COMPLEMENT_WARNING edited.
pull/136/head
Sadra Sabouri 2022-05-28 16:24:18 +04:30 zatwierdzone przez GitHub
rodzic fd80f431ef
commit 819792d832
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 44 dodań i 12 usunięć

Wyświetl plik

@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `INVALID_COLOR_TYPE_ERROR` error
- `COLOR_NOT_FOUND_WARNING` warning
- `BOTH_COLOR_COMPLEMENT_WARNING` warning
- `set_background` function
- `is_valid_color` function
- `color_complement` function

Wyświetl plik

@ -13,9 +13,12 @@ from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECT
from .params import Projection, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
from .params import DATA_TYPE_ERROR, CONFIG_TYPE_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
from .params import INVALID_COLOR_TYPE_ERROR
from .params import BOTH_COLOR_COMPLEMENT_WARNING, COLOR_NOT_FOUND_WARNING
from .params import DATA_SAVE_SUCCESS_MESSAGE, SEED_LOWER_BOUND, SEED_UPPER_BOUND
from .params import ELEMENTS_LIST, ARGUMENTS_LIST, OPERATORS_LIST, RANDOM_COEF_LIST
from .errors import samilaDataError, samilaPlotError, samilaConfigError
from warnings import warn
def random_equation_gen():
@ -103,6 +106,8 @@ def is_valid_color(color):
:type color: any format
:return: result as bool
"""
if color == None:
return True
try:
_ = matplotlib.colors.to_hex(color)
return True
@ -138,6 +143,7 @@ def filter_color(color, bgcolor):
color = select_color(color)
bgcolor = select_color(bgcolor)
if color == "COMPLEMENT" and bgcolor == "COMPLEMENT":
warn(BOTH_COLOR_COMPLEMENT_WARNING, RuntimeWarning)
return None, None
if color == "COMPLEMENT":
bgcolor = matplotlib.colors.to_hex(bgcolor)
@ -168,10 +174,17 @@ def select_color(color):
distance_list = list(map(lambda x: distance_calc(color, x),
VALID_COLORS))
min_distance = min(distance_list)
return VALID_COLORS[distance_list.index(min_distance)]
most_similar_color = VALID_COLORS[distance_list.index(min_distance)]
if min_distance != 0:
warn(
COLOR_NOT_FOUND_WARNING.format(
color,
most_similar_color),
RuntimeWarning)
return most_similar_color
if is_valid_color(color):
return color
return None
raise samilaPlotError(INVALID_COLOR_TYPE_ERROR)
def set_background(bgcolor, fig, ax):

Wyświetl plik

@ -39,8 +39,11 @@ CONFIG_TYPE_ERROR = "Provided config file is not supported. It should be either
CONFIG_NO_STR_FUNCTION_ERROR = "Config file can't be saved. At least one of the function1_str or function2_str is None."
PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use generate method first."
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
INVALID_COLOR_TYPE_ERROR = "Given color/bgcolor type is not supported."
MATPLOTLIB_VERSION_WARNING = "Source matplotlib version({0}) is different from yours, plots may be different."
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"
class Projection(Enum):

Wyświetl plik

@ -34,10 +34,28 @@ samila.errors.samilaDataError: Data file can't be saved. At least one of the dat
Traceback (most recent call last):
...
samila.errors.samilaPlotError: Plotting process can't be Done because data2 is empty. Use generate method first.
>>> g.generate()
>>> g.plot(color=(1, 2, 3, 4, 5))
Traceback (most recent call last):
...
samila.errors.samilaPlotError: Given color/bgcolor type is not supported.
>>> g = GenerativeImage(lambda x,y: x, lambda x,y: y)
>>> result = g.save_config()
Traceback (most recent call last):
...
samila.errors.samilaConfigError: Config file can't be saved. At least one of the function1_str or function2_str is None.
>>> from samila.functions import *
>>> select_color(2)
Traceback (most recent call last):
...
samila.errors.samilaPlotError: Given color/bgcolor type is not supported.
>>> filter_color(2,2)
Traceback (most recent call last):
...
samila.errors.samilaPlotError: Given color/bgcolor type is not supported.
>>> g.plot(color=2, bgcolor=2)
Traceback (most recent call last):
...
samila.errors.samilaPlotError: Given color/bgcolor type is not supported.
>>> os.remove('data.json')
"""

Wyświetl plik

@ -10,10 +10,6 @@ True
True
>>> is_valid_color([1,1,1,1])
True
>>> is_valid_color([1,1,1,1,1,1])
False
>>> is_valid_color("nothing")
False
>>> is_valid_color("#FFFAAF")
True
>>> color_complement("#FFFFFF")
@ -28,7 +24,6 @@ True
'#fffffa'
>>> select_color((0.1,0.1,0.1))
(0.1, 0.1, 0.1)
>>> select_color(2)
>>> select_color(None)
>>> select_color("complement")
'COMPLEMENT'
@ -67,10 +62,6 @@ False
7
>>> len(color2)
7
>>> filter_color(2,2)
(None, None)
>>> filter_color(4,3)
(None, None)
>>> filter_size(2)
>>> filter_size((2, 'test'))
>>> filter_size((2, 3.5))

Wyświetl plik

@ -134,7 +134,7 @@ False
False
>>> socket.socket = guard
>>> g.generate()
>>> g.plot(color=2,bgcolor=2)
>>> g.plot()
>>> result = g.nft_storage("")
>>> result["status"]
False

Wyświetl plik

@ -23,6 +23,10 @@ True
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):
... g.generate(start=0, stop=2, step=0.1)
>>> with warns(RuntimeWarning, match=r"It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."):
... g.plot(color='complement', bgcolor='complement')
>>> with warns(RuntimeWarning, match=r"color 'rad' not found. Replacing it with 'red'"):
... g.plot(color='rad')
>>> os.remove('data.json')
>>> os.remove('config.json')
"""