-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hugo Osvaldo Barrera
committed
Aug 18, 2020
1 parent
a5ed505
commit 77b5a4e
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
from io import BytesIO | ||
|
||
import pytest | ||
|
||
import barcode | ||
from barcode.writer import SVGWriter | ||
|
||
PATH = os.path.dirname(os.path.abspath(__file__)) | ||
TESTPATH = os.path.join(PATH, "test_outputs") | ||
|
||
|
||
def test_generate_without_output(): | ||
with pytest.raises(TypeError, match="'output' cannot be None"): | ||
barcode.generate("ean13", "123455559121112") | ||
|
||
|
||
def test_generate_with_file(): | ||
with open(f"{TESTPATH}/generate_with_file.jpeg", "wb") as f: | ||
barcode.generate("ean13", "123455559121112", output=f) | ||
|
||
|
||
def test_generate_with_filepath(): | ||
# FIXME: extension is added to the filepath even if you include it. | ||
rv = barcode.generate( | ||
"ean13", "123455559121112", output=f"{TESTPATH}/generate_with_filepath" | ||
) | ||
assert rv == os.path.abspath(f"{TESTPATH}/generate_with_filepath.svg") | ||
|
||
|
||
def test_generate_with_file_and_writer(): | ||
with open(f"{TESTPATH}/generate_with_file_and_writer.jpeg", "wb") as f: | ||
barcode.generate("ean13", "123455559121112", output=f, writer=SVGWriter()) | ||
|
||
|
||
def test_generate_with_bytesio(): | ||
bio = BytesIO() | ||
barcode.generate("ean13", "123455559121112", output=bio) | ||
assert len(bio.getvalue()) == 6127 |