Skip to content

Commit

Permalink
Minor edits on line functionality (#285)
Browse files Browse the repository at this point in the history
* fix : merging error messages in `line` function.

* test : tests for errors added for `lprint` and `line` function.

* update : README.md updated.

* update : error messages name fixed.

* update : readme updated (Sepand's comment.).

* fix : minor issues in readme fixed.

* fix : readme fixed.

---------

Co-authored-by: sepandhaghighi <[email protected]>
  • Loading branch information
sadrasabouri and sepandhaghighi authored Nov 14, 2024
1 parent ae31dd9 commit 5adf215
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,32 @@ Filename: test.txt
* Note2 : Use `NON_ASCII_FONTS` to access all Non-ASCII fonts name list (new in `Version 4.4`)
* Note3 : Use `ASCII_FONTS` to access all ASCII fonts name list (new in `Version 5.7`)

### Line

#### 1. lprint

This function prints a grid (`length` by `height`) of any given character.
```pycon
>>> lprint(length=15, height=2, char="*")
***************
***************
```

* Note1: This feature has been added since `Version 6.4`
* Note2: The default values are `length=15`, `height=1`, `char='#'`

#### 2. line

This function returns a grid (`length` by `height`) of any given character as `str` in normal mode and raise `artError` in exception.
```pycon
>>> line(length=15, height=2, char="*")
'***************\n***************'
```

* Note1: This feature has been added since `Version 6.4`
* Note2: The default values are `length=15`, `height=1`, `char='#'`


### Decoration

⚠️ Some environments don't support all decorations
Expand Down
15 changes: 5 additions & 10 deletions art/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .params import DECORATION_TYPE_ERROR, TEXT_TYPE_ERROR, FONT_TYPE_ERROR, CHR_IGNORE_TYPE_ERROR, FILE_TYPE_ERROR
from .params import PRINT_STATUS_TYPE_ERROR, OVERWRITE_TYPE_ERROR, SEP_TYPE_ERROR, SPACE_TYPE_ERROR
from .params import DETAILED_RETURN_TYPE_ERROR, ART_TYPE_ERROR, NUMBER_TYPE_ERROR, ART_NAME_ERROR
from .params import LENGTH_TYPE_ERROR, LENGTH_RANGE_ERROR, HEIGHT_TYPE_ERROR, HEIGHT_RANGE_ERROR, CHAR_TYPE_ERROR
from .params import LINE_LENGTH_ERROR, LINE_HEIGHT_ERROR, CHAR_TYPE_ERROR
from .errors import artError


Expand Down Expand Up @@ -272,18 +272,13 @@ def line(length=15, height=1, char='#'):
:type char: str
:return: generated grid as str
"""
if not isinstance(length, int):
raise artError(LENGTH_TYPE_ERROR)
if not isinstance(height, int):
raise artError(HEIGHT_TYPE_ERROR)
if not isinstance(length, int) or length < 1:
raise artError(LINE_LENGTH_ERROR)
if not isinstance(height, int) or height < 1:
raise artError(LINE_HEIGHT_ERROR)
if not isinstance(char, str):
raise artError(CHAR_TYPE_ERROR)

if length < 1:
raise artError(LENGTH_RANGE_ERROR)
if height < 1:
raise artError(HEIGHT_RANGE_ERROR)

line_str = char * length
return "\n".join([line_str] * height)

Expand Down
6 changes: 2 additions & 4 deletions art/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
FONT_ENVIRONMENT_WARNING = "[Warning] '{0}' font is not printable in this environment."
FONT_OR_DECOR_ENVIRONMENT_WARNING = "[Warning] '{0}' font or '{1}' decoration is not printable in this environment."
PACKAGE_LOAD_WARNING = "[Warning] There is a problem loading the package 'coverage'."
HEIGHT_TYPE_ERROR = "The 'height' type must be int."
HEIGHT_RANGE_ERROR = "The 'height' parameter should be >= 1."
LENGTH_TYPE_ERROR = "The 'length' type must be int."
LENGTH_RANGE_ERROR = "The 'length' parameter should be >= 1."
LINE_LENGTH_ERROR = "The 'length' must be an int higher than 0."
LINE_HEIGHT_ERROR = "The 'height' must be an int higher than 0."
CHAR_TYPE_ERROR = "The 'char' type must be str."

CLI_HELP = """
Expand Down
14 changes: 14 additions & 0 deletions art/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@
>>> lprint(length=15, height=2, char="*")
***************
***************
>>> lprint(length=0, height=1, char="#")
The 'length' must be an int higher than 0.
>>> line(length=10, height=1, char="#")
'##########'
>>> line(length=15, height=2, char="*")
'***************\n***************'
>>> line(length=0, height=1, char="#")
Traceback (most recent call last):
...
art.art.artError: The 'length' must be an int higher than 0.
>>> line(length=15, height='test', char="#")
Traceback (most recent call last):
...
art.art.artError: The 'height' must be an int higher than 0.
>>> line(length=15, height=2, char=4)
Traceback (most recent call last):
...
art.art.artError: The 'char' type must be str.
>>> tprint("\t\t2","block")
<BLANKLINE>
.----------------.
Expand Down

0 comments on commit 5adf215

Please sign in to comment.