예제 #1
0
def test_swapdict():
    assert {1:'a'} == tools.swapdict({'a':1})

    # if the are non-unique values, we can catch the error or no:
    try:
        tools.swapdict({'a':1, 'b':1})
        assert False
    except:
        assert True
    tools.swapdict({'a':1, 'b':1}, check_ambiguity=False)
예제 #2
0
def test_swapdict():
    assert {1: 'a'} == tools.swapdict({'a': 1})

    # if the are non-unique values, we can catch the error or no:
    try:
        tools.swapdict({'a': 1, 'b': 1})
        assert False
    except:
        assert True
    tools.swapdict({'a': 1, 'b': 1}, check_ambiguity=False)
예제 #3
0
 def _set_hex(self, value):
     # hex is an approximation made of 255 bits so do not define rgb here
     if self.is_valid_hex_color(value):
         value = self.get_standard_hex_color(value)
         self._hex = value
         if self._hex in self.colors.values():
             self._name = swapdict(self.colors, check_ambiguity=False)[self._hex]
         else:
             self._name = "undefined"
         self._rgb = hex2rgb(self._hex, normalise=True)
     else:
         # just to warn the user
         self.get_standard_hex_color(value)