How to use pywaffle - 10 common examples

To help you get started, we’ve selected a few pywaffle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_array_resize(self):
        self.assertEqual(array_resize(array=[1, 2, 3, 4, 5], length=2), [1, 2])
        self.assertEqual(array_resize(array=[1, 2, 3, 4, 5], length=2, array_len=5), [1, 2])
        self.assertEqual(array_resize(array=[1, 2], length=5, array_len=2), [1, 2, 1, 2, 1])
        # when a tuple is passed
        self.assertEqual(array_resize(array=(1, 2), length=5, array_len=2), (1, 2, 1, 2, 1))
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_array_resize(self):
        self.assertEqual(array_resize(array=[1, 2, 3, 4, 5], length=2), [1, 2])
        self.assertEqual(array_resize(array=[1, 2, 3, 4, 5], length=2, array_len=5), [1, 2])
        self.assertEqual(array_resize(array=[1, 2], length=5, array_len=2), [1, 2, 1, 2, 1])
        # when a tuple is passed
        self.assertEqual(array_resize(array=(1, 2), length=5, array_len=2), (1, 2, 1, 2, 1))
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_division(self):
        self.assertEqual(division(x=2, y=3, method="float"), 2 / 3)
        self.assertIsInstance(division(x=2, y=3, method="float"), float)

        self.assertEqual(division(x=2, y=3, method="nearest"), 1)
        self.assertIsInstance(division(x=2, y=3, method="nearest"), int)

        self.assertEqual(division(x=2, y=3, method="ceil"), 1)
        self.assertIsInstance(division(x=2, y=3, method="ceil"), int)

        self.assertEqual(division(x=2, y=3, method="floor"), 0)
        self.assertIsInstance(division(x=2, y=3, method="floor"), int)
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_division(self):
        self.assertEqual(division(x=2, y=3, method="float"), 2 / 3)
        self.assertIsInstance(division(x=2, y=3, method="float"), float)

        self.assertEqual(division(x=2, y=3, method="nearest"), 1)
        self.assertIsInstance(division(x=2, y=3, method="nearest"), int)

        self.assertEqual(division(x=2, y=3, method="ceil"), 1)
        self.assertIsInstance(division(x=2, y=3, method="ceil"), int)

        self.assertEqual(division(x=2, y=3, method="floor"), 0)
        self.assertIsInstance(division(x=2, y=3, method="floor"), int)
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_round_up_to_multiple(self):
        self.assertEqual(round_up_to_multiple(x=12, base=5), 15)
        self.assertIsInstance(round_up_to_multiple(x=12, base=5), int)
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_round_up_to_multiple(self):
        self.assertEqual(round_up_to_multiple(x=12, base=5), 15)
        self.assertIsInstance(round_up_to_multiple(x=12, base=5), int)
github gyli / PyWaffle / tests / test_utilities.py View on Github external
def test_flip_lines(self):
        self.assertEqual(
            list(flip_lines(matrix=[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)], base=3)),
            [(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0)],
        )
        self.assertEqual(
            list(flip_lines(matrix=[], base=3)),
            [],
        )
        self.assertEqual(
            list(flip_lines(matrix=[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)], base=0)),
            [],
        )
github gyli / PyWaffle / pywaffle / waffle.py View on Github external
# warnings.warn("Parameter icon_size is deprecated. Use font_size instead.", DeprecationWarning)
                self._pa["font_size"] = self._pa["icon_size"]

            # TODO: deprecating icon_set
            if self._pa["icon_set"] != "solid" and self._pa["icon_style"] == "solid":
                self._pa["icon_style"] = self._pa["icon_set"]
                warnings.warn(
                    "Parameter icon_set is deprecated and will be removed in future version. Use icon_style instead.",
                    DeprecationWarning,
                )

            # If icon_set is a string, convert it into a list of same icon. It's length is the value's length
            # 'solid' -> ['solid', 'solid', 'solid', ]
            if isinstance(self._pa["icon_style"], str):
                self._pa["icon_style"] = [self._pa["icon_style"].lower()] * self.values_len
            elif set(self._pa["icon_style"]) - set(icons.keys()):
                raise KeyError("icon_set should be one of {}".format(", ".join(icons.keys())))

            # If icons is a string, convert it into a list of same icon. It's length is the value's length
            # '\uf26e' -> ['\uf26e', '\uf26e', '\uf26e', ]
            if isinstance(self._pa["icons"], str):
                self._pa["icons"] = [self._pa["icons"]] * self.values_len

            if len(self._pa["icons"]) != self.values_len:
                raise ValueError("Length of icons doesn't match the values.")

            # Replace icon name with Unicode symbols in parameter icons
            self._pa["icons"] = [
                icons[icon_style][icon_name] for icon_name, icon_style in zip(self._pa["icons"], self._pa["icon_style"])
            ]

            # Calculate icon size based on the block size
github gyli / PyWaffle / pywaffle / waffle.py View on Github external
# warnings.warn("Parameter icon_size is deprecated. Use font_size instead.", DeprecationWarning)
                self._pa["font_size"] = self._pa["icon_size"]

            # TODO: deprecating icon_set
            if self._pa["icon_set"] != "solid" and self._pa["icon_style"] == "solid":
                self._pa["icon_style"] = self._pa["icon_set"]
                warnings.warn(
                    "Parameter icon_set is deprecated and will be removed in future version. Use icon_style instead.",
                    DeprecationWarning,
                )

            # If icon_set is a string, convert it into a list of same icon. It's length is the value's length
            # 'solid' -> ['solid', 'solid', 'solid', ]
            if isinstance(self._pa["icon_style"], str):
                self._pa["icon_style"] = [self._pa["icon_style"].lower()] * self.values_len
            elif set(self._pa["icon_style"]) - set(icons.keys()):
                raise KeyError("icon_set should be one of {}".format(", ".join(icons.keys())))

            # If icons is a string, convert it into a list of same icon. It's length is the value's length
            # '\uf26e' -> ['\uf26e', '\uf26e', '\uf26e', ]
            if isinstance(self._pa["icons"], str):
                self._pa["icons"] = [self._pa["icons"]] * self.values_len

            if len(self._pa["icons"]) != self.values_len:
                raise ValueError("Length of icons doesn't match the values.")

            # Replace icon name with Unicode symbols in parameter icons
            self._pa["icons"] = [
                icons[icon_style][icon_name] for icon_name, icon_style in zip(self._pa["icons"], self._pa["icon_style"])
            ]

            # Calculate icon size based on the block size
github gyli / PyWaffle / pywaffle / waffle.py View on Github external
self._pa["font_size"] = self._pa["icon_size"]

            # TODO: deprecating icon_set
            if self._pa["icon_set"] != "solid" and self._pa["icon_style"] == "solid":
                self._pa["icon_style"] = self._pa["icon_set"]
                warnings.warn(
                    "Parameter icon_set is deprecated and will be removed in future version. Use icon_style instead.",
                    DeprecationWarning,
                )

            # If icon_set is a string, convert it into a list of same icon. It's length is the value's length
            # 'solid' -> ['solid', 'solid', 'solid', ]
            if isinstance(self._pa["icon_style"], str):
                self._pa["icon_style"] = [self._pa["icon_style"].lower()] * self.values_len
            elif set(self._pa["icon_style"]) - set(icons.keys()):
                raise KeyError("icon_set should be one of {}".format(", ".join(icons.keys())))

            # If icons is a string, convert it into a list of same icon. It's length is the value's length
            # '\uf26e' -> ['\uf26e', '\uf26e', '\uf26e', ]
            if isinstance(self._pa["icons"], str):
                self._pa["icons"] = [self._pa["icons"]] * self.values_len

            if len(self._pa["icons"]) != self.values_len:
                raise ValueError("Length of icons doesn't match the values.")

            # Replace icon name with Unicode symbols in parameter icons
            self._pa["icons"] = [
                icons[icon_style][icon_name] for icon_name, icon_style in zip(self._pa["icons"], self._pa["icon_style"])
            ]

            # Calculate icon size based on the block size
            tx, ty = self.ax.transData.transform([(0, 0), (0, block_x_length)])