Skip to content

Commit

Permalink
Closes #79: Migrated to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsIch committed Sep 28, 2021
1 parent 89d67ad commit faad8e7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: build

on: [push, pull_request]

jobs:
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- run: (new-object net.webclient).DownloadFile("https://raw.githubusercontent.com/SublimeText/UnitTesting/master/sbin/github.ps1","github.ps1")
- run: |
./github.ps1 "bootstrap" -verbose
./github.ps1 "install_package_control" -verbose
./github.ps1 "run_tests" -coverage -verbose
# ./github.ps1 "run_syntax_tests" -coverage -verbose
- run: |
pip3 install coverage==4.5.4 codecov==2.0.15
codecov
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
!dependencies.json

# include important build system files
!.github/
!appveyor.yml
!gradle
!build.gradle
Expand Down
64 changes: 32 additions & 32 deletions tests/test_color_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@

from unittest import TestCase

COLOR_CONVERTER = sys.modules["Rainmeter.color.converter"]
from Rainmeter.color import converter


class IntToHexTest(TestCase):
"""Testing int to hex conversion and its corner cases."""

def test_below_lower_boundary(self):
"""Rainmeter only supports from 0 upwards."""
self.assertRaises(AssertionError, COLOR_CONVERTER.int_to_hex, -1)
self.assertRaises(AssertionError, converter.int_to_hex, -1)

def test_lower_boundary(self):
"""Zero is a corner case and should return 00."""
hex_value = COLOR_CONVERTER.int_to_hex(0)
hex_value = converter.int_to_hex(0)

self.assertEqual(hex_value, "00")

def test_default(self):
"""A random number within the boundary 0, 255 should work."""
hex_value = COLOR_CONVERTER.int_to_hex(128)
hex_value = converter.int_to_hex(128)

self.assertEqual(hex_value, "80")

def test_upper_boundary(self):
"""255 is a corner case and should return FF."""
hex_value = COLOR_CONVERTER.int_to_hex(255)
hex_value = converter.int_to_hex(255)

self.assertEqual(hex_value, "FF")

def test_over_upper_boundary(self):
"""Rainmeter only supports up to 255."""
self.assertRaises(AssertionError, COLOR_CONVERTER.int_to_hex, 256)
self.assertRaises(AssertionError, converter.int_to_hex, 256)

def test_letter_case(self):
"""We also support lower case if it is requested."""
hex_value = COLOR_CONVERTER.int_to_hex(255, letter_case=COLOR_CONVERTER.LetterCase.Lower)
hex_value = converter.int_to_hex(255, letter_case=converter.LetterCase.Lower)

self.assertEqual(hex_value, "ff")

Expand All @@ -49,37 +49,37 @@ class RGBsToHexesTest(TestCase):

def test_default_rgb_conversion(self):
"""3 valid ints should convert to 3 hexes."""
hexes = COLOR_CONVERTER.rgbs_to_hexes([128, 128, 128])
hexes = converter.rgbs_to_hexes([128, 128, 128])

self.assertEqual(hexes, ["80", "80", "80"])

def test_default_rgba_conversion(self):
"""4 valid ints should convert to 4 hexes."""
hexes = COLOR_CONVERTER.rgbs_to_hexes([128, 128, 128, 128])
hexes = converter.rgbs_to_hexes([128, 128, 128, 128])

self.assertEqual(hexes, ["80", "80", "80", "80"])

def test_invalid_rgb_low_len(self):
"""RGB are at least 3 values."""
self.assertRaises(AssertionError, COLOR_CONVERTER.rgbs_to_hexes, [128, 128])
self.assertRaises(AssertionError, converter.rgbs_to_hexes, [128, 128])

def test_invalid_rgb_high_len(self):
"""RGB are at most 4 values."""
self.assertRaises(AssertionError, COLOR_CONVERTER.rgbs_to_hexes, [128, 128, 128, 128, 128])
self.assertRaises(AssertionError, converter.rgbs_to_hexes, [128, 128, 128, 128, 128])


class HexesToStringTest(TestCase):
"""This test guerentees that a proper string conversion ."""

def test_stringing(self):
"""Default case with one spacing."""
stringed = COLOR_CONVERTER.hexes_to_string(["80", "80", "80"])
stringed = converter.hexes_to_string(["80", "80", "80"])

self.assertEqual(stringed, "808080")

def test_rgba(self):
"""RGBA case."""
stringed = COLOR_CONVERTER.hexes_to_string(["80", "80", "80", "80"])
stringed = converter.hexes_to_string(["80", "80", "80", "80"])

self.assertEqual(stringed, "80808080")

Expand All @@ -89,55 +89,55 @@ class HexToIntTest(TestCase):

def test_below_lower_boundary(self):
"""Rainmeter only supports from 0 upwards."""
self.assertRaises(AssertionError, COLOR_CONVERTER.hex_to_int, "-1")
self.assertRaises(AssertionError, converter.hex_to_int, "-1")

def test_lower_boundary(self):
"""00 is a corner case and should return 0."""
int_value = COLOR_CONVERTER.hex_to_int("00")
int_value = converter.hex_to_int("00")

self.assertEqual(int_value, 0)

def test_default(self):
"""A random number within the boundary 0, 255 should work."""
int_value = COLOR_CONVERTER.hex_to_int("80")
int_value = converter.hex_to_int("80")

self.assertEqual(int_value, 128)

def test_upper_boundary(self):
"""FF is a corner case and should return 255."""
int_value = COLOR_CONVERTER.hex_to_int("FF")
int_value = converter.hex_to_int("FF")

self.assertEqual(int_value, 255)

def test_over_upper_boundary(self):
"""Rainmeter only supports up to 255."""
self.assertRaises(AssertionError, COLOR_CONVERTER.hex_to_int, "100")
self.assertRaises(AssertionError, converter.hex_to_int, "100")


class HexesToRGBsTest(TestCase):
"""Testing Hexes to RGBs conversion and its corner cases."""

def test_default_hex_conversion(self):
"""."""
rgb = COLOR_CONVERTER.hexes_to_rgbs(["80", "80", "80"])
rgb = converter.hexes_to_rgbs(["80", "80", "80"])

self.assertEqual(rgb, [128, 128, 128])

def test_default_hexa_conversion(self):
"""4 valid hexes should convert to rgba."""
rgba = COLOR_CONVERTER.hexes_to_rgbs(["80", "80", "80", "80"])
rgba = converter.hexes_to_rgbs(["80", "80", "80", "80"])

self.assertEqual(rgba, [128, 128, 128, 128])

def test_invalid_hex_low_len(self):
"""Require at least 3 values."""
self.assertRaises(AssertionError, COLOR_CONVERTER.hexes_to_rgbs, ["FF", "FF"])
self.assertRaises(AssertionError, converter.hexes_to_rgbs, ["FF", "FF"])

def test_invalid_hex_high_len(self):
"""Require at most 4 values."""
self.assertRaises(
AssertionError,
COLOR_CONVERTER.hexes_to_rgbs,
converter.hexes_to_rgbs,
["FF", "FF", "FF", "FF", "FF"]
)

Expand All @@ -147,19 +147,19 @@ class RGBsToStringTest(TestCase):

def test_stringing(self):
"""Default Rainmeter decimal color representation."""
stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128])
stringed = converter.rgbs_to_string([128, 128, 128])

self.assertEqual(stringed, "128,128,128")

def test_with_spacing(self):
"""For people who like to space things."""
stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128], spacing=1)
stringed = converter.rgbs_to_string([128, 128, 128], spacing=1)

self.assertEqual(stringed, "128, 128, 128")

def test_with_more_spacing(self):
"""For people who like to use a lot of spacings."""
stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128], spacing=5)
stringed = converter.rgbs_to_string([128, 128, 128], spacing=5)

self.assertEqual(stringed, "128, 128, 128")

Expand All @@ -169,25 +169,25 @@ class HexAppendAlphaTest(TestCase):

def test_lower_case(self):
"""Lower case hex string adds a lower-case full alpha channel."""
stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("ff8800")
stringed = converter.convert_hex_to_hex_with_alpha("ff8800")

self.assertEqual(stringed, "ff8800ff")

def test_upper_case(self):
"""Upper case hex string adds upper-case full alpha channel."""
stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("FF8800")
stringed = converter.convert_hex_to_hex_with_alpha("FF8800")

self.assertEqual(stringed, "FF8800FF")

def test_mixed_case(self):
"""If case is not clear add upper-case full alpha channel."""
stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("Ff8800")
stringed = converter.convert_hex_to_hex_with_alpha("Ff8800")

self.assertEqual(stringed, "Ff8800FF")

def test_already_alpha(self):
"""Only add alpha channel if have only RGB."""
stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("FF8800FF")
stringed = converter.convert_hex_to_hex_with_alpha("FF8800FF")

self.assertEqual(stringed, "FF8800FF")

Expand All @@ -203,7 +203,7 @@ def test_without_alpha(self):
unless we have a value which differs from FF or 255.
The color picker will default to FF if a non alpha channel color is inputted.
"""
stringed = COLOR_CONVERTER.convert_hex_str_to_rgba_str("FFFFFFFF", False)
stringed = converter.convert_hex_str_to_rgba_str("FFFFFFFF", False)

self.assertEqual(stringed, "255,255,255")

Expand All @@ -213,7 +213,7 @@ def test_with_alpha(self):
That way even FF is written back.
"""
stringed = COLOR_CONVERTER.convert_hex_str_to_rgba_str("FFFFFFFF", True)
stringed = converter.convert_hex_str_to_rgba_str("FFFFFFFF", True)

self.assertEqual(stringed, "255,255,255,255")

Expand All @@ -224,6 +224,6 @@ def test_without_alpha_but_non_max(self):
In that case we have to translate that information too
and force add the alpha channel to the content.
"""
stringed = COLOR_CONVERTER.convert_hex_str_to_rgba_str("FFFFFF01", False)
stringed = converter.convert_hex_str_to_rgba_str("FFFFFF01", False)

self.assertEqual(stringed, "255,255,255,1")

0 comments on commit faad8e7

Please sign in to comment.