diff --git a/tests/transformer/test_locust.py b/tests/transformer/test_locust.py index b5e7a51..bf2efc5 100644 --- a/tests/transformer/test_locust.py +++ b/tests/transformer/test_locust.py @@ -38,17 +38,24 @@ def test_it_renders_a_locustfile_template(self): # File automatically generated by Transformer v{__version__}: # https://github.com/zalando-incubator/Transformer import re -import sys from distutils.version import LooseVersion from locust import __version__ -if LooseVersion(__version__) >= LooseVersion('1.0.0'): - print(f'Sorry! You have locust=={{__version__}},', "but Transformer doesn't support locust>=0.99 yet.", 'Please try again with a less recent Locust version', '(e.g. "pip install \\'locustio==0.14.6\\'")', 'while we are working on a long-term solution. 😊', file=sys.stderr) - exit(1) -from locust import HttpLocust -from locust import TaskSequence -from locust import TaskSet -from locust import seq_task -from locust import task +LOCUST_MAJOR_VERSION = LooseVersion(__version__).version[0] +if LOCUST_MAJOR_VERSION >= 1: + from locust import HttpUser + from locust import SequentialTaskSet + from locust import TaskSet + from locust import task + HttpLocust = HttpUser + TaskSequence = SequentialTaskSet + def seq_task(_): + return task +else: + from locust import HttpLocust + from locust import TaskSequence + from locust import TaskSet + from locust import seq_task + from locust import task class ScenarioGroup(TaskSet): @task(1) class SomeScenario(TaskSequence): @@ -56,7 +63,10 @@ class SomeScenario(TaskSequence): def some_task(self): response = self.client.get(url='some_url', name='some_url', timeout=$TIMEOUT, allow_redirects=False, headers={{'a': 'b'}}) class LocustForScenarioGroup(HttpLocust): - task_set = ScenarioGroup + if LOCUST_MAJOR_VERSION >= 1: + tasks = [ScenarioGroup] + else: + task_set = ScenarioGroup weight = 2 min_wait = 0 max_wait = 10 @@ -92,17 +102,24 @@ def plugin_change_task_name(t: Task2) -> Task2: # File automatically generated by Transformer v{__version__}: # https://github.com/zalando-incubator/Transformer import re -import sys from distutils.version import LooseVersion from locust import __version__ -if LooseVersion(__version__) >= LooseVersion('1.0.0'): - print(f'Sorry! You have locust=={{__version__}},', "but Transformer doesn't support locust>=0.99 yet.", 'Please try again with a less recent Locust version', '(e.g. "pip install \\'locustio==0.14.6\\'")', 'while we are working on a long-term solution. 😊', file=sys.stderr) - exit(1) -from locust import HttpLocust -from locust import TaskSequence -from locust import TaskSet -from locust import seq_task -from locust import task +LOCUST_MAJOR_VERSION = LooseVersion(__version__).version[0] +if LOCUST_MAJOR_VERSION >= 1: + from locust import HttpUser + from locust import SequentialTaskSet + from locust import TaskSet + from locust import task + HttpLocust = HttpUser + TaskSequence = SequentialTaskSet + def seq_task(_): + return task +else: + from locust import HttpLocust + from locust import TaskSequence + from locust import TaskSet + from locust import seq_task + from locust import task class ScenarioGroup(TaskSet): @task(1) class SomeScenario(TaskSequence): @@ -110,7 +127,10 @@ class SomeScenario(TaskSequence): def some_task(self): response = self.client.get(url='some_url', name='changed_name', timeout=$TIMEOUT, allow_redirects=False, headers={{'a': 'b'}}) class LocustForScenarioGroup(HttpLocust): - task_set = ScenarioGroup + if LOCUST_MAJOR_VERSION >= 1: + tasks = [ScenarioGroup] + else: + task_set = ScenarioGroup weight = 2 min_wait = 0 max_wait = 10 diff --git a/transformer/builders_python.py b/transformer/builders_python.py index c7714b9..a0efc97 100644 --- a/transformer/builders_python.py +++ b/transformer/builders_python.py @@ -43,7 +43,7 @@ def ascii_text(min_size: int = 0, max_size: Optional[int] = 5) -> SearchStrategy def ascii_inline_text( - min_size: int = 0, max_size: Optional[int] = 5 + min_size: int = 0, max_size: Optional[int] = 3 ) -> SearchStrategy[str]: """Similar to ascii_text, but does not generate multiline strings.""" return text(_ascii_inline, min_size=min_size, max_size=max_size)