mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-19 15:50:50 +02:00
Merge pull request #11 from dylanaraps/tests
Tests: Start writing tests.
This commit is contained in:
commit
ea160a42de
@ -2,9 +2,14 @@ language: python
|
||||
python:
|
||||
- "3.6"
|
||||
|
||||
before_install:
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get install -y imagemagick
|
||||
|
||||
install:
|
||||
- pip install flake8 pylint
|
||||
|
||||
script:
|
||||
- flake8 pywal setup.py
|
||||
- pylint --ignore-imports=yes pywal setup.py
|
||||
- flake8 pywal tests setup.py
|
||||
- pylint --ignore-imports=yes pywal tests setup.py
|
||||
- python setup.py test
|
||||
|
@ -8,7 +8,9 @@ import subprocess
|
||||
|
||||
def read_file(input_file):
|
||||
"""Read colors from a file."""
|
||||
return open(input_file).read().splitlines()
|
||||
with open(input_file) as file:
|
||||
colors = file.read().splitlines()
|
||||
return colors
|
||||
|
||||
|
||||
def save_file(colors, export_file):
|
||||
|
3
setup.py
3
setup.py
@ -35,5 +35,6 @@ setup(
|
||||
entry_points={
|
||||
"console_scripts": ["wal=pywal.__main__:main"]
|
||||
},
|
||||
python_requires=">=3.6"
|
||||
python_requires=">=3.6",
|
||||
test_suite="tests",
|
||||
)
|
||||
|
4
tests/__init__.py
Executable file
4
tests/__init__.py
Executable file
@ -0,0 +1,4 @@
|
||||
"""
|
||||
wal - Generate and change colorschemes on the fly.
|
||||
Created by Dylan Araps.
|
||||
"""
|
26
tests/test_export_colors.py
Executable file
26
tests/test_export_colors.py
Executable file
@ -0,0 +1,26 @@
|
||||
"""Test export functions."""
|
||||
import unittest
|
||||
import pathlib
|
||||
|
||||
from pywal import export_colors
|
||||
from pywal import util
|
||||
|
||||
|
||||
# Import colors.
|
||||
COLORS = util.read_file("tests/test_files/test_file")
|
||||
|
||||
|
||||
class TestExportColors(unittest.TestCase):
|
||||
"""Test the export_colors functions."""
|
||||
|
||||
def test_save_colors(self):
|
||||
"""> Export colors to a file."""
|
||||
tmp_file = pathlib.Path("/tmp/test_file")
|
||||
colors = util.read_file("tests/test_files/test_file")
|
||||
export_colors.save_colors(colors, tmp_file, "plain colors")
|
||||
result = tmp_file.is_file()
|
||||
self.assertTrue(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
BIN
tests/test_files/test.jpg
Normal file
BIN
tests/test_files/test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
16
tests/test_files/test_file
Normal file
16
tests/test_files/test_file
Normal file
@ -0,0 +1,16 @@
|
||||
#363442
|
||||
#99A3B1
|
||||
#C5BDB6
|
||||
#98AEC2
|
||||
#A8B9C6
|
||||
#96C4CF
|
||||
#B7C5CC
|
||||
#C9CFD0
|
||||
#999999
|
||||
#99A3B1
|
||||
#C5BDB6
|
||||
#98AEC2
|
||||
#A8B9C6
|
||||
#96C4CF
|
||||
#B7C5CC
|
||||
#C9CFD0
|
47
tests/test_format_colors.py
Executable file
47
tests/test_format_colors.py
Executable file
@ -0,0 +1,47 @@
|
||||
"""Test format functions."""
|
||||
import unittest
|
||||
|
||||
from pywal import format_color
|
||||
from pywal import util
|
||||
|
||||
|
||||
# Import colors.
|
||||
COLORS = util.read_file("tests/test_files/test_file")
|
||||
|
||||
|
||||
class TestFormatColors(unittest.TestCase):
|
||||
"""Test the format_colors functions."""
|
||||
|
||||
def test_plain(self):
|
||||
"""> Convert colors to plain."""
|
||||
result = format_color.plain(COLORS)
|
||||
self.assertEqual(result[0], "#363442\n")
|
||||
|
||||
def test_shell(self):
|
||||
"""> Convert colors to shell variables."""
|
||||
result = format_color.shell(COLORS)
|
||||
self.assertEqual(result[0], "color0='#363442'\n")
|
||||
|
||||
def test_css(self):
|
||||
"""> Convert colors to css variables."""
|
||||
result = format_color.css(COLORS)
|
||||
self.assertEqual(result[1], "\t--color0: #363442;\n")
|
||||
|
||||
def test_scss(self):
|
||||
"""> Convert colors to scss variables."""
|
||||
result = format_color.scss(COLORS)
|
||||
self.assertEqual(result[0], "$color0: #363442;\n")
|
||||
|
||||
def test_putty(self):
|
||||
"""> Convert colors to putty theme."""
|
||||
result = format_color.putty(COLORS)
|
||||
self.assertEqual(result[2], "\"colour0\"=\"54,52,66\"\n")
|
||||
|
||||
def test_xrdb(self):
|
||||
"""> Convert colors to putty theme."""
|
||||
result = format_color.xrdb(COLORS)
|
||||
self.assertEqual(result[6], "*.color0: #363442\n*color0: #363442\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
27
tests/test_gen_colors.py
Executable file
27
tests/test_gen_colors.py
Executable file
@ -0,0 +1,27 @@
|
||||
"""Test gen functions."""
|
||||
import unittest
|
||||
|
||||
from pywal import gen_colors
|
||||
|
||||
|
||||
class TestGenColors(unittest.TestCase):
|
||||
"""Test the gen_colors functions."""
|
||||
|
||||
def test_get_img(self):
|
||||
"""> Validate image file."""
|
||||
result = gen_colors.get_image("tests/test_files/test.jpg")
|
||||
self.assertEqual(result, "tests/test_files/test.jpg")
|
||||
|
||||
def test_get_img_dir(self):
|
||||
"""> Validate image directory."""
|
||||
result = gen_colors.get_image("tests/test_files")
|
||||
self.assertEqual(result, "tests/test_files/test.jpg")
|
||||
|
||||
def test_gen_colors(self):
|
||||
"""> Generate a colorscheme."""
|
||||
result = gen_colors.gen_colors("tests/test_files/test.jpg")
|
||||
self.assertEqual(result[0], "#0F191A")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
32
tests/test_set_colors.py
Executable file
32
tests/test_set_colors.py
Executable file
@ -0,0 +1,32 @@
|
||||
"""Test set functions."""
|
||||
import unittest
|
||||
|
||||
from pywal import set_colors
|
||||
from pywal import util
|
||||
|
||||
|
||||
# Import colors.
|
||||
COLORS = util.read_file("tests/test_files/test_file")
|
||||
|
||||
|
||||
class TestSetColors(unittest.TestCase):
|
||||
"""Test the set_colors functions."""
|
||||
|
||||
def test_set_special(self):
|
||||
"""> Create special escape sequence."""
|
||||
result = set_colors.set_special(11, COLORS[0])
|
||||
self.assertEqual(result, "\x1b]11;#363442\x07")
|
||||
|
||||
def test_set_color(self):
|
||||
"""> Create color escape sequence."""
|
||||
result = set_colors.set_color(11, COLORS[0])
|
||||
self.assertEqual(result, "\033]4;11;#363442\007")
|
||||
|
||||
def test_set_grey(self):
|
||||
"""> Create special escape sequence."""
|
||||
result = set_colors.set_grey(COLORS)
|
||||
self.assertEqual(result, "#999999")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
55
tests/test_util.py
Executable file
55
tests/test_util.py
Executable file
@ -0,0 +1,55 @@
|
||||
"""Test util functions."""
|
||||
import unittest
|
||||
import pathlib
|
||||
|
||||
from pywal import util
|
||||
|
||||
|
||||
class TestUtil(unittest.TestCase):
|
||||
"""Test the util functions."""
|
||||
|
||||
def test_read_file_start(self):
|
||||
"""> Read colors from a file."""
|
||||
result = util.read_file("tests/test_files/test_file")
|
||||
self.assertEqual(result[0], "#363442")
|
||||
|
||||
def test_read_file_end(self):
|
||||
"""> Read colors from a file."""
|
||||
result = util.read_file("tests/test_files/test_file")
|
||||
self.assertEqual(result[15], "#C9CFD0")
|
||||
|
||||
def test_save_file(self):
|
||||
"""> Save colors to a file."""
|
||||
tmp_file = pathlib.Path("/tmp/test_file")
|
||||
util.save_file("Hello, world", tmp_file)
|
||||
result = tmp_file.is_file()
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_create_dir(self):
|
||||
"""> Create a directoru."""
|
||||
tmp_dir = pathlib.Path("/tmp/test_dir")
|
||||
util.create_dir(tmp_dir)
|
||||
result = tmp_dir.is_dir()
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_hex_to_rgb_black(self):
|
||||
"""> Convert #000000 to RGB."""
|
||||
result = util.hex_to_rgb("#000000")
|
||||
self.assertEqual(result, "0,0,0")
|
||||
|
||||
def test_hex_to_rgb_white(self):
|
||||
"""> Convert #FFFFFF to RGB."""
|
||||
result = util.hex_to_rgb("#FFFFFF")
|
||||
self.assertEqual(result, "255,255,255")
|
||||
|
||||
def test_hex_to_rgb_rand(self):
|
||||
"""> Convert #98AEC2 to RGB."""
|
||||
result = util.hex_to_rgb("#98AEC2")
|
||||
self.assertEqual(result, "152,174,194")
|
||||
|
||||
# Figure out how to test this.
|
||||
# def test_disown(self):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user