From cd5d5136306c2a135e54f7129331dcd647e26dc7 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 12:56:38 -0400 Subject: [PATCH 01/25] ADD: added _validate_only_one_iterable staticmethod --- spyrograph/_trochoid.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index f842a0c..f0f691a 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -513,6 +513,11 @@ def create_range( )) return shapes + @staticmethod + def _validate_only_one_iterable(*args) -> bool: + """Return validation check that only one argument passed to create_range is an iterable""" + inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) + @staticmethod def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: """Return list of numbers from given input parameter""" From 7091caa207d5b5f36711b67a043e9b45ffccf7ea Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 12:57:23 -0400 Subject: [PATCH 02/25] ADD: added ValueError raise if more than one iterable passed to _validate_only_one_iterable --- spyrograph/_trochoid.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index f0f691a..88165cc 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -517,6 +517,8 @@ def create_range( def _validate_only_one_iterable(*args) -> bool: """Return validation check that only one argument passed to create_range is an iterable""" inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) + if inputs[True] > 1: + raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") @staticmethod def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: From 06c2465c761a66a0ffa6c1a11e83885ddfd971ba Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 12:58:23 -0400 Subject: [PATCH 03/25] ADD: added _validate_only_one_iterable as the call in Trochoid create_range --- spyrograph/_trochoid.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index 88165cc..21bfdd6 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -490,13 +490,7 @@ def create_range( 3 """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme - inputs = collections.Counter([ - isinstance(R, collections.abc.Iterable), - isinstance(r, collections.abc.Iterable), - isinstance(d, collections.abc.Iterable) - ]) - if inputs[True] > 1: - raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") + cls._validate_only_one_iterable(R, r, d) R_arr = cls._set_int_to_list(R) r_arr = cls._set_int_to_list(r) d_arr = cls._set_int_to_list(d) From a9ffdde565e273106a84589249020827d37db3be Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 12:59:25 -0400 Subject: [PATCH 04/25] MODIFY: refactored create_range in _Cycloid to use inherited _validate_only_one_iterable --- spyrograph/_cycloid.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index 6e117a7..a0a151e 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -172,12 +172,7 @@ def create_range( Custom origin to center the shapes at. Default is (0,0) """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme - inputs = collections.Counter([ - isinstance(R, collections.abc.Iterable), - isinstance(r, collections.abc.Iterable) - ]) - if inputs[True] > 1: - raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") + cls._validate_only_one_iterable(R, r) R_arr = cls._set_int_to_list(R) r_arr = cls._set_int_to_list(r) From b0f809052b926ea580f53542a49fa235b0b68d46 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:06:03 -0400 Subject: [PATCH 05/25] ADD: added itertools import --- spyrograph/_trochoid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index 21bfdd6..695bdf3 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -10,6 +10,7 @@ import time from abc import ABC, abstractmethod import collections +import itertools import numpy as np From 1191f9071253153f66c72c80a3a6033a4444f4c0 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:09:41 -0400 Subject: [PATCH 06/25] MODIFY: refactored create_range to use _get_products_of_inputs --- spyrograph/_trochoid.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index 695bdf3..ba57506 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -492,9 +492,7 @@ def create_range( """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme cls._validate_only_one_iterable(R, r, d) - R_arr = cls._set_int_to_list(R) - r_arr = cls._set_int_to_list(r) - d_arr = cls._set_int_to_list(d) + input_params = cls._get_products_of_inputs(R, r, d) # TODO: this is fairly ugly, need to come up with better way of handling # this @@ -508,6 +506,12 @@ def create_range( )) return shapes + def _get_products_of_inputs(self, *args) -> Tuple[Number]: + """Return a list of tuples that contains all of the input arguments""" + list_of_lists = [self._set_int_to_list(el) for el in args] + product = itertools.product(*list_of_lists) + return product + @staticmethod def _validate_only_one_iterable(*args) -> bool: """Return validation check that only one argument passed to create_range is an iterable""" From 859f738831230bd439e0a9cbf31f749de4c43905 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:10:31 -0400 Subject: [PATCH 07/25] MODIFY: modified create_range behavior to use new method --- spyrograph/_trochoid.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index ba57506..8961ded 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -497,13 +497,11 @@ def create_range( # TODO: this is fairly ugly, need to come up with better way of handling # this shapes = [] - for R in R_arr: - for r in r_arr: - for d in d_arr: - shapes.append(cls( - R, r, d, thetas, theta_start, theta_stop, theta_step, - origin - )) + for R, r, d in input_params: + shapes.append(cls( + R, r, d, thetas, theta_start, theta_stop, theta_step, + origin + )) return shapes def _get_products_of_inputs(self, *args) -> Tuple[Number]: From 7c44738f63aaac313be2b4783d8c762ce529b3e3 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:12:01 -0400 Subject: [PATCH 08/25] MODIFY: moved staticmethods out of the class --- spyrograph/_trochoid.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index 8961ded..e71988b 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -504,26 +504,6 @@ def create_range( )) return shapes - def _get_products_of_inputs(self, *args) -> Tuple[Number]: - """Return a list of tuples that contains all of the input arguments""" - list_of_lists = [self._set_int_to_list(el) for el in args] - product = itertools.product(*list_of_lists) - return product - - @staticmethod - def _validate_only_one_iterable(*args) -> bool: - """Return validation check that only one argument passed to create_range is an iterable""" - inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) - if inputs[True] > 1: - raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") - - @staticmethod - def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: - """Return list of numbers from given input parameter""" - if isinstance(input_val, Number): - input_val = [input_val] - return input_val - def _show_full_path(self, pre_draw_turtle: "turtle.Turtle") -> None: """Draw the full path prior to tracing""" # pylint: disable=no-member, unused-variable @@ -704,3 +684,21 @@ def __repr__(self) -> str: else: thetas_str = f"[{self.thetas[0]}, {self.thetas[1]}, ... {self.thetas[-1]}]" return(f"{self.__class__.__name__}(R={self.R}, r={self.r}, d={self.d}, thetas={thetas_str}, origin=({self.origin[0]},{self.origin[1]}))") + +def _get_products_of_inputs(self, *args) -> Tuple[Number]: + """Return a list of tuples that contains all of the input arguments""" + list_of_lists = [self._set_int_to_list(el) for el in args] + product = itertools.product(*list_of_lists) + return product + +def _validate_only_one_iterable(*args) -> bool: + """Return validation check that only one argument passed to create_range is an iterable""" + inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) + if inputs[True] > 1: + raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") + +def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: + """Return list of numbers from given input parameter""" + if isinstance(input_val, Number): + input_val = [input_val] + return input_val \ No newline at end of file From 35bed43ba7f07d4a5efa6fe27568c236ba0e63f2 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:13:00 -0400 Subject: [PATCH 09/25] REMOVE: removed self and cls references to funcs that used to be staticmethods --- spyrograph/_trochoid.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index e71988b..e40f59e 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -491,8 +491,8 @@ def create_range( 3 """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme - cls._validate_only_one_iterable(R, r, d) - input_params = cls._get_products_of_inputs(R, r, d) + _validate_only_one_iterable(R, r, d) + input_params = _get_products_of_inputs(R, r, d) # TODO: this is fairly ugly, need to come up with better way of handling # this @@ -687,7 +687,7 @@ def __repr__(self) -> str: def _get_products_of_inputs(self, *args) -> Tuple[Number]: """Return a list of tuples that contains all of the input arguments""" - list_of_lists = [self._set_int_to_list(el) for el in args] + list_of_lists = [_set_int_to_list(el) for el in args] product = itertools.product(*list_of_lists) return product From f7d49e433db0a7e9a3b5383ce2a783f52f708c7f Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:15:11 -0400 Subject: [PATCH 10/25] ADD: added _misc module for moving some functionality into --- spyrograph/_misc.py | 19 +++++++++++++++++++ spyrograph/_trochoid.py | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 spyrograph/_misc.py diff --git a/spyrograph/_misc.py b/spyrograph/_misc.py new file mode 100644 index 0000000..6dad6bc --- /dev/null +++ b/spyrograph/_misc.py @@ -0,0 +1,19 @@ + + +def _get_products_of_inputs(self, *args) -> Tuple[Number]: + """Return a list of tuples that contains all of the input arguments""" + list_of_lists = [_set_int_to_list(el) for el in args] + product = itertools.product(*list_of_lists) + return product + +def _validate_only_one_iterable(*args) -> bool: + """Return validation check that only one argument passed to create_range is an iterable""" + inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) + if inputs[True] > 1: + raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") + +def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: + """Return list of numbers from given input parameter""" + if isinstance(input_val, Number): + input_val = [input_val] + return input_val \ No newline at end of file diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index e40f59e..a35a330 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -684,21 +684,3 @@ def __repr__(self) -> str: else: thetas_str = f"[{self.thetas[0]}, {self.thetas[1]}, ... {self.thetas[-1]}]" return(f"{self.__class__.__name__}(R={self.R}, r={self.r}, d={self.d}, thetas={thetas_str}, origin=({self.origin[0]},{self.origin[1]}))") - -def _get_products_of_inputs(self, *args) -> Tuple[Number]: - """Return a list of tuples that contains all of the input arguments""" - list_of_lists = [_set_int_to_list(el) for el in args] - product = itertools.product(*list_of_lists) - return product - -def _validate_only_one_iterable(*args) -> bool: - """Return validation check that only one argument passed to create_range is an iterable""" - inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) - if inputs[True] > 1: - raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") - -def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: - """Return list of numbers from given input parameter""" - if isinstance(input_val, Number): - input_val = [input_val] - return input_val \ No newline at end of file From 73e679e163be50a294129670573a9dcbf8c07120 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:16:11 -0400 Subject: [PATCH 11/25] ADD: added relevant imports --- spyrograph/_misc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spyrograph/_misc.py b/spyrograph/_misc.py index 6dad6bc..d3635c3 100644 --- a/spyrograph/_misc.py +++ b/spyrograph/_misc.py @@ -1,4 +1,7 @@ - +import itertools +import collections +from typing import Tuple, List, Union +from numbers import Number def _get_products_of_inputs(self, *args) -> Tuple[Number]: """Return a list of tuples that contains all of the input arguments""" From 72b19346598d8204de5fe373e9f742bd0ec6c681 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:17:14 -0400 Subject: [PATCH 12/25] ADD: added import of the misc functions --- spyrograph/_trochoid.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index a35a330..7cfe9e3 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -14,6 +14,8 @@ import numpy as np +from spyrograph._misc import _get_products_of_inputs, _validate_only_one_iterable + try: import matplotlib.pyplot as plt except ImportError: From 138591a1aaea3920c0b7ea5dca2908bad7031f18 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:17:33 -0400 Subject: [PATCH 13/25] REMOVE: removed unnecessary itertools import --- spyrograph/_trochoid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index 7cfe9e3..da709ea 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -10,7 +10,6 @@ import time from abc import ABC, abstractmethod import collections -import itertools import numpy as np From 7d5d60bfc628c2a2b5a84e4d91a033ff356d79f0 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:18:11 -0400 Subject: [PATCH 14/25] ADD: added helper function imports --- spyrograph/_cycloid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index a0a151e..595c1ee 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -8,6 +8,7 @@ import time from spyrograph._trochoid import _Trochoid +from spyrograph._misc import _get_products_of_inputs, _validate_only_one_iterable class _Cycloid(_Trochoid): # pylint: disable=too-few-public-methods From 0d55534ca1f026393ce5c802ee1695f8860a979a Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:19:55 -0400 Subject: [PATCH 15/25] REFACTOR: refactored _Cycloid.create_range to use misc funcs --- spyrograph/_cycloid.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index 595c1ee..090e4b8 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -173,19 +173,17 @@ def create_range( Custom origin to center the shapes at. Default is (0,0) """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme - cls._validate_only_one_iterable(R, r) - R_arr = cls._set_int_to_list(R) - r_arr = cls._set_int_to_list(r) + _validate_only_one_iterable(R, r) + input_params = _get_products_of_inputs(R, r) # TODO: this is fairly ugly, need to come up with better way of handling # this shapes = [] - for R in R_arr: - for r in r_arr: - shapes.append(cls( - R, r, thetas, theta_start, theta_stop, theta_step, - origin - )) + for R, r in input_params: + shapes.append(cls( + R, r, thetas, theta_start, theta_stop, theta_step, + origin + )) return shapes @classmethod From ae5642231d32b89bb1484f774462a1257352d75b Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:22:45 -0400 Subject: [PATCH 16/25] FIX: converted product to list --- spyrograph/_cycloid.py | 1 + spyrograph/_misc.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index 090e4b8..797b1e7 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -175,6 +175,7 @@ def create_range( # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme _validate_only_one_iterable(R, r) input_params = _get_products_of_inputs(R, r) + print(input_params) # TODO: this is fairly ugly, need to come up with better way of handling # this diff --git a/spyrograph/_misc.py b/spyrograph/_misc.py index d3635c3..6b15d69 100644 --- a/spyrograph/_misc.py +++ b/spyrograph/_misc.py @@ -6,7 +6,7 @@ def _get_products_of_inputs(self, *args) -> Tuple[Number]: """Return a list of tuples that contains all of the input arguments""" list_of_lists = [_set_int_to_list(el) for el in args] - product = itertools.product(*list_of_lists) + product = list(itertools.product(*list_of_lists)) return product def _validate_only_one_iterable(*args) -> bool: From 9669efac150a1f7fdec147b3ceb9ad3e54788a2e Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:24:56 -0400 Subject: [PATCH 17/25] REMOVE: removed self arg --- spyrograph/_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyrograph/_misc.py b/spyrograph/_misc.py index 6b15d69..44512ec 100644 --- a/spyrograph/_misc.py +++ b/spyrograph/_misc.py @@ -3,7 +3,7 @@ from typing import Tuple, List, Union from numbers import Number -def _get_products_of_inputs(self, *args) -> Tuple[Number]: +def _get_products_of_inputs(*args) -> Tuple[Number]: """Return a list of tuples that contains all of the input arguments""" list_of_lists = [_set_int_to_list(el) for el in args] product = list(itertools.product(*list_of_lists)) From 1ca6e85d31fbd00e1b896901bdb110e86e8a67c3 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:26:29 -0400 Subject: [PATCH 18/25] REMOVE: removed TODO on reimplementing --- spyrograph/_cycloid.py | 3 --- spyrograph/_trochoid.py | 2 -- 2 files changed, 5 deletions(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index 797b1e7..b10daf8 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -175,10 +175,7 @@ def create_range( # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme _validate_only_one_iterable(R, r) input_params = _get_products_of_inputs(R, r) - print(input_params) - # TODO: this is fairly ugly, need to come up with better way of handling - # this shapes = [] for R, r in input_params: shapes.append(cls( diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index da709ea..ecad0ff 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -495,8 +495,6 @@ def create_range( _validate_only_one_iterable(R, r, d) input_params = _get_products_of_inputs(R, r, d) - # TODO: this is fairly ugly, need to come up with better way of handling - # this shapes = [] for R, r, d in input_params: shapes.append(cls( From 2ba57d4434f5c48df44a1b508f9c33c89dcd2f02 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:27:54 -0400 Subject: [PATCH 19/25] MOVE: moved set_int_to_list into its own function --- tests/_roulette.py | 9 --------- tests/test_misc.py | 8 ++++++++ 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 tests/test_misc.py diff --git a/tests/_roulette.py b/tests/_roulette.py index 83bbd3e..66b789e 100644 --- a/tests/_roulette.py +++ b/tests/_roulette.py @@ -104,15 +104,6 @@ def test_create_range_single_input(self, thetas): assert len(shapes) == 1 assert isinstance(shapes[0], self.class_name) - def test_set_int_to_list(self): - """Test that setting int to list""" - num_test = self.class_name._set_int_to_list(1) - list_test = self.class_name._set_int_to_list([2]) - assert isinstance(num_test, list) - assert isinstance(list_test, list) - assert num_test[0] == 1 - assert list_test[0] == 2 - def test_create_range_multiple_arguments_exception(self, thetas): """Test that passing multiple parameters raises an error""" with pytest.raises(ValueError): diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 0000000..75b1103 --- /dev/null +++ b/tests/test_misc.py @@ -0,0 +1,8 @@ +def test_set_int_to_list(self): + """Test that setting int to list""" + num_test = self.class_name._set_int_to_list(1) + list_test = self.class_name._set_int_to_list([2]) + assert isinstance(num_test, list) + assert isinstance(list_test, list) + assert num_test[0] == 1 + assert list_test[0] == 2 \ No newline at end of file From cec5726bdc36a0060079f0175f0f396ee8cc4440 Mon Sep 17 00:00:00 2001 From: chris-greening Date: Sun, 2 Apr 2023 13:28:39 -0400 Subject: [PATCH 20/25] FIX: fixed test to work for set_int_to_list --- tests/test_misc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 75b1103..f192d7e 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,7 +1,9 @@ -def test_set_int_to_list(self): +from spyrograph._misc import _set_int_to_list + +def test_set_int_to_list(): """Test that setting int to list""" - num_test = self.class_name._set_int_to_list(1) - list_test = self.class_name._set_int_to_list([2]) + num_test = _set_int_to_list(1) + list_test = _set_int_to_list([2]) assert isinstance(num_test, list) assert isinstance(list_test, list) assert num_test[0] == 1 From 9b910a700a9ef003089e96700043bc1a7151f9f0 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Sun, 2 Apr 2023 23:16:09 -0400 Subject: [PATCH 21/25] ADD: added length_args try-except logic --- spyrograph/_cycloid.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index b10daf8..dede76d 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -173,15 +173,24 @@ def create_range( Custom origin to center the shapes at. Default is (0,0) """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme - _validate_only_one_iterable(R, r) - input_params = _get_products_of_inputs(R, r) + try: + length_args = (R, r, d) + except NameError: + length_args = (R, r) + _validate_only_one_iterable(*length_args) + input_params = _get_products_of_inputs(*length_args) shapes = [] - for R, r in input_params: - shapes.append(cls( - R, r, thetas, theta_start, theta_stop, theta_step, - origin - )) + try: + for R, r, d in input_params: + shapes.append(cls( + R, r, d, thetas, theta_start, theta_stop, theta_step, origin + )) + except ValueError: + for R, r in input_params: + shapes.append(cls( + R, r, thetas, theta_start, theta_stop, theta_step, origin + )) return shapes @classmethod From 2ebe293c9209a5c393af339251e6e3f4f285cbfd Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Sun, 2 Apr 2023 23:19:31 -0400 Subject: [PATCH 22/25] ADD: added logic to _Trochoid --- spyrograph/_trochoid.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index ecad0ff..ffa5e54 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -492,15 +492,24 @@ def create_range( 3 """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme - _validate_only_one_iterable(R, r, d) - input_params = _get_products_of_inputs(R, r, d) + try: + length_args = (R, r, d) + except NameError: + length_args = (R, r) + _validate_only_one_iterable(*length_args) + input_params = _get_products_of_inputs(*length_args) shapes = [] - for R, r, d in input_params: - shapes.append(cls( - R, r, d, thetas, theta_start, theta_stop, theta_step, - origin - )) + try: + for R, r, d in input_params: + shapes.append(cls( + R, r, d, thetas, theta_start, theta_stop, theta_step, origin + )) + except ValueError: + for R, r in input_params: + shapes.append(cls( + R, r, thetas, theta_start, theta_stop, theta_step, origin + )) return shapes def _show_full_path(self, pre_draw_turtle: "turtle.Turtle") -> None: From ab2a7347f09da45624bb887e9e278622d8cb85e8 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Sun, 2 Apr 2023 23:24:11 -0400 Subject: [PATCH 23/25] REMOVE: removed unnecessary code from create_range --- spyrograph/_cycloid.py | 22 ++++++---------------- spyrograph/_trochoid.py | 22 ++++++---------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py index dede76d..d7b0255 100644 --- a/spyrograph/_cycloid.py +++ b/spyrograph/_cycloid.py @@ -173,24 +173,14 @@ def create_range( Custom origin to center the shapes at. Default is (0,0) """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,no-member,fixme - try: - length_args = (R, r, d) - except NameError: - length_args = (R, r) - _validate_only_one_iterable(*length_args) - input_params = _get_products_of_inputs(*length_args) + _validate_only_one_iterable(R, r) + input_params = _get_products_of_inputs(R, r) shapes = [] - try: - for R, r, d in input_params: - shapes.append(cls( - R, r, d, thetas, theta_start, theta_stop, theta_step, origin - )) - except ValueError: - for R, r in input_params: - shapes.append(cls( - R, r, thetas, theta_start, theta_stop, theta_step, origin - )) + for R, r in input_params: + shapes.append(cls( + R, r, thetas, theta_start, theta_stop, theta_step, origin + )) return shapes @classmethod diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index ffa5e54..d82dabf 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -492,24 +492,14 @@ def create_range( 3 """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme - try: - length_args = (R, r, d) - except NameError: - length_args = (R, r) - _validate_only_one_iterable(*length_args) - input_params = _get_products_of_inputs(*length_args) + _validate_only_one_iterable(R, r, d) + input_params = _get_products_of_inputs(R, r, d) shapes = [] - try: - for R, r, d in input_params: - shapes.append(cls( - R, r, d, thetas, theta_start, theta_stop, theta_step, origin - )) - except ValueError: - for R, r in input_params: - shapes.append(cls( - R, r, thetas, theta_start, theta_stop, theta_step, origin - )) + for R, r, d in input_params: + shapes.append(cls( + R, r, d, thetas, theta_start, theta_stop, theta_step, origin + )) return shapes def _show_full_path(self, pre_draw_turtle: "turtle.Turtle") -> None: From 91f4fd3883fcc54dc6c30231b4f7d69c220621d3 Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Sun, 2 Apr 2023 23:48:44 -0400 Subject: [PATCH 24/25] MODIFY: changed spacing of cls --- spyrograph/_trochoid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyrograph/_trochoid.py b/spyrograph/_trochoid.py index d82dabf..0333802 100644 --- a/spyrograph/_trochoid.py +++ b/spyrograph/_trochoid.py @@ -492,6 +492,7 @@ def create_range( 3 """ # pylint: disable=line-too-long,redefined-argument-from-local,invalid-name,fixme + _validate_only_one_iterable(R, r, d) input_params = _get_products_of_inputs(R, r, d) From 12325f897666b9a2c29415d5bb2b7689c6c9e7cb Mon Sep 17 00:00:00 2001 From: Christopher Greening Date: Sun, 2 Apr 2023 23:49:24 -0400 Subject: [PATCH 25/25] MODIFY: incr patch version to 0.20.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c6afab9..abcee13 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="spyrograph", - version="0.20.1", + version="0.20.2", author="Chris Greening", author_email="chris@christophergreening.com", description="Library for drawing spirographs in Python",