Esempio n. 1
0
class TestDigitToSwitch(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('484848')

    def test_subtleFalse_returnsZero(self):
        self.assertEqual(self.color._digit_to_switch(False), 0)

    def test_subtleTrue_returnsOne(self):
        self.assertEqual(self.color._digit_to_switch(True), 1)
Esempio n. 2
0
class TestAddHex(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('484848')

    def test_inRangePositive_shiftFullAmount(self):
        self.assertEqual(self.color._add_hex('8', 3), 'b')

    def test_inRangeNegative_shiftFullAmount(self):
        self.assertEqual(self.color._add_hex('8', -1), '7')

    def test_zeroAmount_doesntShift(self):
        self.assertEqual(self.color._add_hex('b', 0), 'b')

    def test_returnsHexValue(self):
        self.assertEqual(self.color._add_hex('8', 3), 'b')

    def test_higherThanRange_raisesErrorWithNegativeValueToCut(self):
        with self.assertRaises(DigitOutOfRange) as out_of_range_error:
            self.color._add_hex('c', 5)
        self.assertEqual(out_of_range_error.exception.msg,
                         'We had to neutralize the color -2 units.')
        self.assertEqual(out_of_range_error.exception.overflow, -2)

    def test_lowerThanRange_raisesErrorWithPositiveValueToCut(self):
        with self.assertRaises(DigitOutOfRange) as out_of_range_error:
            self.color._add_hex('5', -6)
        self.assertEqual(out_of_range_error.exception.msg,
                         'We had to neutralize the color 1 units.')
        self.assertEqual(out_of_range_error.exception.overflow, 1)
Esempio n. 3
0
class TestAmountChecker(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('484848')

    def test_positiveInRange_returnsValid(self):
        self.assertTrue(self.color._amount_in_valid_range(3))

    def test_negativeInRange_returnsValid(self):
        self.assertTrue(self.color._amount_in_valid_range(-3))

    def test_positiveOutOfRange_returnsInvalid(self):
        self.assertFalse(self.color._amount_in_valid_range(10))

    def test_negativeOutOfRange_returnsInvalid(self):
        self.assertFalse(self.color._amount_in_valid_range(-10))

    def test_rangeLimitHighOutside_returnsValid(self):
        self.assertFalse(self.color._amount_in_valid_range(8))

    def test_rangeLimitLowOutside_returnsValid(self):
        self.assertFalse(self.color._amount_in_valid_range(-8))

    def test_rangeLimitHighInside_returnsValid(self):
        self.assertTrue(self.color._amount_in_valid_range(7))

    def test_rangeLimitLowInside_returnsValid(self):
        self.assertTrue(self.color._amount_in_valid_range(0))
Esempio n. 4
0
class TestBrightener(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('888888')

    @patch('hex_color.HexColor._change_shades')
    def test_positiveAmount_callsChangeShadesWithPositiveSign(
            self, shade_changer):
        self.color.brightener(1, False)
        shade_changer.assert_called_with(1, subtle=False)

    @patch('hex_color.HexColor._change_shades')
    def test_negativeAmount_callsChangeTempWithNegativeSign(
            self, shade_changer):
        self.color.brightener(-1, False)
        shade_changer.assert_called_with(-1, subtle=False)
Esempio n. 5
0
class TestWarmer(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('484848')

    @patch('hex_color.HexColor._change_temperature')
    def test_positiveAmount_callsChangeTempWithPositiveSign(
            self, temp_changer):
        self.color.warmer(1, False)
        temp_changer.assert_called_with(1, subtle=False)

    @patch('hex_color.HexColor._change_temperature')
    def test_negativeAmount_callsChangeTempWithNegativeSign(
            self, temp_changer):
        self.color.warmer(-1, False)
        temp_changer.assert_called_with(-1, subtle=False)
Esempio n. 6
0
class TestAllColorsCanBeSwitched(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('484848')

    def test_allInRange_returnsTrue(self):
        self.assertTrue(self.color._all_colors_can_be_switched('3', '6', 'a'))

    def test_lowLimitRed_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('0', '3', 'd'))

    def test_lowLimitGreen_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('3', '0', '1'))

    def test_lowLimitBlue_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('5', '2', '0'))

    def test_highLimitRed_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('f', 'a', 'a'))

    def test_highLimitGreen_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('a', 'f', 'a'))

    def test_highLimitBlue_returnsFalse(self):
        self.assertFalse(self.color._all_colors_can_be_switched('a', '5', 'f'))
Esempio n. 7
0
 def test_halfing_saturator_out_of_range(self):
     color = HexColor('fac80b')
     expected = HexColor('fa680b')
     color.subtractive_saturator()
     self.assertEqual(color, expected)
Esempio n. 8
0
 def test_halfing_saturator_in_range(self):
     color = HexColor('5a482b')
     expected = HexColor('5a281b')
     color.subtractive_saturator()
     self.assertEqual(color, expected)
Esempio n. 9
0
 def test_retrieve_matching_hues(self):
     colors = ['2288cc', '22cc88', '8822cc', '88cc22', 'cc2288', 'cc8822']
     expected = [HexColor(color) for color in colors]
     self.palette.retrieve_matching_hues()
     self.assertEqual(self.palette.colors, expected)
Esempio n. 10
0
 def test_palette_from_hex_colors(self):
     color1 = HexColor('111')
     color2 = HexColor('222')
     res = str(Palette(color1, color2))
     self.assertEqual(res, 'Palette: #111111 #222222')
Esempio n. 11
0
 def test_palette_print(self):
     color1 = HexColor('111')
     color2 = HexColor('222')
     color3 = HexColor('333')
     res = str(Palette(color1, color2, color3))
     self.assertEqual(res, 'Palette: #111111 #222222 #333333')
Esempio n. 12
0
 def test__get_hex_name_returns_seven_chars(self):
     result = HexColor('012345')
     self.assertEqual(len(str(result)), 7)
Esempio n. 13
0
 def test_lowLimitInRange_shiftsBright(self):
     result = HexColor('11c')._change_shades(-5, subtle=True)
     self.assertEqual(result, '1010cb')
Esempio n. 14
0
 def test_blueLastNotInRange_cutMovementOnRedGreenToo(self):
     result = HexColor('55c')._change_shades(5, subtle=True)
     self.assertEqual(result, '5858cf')
Esempio n. 15
0
 def test_positiveNotAllInRange_cutMovement(self):
     result = HexColor('83888a')._change_shades(4, subtle=True)
     self.assertEqual(result, '878c8e')
Esempio n. 16
0
 def test_negativeNotAllInRange_cutMovement(self):
     result = HexColor('3888c8')._change_shades(-9, subtle=False)
     self.assertEqual(result, '085898')
Esempio n. 17
0
 def setUp(self):
     self.color = HexColor('888888')
Esempio n. 18
0
class TestChangeShades(unittest.TestCase):
    def setUp(self):
        self.color = HexColor('888888')

    @patch('hex_color.HexColor._digit_to_switch')
    @patch('hex_color.HexColor._all_colors_can_be_switched', return_value=True)
    def test_validAmount_callsDigitsToSwitch(self, amount_checker, get_digit):
        self.color._change_shades(1, subtle=False)
        get_digit.assert_called_with(False)

    @patch('hex_color.HexColor._add_hex')
    @patch('hex_color.HexColor._digit_to_switch', return_value=0)
    @patch('hex_color.HexColor._all_colors_can_be_switched', return_value=True)
    def test_validAmount_callsAddHex(self, amount_checker, get_digit, add_hex):
        self.color._change_shades(-1, subtle=False)
        self.assertEqual(add_hex.call_count, 3)

    @patch('hex_color.HexColor._add_hex')
    def test_allInRange_moveAllValuesFullRange(self, add_hex):
        self.color._change_shades(1, subtle=False)
        self.assertEqual(add_hex.call_count, 3)

    def test_zeroAmount_doesntShift(self):
        result = self.color._change_shades(0, subtle=False)
        self.assertEqual(result, '888888')

    def test_subtleTrue_shiftsOnesDigit(self):
        result = self.color._change_shades(4, subtle=True)
        self.assertEqual(result, '8c8c8c')

    def test_subtleFalse_shiftsSixteensDigit(self):
        result = self.color._change_shades(-5, subtle=False)
        self.assertEqual(result, '383838')

    def test_returnsHexValue(self):
        result = self.color._change_shades(3, subtle=True)
        self.assertEqual(result, '8b8b8b')

    def test_negativeNotAllInRange_cutMovement(self):
        result = HexColor('3888c8')._change_shades(-9, subtle=False)
        self.assertEqual(result, '085898')

    def test_positiveNotAllInRange_cutMovement(self):
        result = HexColor('83888a')._change_shades(4, subtle=True)
        self.assertEqual(result, '878c8e')

    def test_blueLastNotInRange_cutMovementOnRedGreenToo(self):
        result = HexColor('55c')._change_shades(5, subtle=True)
        self.assertEqual(result, '5858cf')

    def test_lowLimitInRange_shiftsBright(self):
        result = HexColor('11c')._change_shades(-5, subtle=True)
        self.assertEqual(result, '1010cb')

    def test_lowLimitOutRange_cutMovement(self):
        result = HexColor('15c')._change_shades(-2, subtle=True)
        self.assertEqual(result, '1054cb')

    def test_highLimitInRange_shiftsBright(self):
        result = HexColor('dcc')._change_shades(2, subtle=True)
        self.assertEqual(result, 'dfcece')

    def test_highLimitOutRange_doesntShiftBright(self):
        result = HexColor('ecc')._change_shades(5, subtle=True)
        self.assertEqual(result, 'efcdcd')
Esempio n. 19
0
 def test_lowLimitOutRange_cutMovement(self):
     result = HexColor('15c')._change_shades(-2, subtle=True)
     self.assertEqual(result, '1054cb')
Esempio n. 20
0
 def test__get_channels_from_paired_channels(self):
     result = HexColor('012345')
     self.assertEqual(str(result), '#012345')
Esempio n. 21
0
 def setUp(self):
     self.color = HexColor('484848')
Esempio n. 22
0
 def test_highLimitInRange_shiftsBright(self):
     result = HexColor('dcc')._change_shades(2, subtle=True)
     self.assertEqual(result, 'dfcece')
Esempio n. 23
0
 def test_palette_from_hex_colors_and_values_mixed(self):
     color1 = '111'
     color2 = HexColor('222')
     res = str(Palette(color1, color2))
     self.assertEqual(res, 'Palette: #111111 #222222')
Esempio n. 24
0
 def test_highLimitOutRange_doesntShiftBright(self):
     result = HexColor('ecc')._change_shades(5, subtle=True)
     self.assertEqual(result, 'efcdcd')
Esempio n. 25
0
 def test_palette_repr(self):
     color1 = HexColor('111')
     color2 = HexColor('222')
     color3 = HexColor('333')
     res = repr(Palette(color1, color2, color3))
     self.assertEqual(res, '<Palette HexColors: #111111 #222222 #333333>')
Esempio n. 26
0
 def test_additive_saturator_in_range(self):
     color = HexColor('5a483b')
     expected = HexColor('aa483b')
     color.additive_saturator(5)
     self.assertEqual(color, expected)
Esempio n. 27
0
 def setUp(self):
     self.color = HexColor('28c')
     self.palette = PaletteFromColor(self.color)
Esempio n. 28
0
 def test_doubling_saturator_out_of_range(self):
     color = HexColor('aa483b')
     expected = HexColor('fa483b')
     color.additive_saturator()
     self.assertEqual(color, expected)
Esempio n. 29
0
def main():

    # Command line script to make a working example in the main.
    # If you're a recruiter looking for good code practices, avoid this example main and please check the tests and the palette/hex_color modules.
    # Validations in progress. This main is not tested either. Only the modules.

    print(
        "JUST A WARN: This script is gonna open in your browser the EXTERNAL web page colorcombos.com in order to show you the colors. You can close the program to avoid it or follow the rules to continue."
    )
    colorValue = input('Insert a hex color value...')
    color = HexColor(colorValue)
    print(f"{color} is nice!")

    ComboTest(Palette(color)).show()
    print(f"Let's create a Palette from {color}.")
    input('Press enter to continue...')
    palette = PaletteFromColor(color)
    palette.retrieve_matching_hues()

    ComboTest(palette).show()

    print("- " * 10)
    print(f"""Now let's get from your color, three matching ones.
    You'll get your color and two matching more, towards the selected hue.
    
    (If you repeat a channel value, you're going to get less than three, because of the permutation algorithm.)
    
    Choose towards which tone you want to go:
    For example, if you want two blue-ish colors matching yours, write 'b'.
    
    The validation is in progress, so keep in mind that the accepted values are:
    r, g and b (no caps).
    """)

    toneValue = input('Insert r, g or b...')

    trio = TrioFromColor(color)
    trio.choose_hue(toneValue)

    ComboTest(trio).show()

    print("- " * 10)
    print(
        f"""What about being more precise? Let's create a duo from your color.
    You'll get your color and a matching one towards the selected hues.
    
    (If you repeat a channel value, you may get only one, because of the permutation algorithm.)
    
    For example, if you want two red-greenish colors matching yours, write 'rg'.
    The validation is in progress, so keep in mind that the accepted values are:
    rb, gr, gb, br, bg, rg (no caps nor spaces, but they can be in any order).  
    """)

    toneValues = input('Insert two color initials... E.g.: rb')

    duet = DuetFromColor(color)
    duet.choose_hue(toneValues)
    ComboTest(duet).show()

    print("= " * 10)
    print(f"""Now let's play modifying your selected color:
    If we upper the highest channel we get a lighter more saturated color.
    If amount negative, dulls the color.  
    
    Raises an error if the value is > 8. ANd if one of the values reach the max/min, the other one stops in order to get a matching color and not a random one.
    """)

    amountSatChange = input(
        'Insert the amount to change the saturation... E.g.: -4')

    new_color = HexColor(colorValue)
    new_color.additive_saturator(int(amountSatChange))
    satPalette = Palette(color, new_color)
    ComboTest(satPalette).show()
Esempio n. 30
0
 def test_subtractive_saturator_out_of_range(self):
     color = HexColor('5a482b')
     expected = HexColor('5a080b')
     color.subtractive_saturator(10)
     self.assertEqual(color, expected)