-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from fossasia/add-colors
Add colors
- Loading branch information
Showing
30 changed files
with
222 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ The ``knittingpattern`` Module Reference | |
ParsingSpecification | ||
Prototype | ||
Row | ||
utils | ||
walk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
.. py:currentmodule:: knittingpattern.utils | ||
:py:mod:`utils` Module | ||
====================== | ||
|
||
.. automodule:: knittingpattern.utils | ||
:show-inheritance: | ||
:members: | ||
:special-members: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""This module holds the common test code. | ||
.. seealso:: `pytest good practices | ||
<https://pytest.org/latest/goodpractices.html>`__ for why this module exists. | ||
""" | ||
import os | ||
import sys | ||
|
||
# sys.path makes knittingpattern importable | ||
HERE = os.path.dirname(__file__) | ||
sys.path.insert(0, os.path.join(HERE, "../..")) | ||
__builtins__["HERE"] = HERE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,50 @@ | ||
"""This module holds the common test code. | ||
.. seealso:: `pytest good practices | ||
<https://pytest.org/latest/goodpractices.html>`__ for why this module exists. | ||
""" | ||
from pytest import fixture, raises | ||
from unittest.mock import MagicMock | ||
import os | ||
import sys | ||
import pytest | ||
|
||
# sys.path makes knittingpattern importable | ||
HERE = os.path.dirname(__file__) | ||
sys.path.insert(0, os.path.join(HERE, "../..")) | ||
|
||
__all__ = ["fixture", "raises", "MagicMock", "os", "sys", "pytest"] | ||
from knittingpattern import new_knitting_pattern | ||
import knittingpattern.KnittingPattern as KnittingPatternModule | ||
from knittingpattern.KnittingPattern import KnittingPattern | ||
from unittest.mock import Mock | ||
from test_row_instructions import a1 | ||
import knittingpattern | ||
from pytest import fixture | ||
|
||
|
||
class TestInstructionColors(object): | ||
|
||
"""Test KnittingPattern.instruction_colors.""" | ||
|
||
@fixture | ||
def unique(self, monkeypatch): | ||
mock = Mock() | ||
monkeypatch.setattr(KnittingPatternModule, "unique", mock) | ||
return mock | ||
|
||
@fixture | ||
def rows_in_knit_order(self, rows, monkeypatch): | ||
mock = Mock() | ||
monkeypatch.setattr(KnittingPattern, "rows_in_knit_order", mock) | ||
mock.return_value = rows | ||
return mock | ||
|
||
@fixture | ||
def rows(self): | ||
return [Mock(), Mock(), Mock()] | ||
|
||
@fixture | ||
def knittingpattern(self, rows): | ||
return KnittingPattern(Mock(), Mock(), Mock(), Mock()) | ||
|
||
def test_result(self, knittingpattern, unique, rows_in_knit_order): | ||
assert knittingpattern.instruction_colors == unique.return_value | ||
|
||
def test_call_arguments(self, knittingpattern, unique, rows, | ||
rows_in_knit_order): | ||
knittingpattern.instruction_colors | ||
instruction_colors = [row.instruction_colors for row in rows] | ||
unique.assert_called_once_with(instruction_colors) | ||
|
||
def test_chalotte(self, a1): | ||
assert a1.instruction_colors == [None] | ||
|
||
def test_cafe(self): | ||
pattern = knittingpattern.load_from().example("Cafe.json").first | ||
colors = ["mocha latte", "dark brown", "brown", "white", ] | ||
assert pattern.instruction_colors == colors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from knittingpattern.utils import unique | ||
import pytest | ||
|
||
|
||
class TestUniquenes(object): | ||
|
||
"""Test the function unique.""" | ||
|
||
@pytest.mark.parametrize("input,expected_result", [ | ||
([], []), ([[1, 1, 1, 1, 1]], [1]), | ||
([[1, 2, 3], [4, 3, 2, 1]], [1, 2, 3, 4]), | ||
([[None, 4], [4, 6, None]], [None, 4, 6]), | ||
([[[], [1]], [[1], [0], []]], [[], [1], [0]])]) | ||
@pytest.mark.parametrize("use_generator", [True, False]) | ||
def test_results(self, input, expected_result, use_generator): | ||
if use_generator: | ||
input = [(element for element in listing) for listing in input] | ||
result = unique(input) | ||
assert result == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""This module contains some useful functions. | ||
The functions work on the standart library or are not specific to | ||
a certain exising module. | ||
""" | ||
|
||
|
||
def unique(iterables): | ||
"""Create an iterable from the iterables that contains each element once. | ||
:return: an iterable over the iterables. Each element of the result | ||
appeard only once in the result. They are oredered by the first | ||
occurrence in the iterables. | ||
""" | ||
included_elements = [] | ||
|
||
def included(element): | ||
result = element in included_elements | ||
included_elements.append(element) | ||
return result | ||
return [element for elements in iterables for element in elements | ||
if not included(element)] | ||
|
||
|
||
__all__ = ["unique"] |