From 7aa8f4568a1da6382a85441a243100f963ee215a Mon Sep 17 00:00:00 2001 From: Quitterie Lucas Date: Fri, 27 Oct 2023 15:17:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D(project)=20unify=20infinitive=20us?= =?UTF-8?q?e=20in=20docstrings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In ralph, it has been established that all docstrings shall begin with an infinitive verb. Some typos remaining are now unified. --- gitlint/gitlint_emoji.py | 2 +- src/ralph/api/auth/basic.py | 2 +- src/ralph/api/routers/health.py | 4 +-- src/ralph/api/routers/statements.py | 2 +- src/ralph/backends/data/s3.py | 2 +- src/ralph/backends/data/swift.py | 2 +- src/ralph/backends/mixins.py | 4 +-- src/ralph/cli.py | 18 +++++----- src/ralph/conf.py | 6 ++-- src/ralph/models/converter.py | 6 ++-- src/ralph/models/selector.py | 2 +- src/ralph/models/validator.py | 6 ++-- src/ralph/parsers.py | 4 +-- tests/api/auth/test_basic.py | 2 +- tests/api/test_forwarding.py | 2 +- tests/api/test_statements.py | 2 +- tests/api/test_statements_get.py | 4 +-- tests/api/test_statements_post.py | 2 +- tests/api/test_statements_put.py | 2 +- tests/backends/http/test_async_lrs.py | 5 +-- tests/backends/lrs/test_async_mongo.py | 2 +- tests/backends/lrs/test_mongo.py | 2 +- tests/backends/stream/test_base.py | 2 +- tests/fixtures/backends.py | 33 ++++++++++++++----- tests/fixtures/hypothesis_strategies.py | 2 +- tests/helpers.py | 1 + tests/models/edx/converters/xapi/test_base.py | 6 ++-- .../models/edx/converters/xapi/test_video.py | 10 +++--- .../open_response_assessment/test_events.py | 6 ++-- .../edx/peer_instruction/test_statements.py | 9 +++-- tests/models/test_converter.py | 8 ++--- tests/models/xapi/base/test_statements.py | 16 ++++----- tests/models/xapi/test_video.py | 3 +- tests/models/xapi/test_virtual_classroom.py | 6 ++-- tests/test_cli.py | 28 ++++++++-------- tests/test_helpers.py | 2 +- tests/test_utils.py | 8 ++--- 37 files changed, 124 insertions(+), 99 deletions(-) diff --git a/gitlint/gitlint_emoji.py b/gitlint/gitlint_emoji.py index eb9040432..efad682bb 100644 --- a/gitlint/gitlint_emoji.py +++ b/gitlint/gitlint_emoji.py @@ -23,7 +23,7 @@ class GitmojiTitle(LineRule): target = CommitMessageTitle def validate(self, title, _commit): - """Validates Gitmoji title rule. + """Validate Gitmoji title rule. Downloads the list possible gitmojis from the project's GitHub repository and check that title contains one of them. diff --git a/src/ralph/api/auth/basic.py b/src/ralph/api/auth/basic.py index 027552595..f309ba371 100644 --- a/src/ralph/api/auth/basic.py +++ b/src/ralph/api/auth/basic.py @@ -114,7 +114,7 @@ def get_basic_auth_user( credentials: Optional[HTTPBasicCredentials] = Depends(security), security_scopes: SecurityScopes = SecurityScopes([]), ) -> AuthenticatedUser: - """Checks valid auth parameters. + """Check valid auth parameters. Get the basic auth parameters from the Authorization header, and checks them against our own list of hashed credentials. diff --git a/src/ralph/api/routers/health.py b/src/ralph/api/routers/health.py index 1bafb3467..c8ca015f1 100644 --- a/src/ralph/api/routers/health.py +++ b/src/ralph/api/routers/health.py @@ -25,7 +25,7 @@ async def lbheartbeat() -> None: """Load balancer heartbeat. - Returns a 200 when the server is running. + Return a 200 when the server is running. """ return @@ -34,7 +34,7 @@ async def lbheartbeat() -> None: async def heartbeat() -> JSONResponse: """Application heartbeat. - Returns a 200 if all checks are successful. + Return a 200 if all checks are successful. """ content = {"database": (await await_if_coroutine(BACKEND_CLIENT.status())).value} status_code = ( diff --git a/src/ralph/api/routers/statements.py b/src/ralph/api/routers/statements.py index f163e2f99..436f82c52 100644 --- a/src/ralph/api/routers/statements.py +++ b/src/ralph/api/routers/statements.py @@ -588,5 +588,5 @@ async def post( logger.info("Indexed %d statements with success", success_count) - # Returns the list of IDs in the same order they were stored + # Return the list of IDs in the same order they were stored return list(statements_dict) diff --git a/src/ralph/backends/data/s3.py b/src/ralph/backends/data/s3.py index d4c30af5c..4198b9b5f 100644 --- a/src/ralph/backends/data/s3.py +++ b/src/ralph/backends/data/s3.py @@ -164,7 +164,7 @@ def read( ignore_errors: bool = False, ) -> Iterator[Union[bytes, dict]]: # pylint: disable=too-many-arguments - """Read an object matching the `query` in the `target` bucket and yields it. + """Read an object matching the `query` in the `target` bucket and yield it. Args: query: (str or BaseQuery): The ID of the object to read. diff --git a/src/ralph/backends/data/swift.py b/src/ralph/backends/data/swift.py index b0b75c53d..ac3b0ef9b 100644 --- a/src/ralph/backends/data/swift.py +++ b/src/ralph/backends/data/swift.py @@ -169,7 +169,7 @@ def read( ignore_errors: bool = False, ) -> Iterator[Union[bytes, dict]]: # pylint: disable=too-many-arguments - """Read objects matching the `query` in the `target` container and yields them. + """Read objects matching the `query` in the `target` container and yield them. Args: query: (str or BaseQuery): The query to select objects to read. diff --git a/src/ralph/backends/mixins.py b/src/ralph/backends/mixins.py index ae6e53ac4..6304abe08 100644 --- a/src/ralph/backends/mixins.py +++ b/src/ralph/backends/mixins.py @@ -59,10 +59,10 @@ def append_to_history(self, event): self.write_history(self.history + [event]) def get_command_history(self, backend_name, command): - """Extracts entry ids from the history for a given command and backend_name.""" + """Extract entry ids from the history for a given command and backend_name.""" def filter_by_name_and_command(entry): - """Checks whether the history entry matches the backend_name and command.""" + """Check whether the history entry matches the backend_name and command.""" return entry.get("backend") == backend_name and ( command in [entry.get("command"), entry.get("action")] ) diff --git a/src/ralph/cli.py b/src/ralph/cli.py index 932957bb5..782944c34 100644 --- a/src/ralph/cli.py +++ b/src/ralph/cli.py @@ -56,7 +56,7 @@ class CommaSeparatedTupleParamType(click.ParamType): name = "value1,value2,value3" def convert(self, value, param, ctx): - """Splits the value by comma to return a tuple of values.""" + """Split the value by comma to return a tuple of values.""" if isinstance(value, str): return tuple(value.split(",")) @@ -76,9 +76,9 @@ class CommaSeparatedKeyValueParamType(click.ParamType): name = "key=value,key=value" def convert(self, value, param, ctx): - """Splits the values by comma and equal sign. + """Split the values by comma and equal sign. - Returns a dictionary build with key/value pairs. + Return a dictionary build with key/value pairs. """ if isinstance(value, dict): return value @@ -116,7 +116,7 @@ class ClientOptionsParamType(CommaSeparatedKeyValueParamType): """Comma separated key=value parameter type for client options.""" def __init__(self, client_options_type: Any) -> None: - """Instantiates ClientOptionsParamType for a client_options_type. + """Instantiate ClientOptionsParamType for a client_options_type. Args: client_options_type (any): Pydantic model used for client options. @@ -124,9 +124,9 @@ def __init__(self, client_options_type: Any) -> None: self.client_options_type = client_options_type def convert(self, value, param, ctx): - """Splits the values by comma and equal sign. + """Split the values by comma and equal sign. - Returns an instance of client_options_type build with key/value pairs. + Return an instance of client_options_type build with key/value pairs. """ if isinstance(value, self.client_options_type): return value @@ -138,7 +138,7 @@ class HeadersParametersParamType(CommaSeparatedKeyValueParamType): """Comma separated key=value parameter type for headers parameters.""" def __init__(self, headers_parameters_type: Any) -> None: - """Instantiates HeadersParametersParamType for a headers_parameters_type. + """Instantiate HeadersParametersParamType for a headers_parameters_type. Args: headers_parameters_type (any): Pydantic model used for headers parameters. @@ -146,9 +146,9 @@ def __init__(self, headers_parameters_type: Any) -> None: self.headers_parameters_type = headers_parameters_type def convert(self, value, param, ctx): - """Splits the values by comma and equal sign. + """Split the values by comma and equal sign. - Returns an instance of headers_parameters_type build with key/value pairs. + Return an instance of headers_parameters_type build with key/value pairs. """ if isinstance(value, self.headers_parameters_type): return value diff --git a/src/ralph/conf.py b/src/ralph/conf.py index 00affd056..5b415fa7f 100644 --- a/src/ralph/conf.py +++ b/src/ralph/conf.py @@ -79,7 +79,7 @@ class Config: # pylint: disable=missing-class-docstring # noqa: D106 _class_path: str = None def get_instance(self, **init_parameters): - """Returns an instance of the settings item class using its `_class_path`.""" + """Return an instance of the settings item class using its `_class_path`.""" return import_string(self._class_path)(**init_parameters) @@ -208,12 +208,12 @@ class AuthBackends(Enum): @property def APP_DIR(self) -> Path: # pylint: disable=invalid-name - """Returns the path to Ralph's configuration directory.""" + """Return the path to Ralph's configuration directory.""" return self._CORE.APP_DIR @property def LOCALE_ENCODING(self) -> str: # pylint: disable=invalid-name - """Returns Ralph's default locale encoding.""" + """Return Ralph's default locale encoding.""" return self._CORE.LOCALE_ENCODING @root_validator(allow_reuse=True) diff --git a/src/ralph/models/converter.py b/src/ralph/models/converter.py index 7ddbe96e0..49b412365 100644 --- a/src/ralph/models/converter.py +++ b/src/ralph/models/converter.py @@ -102,12 +102,12 @@ class BaseConversionSet(ABC): __dest__: BaseModel def __init__(self) -> None: - """Initializes BaseConversionSet.""" + """Initialize BaseConversionSet.""" self._conversion_items = self._get_conversion_items() @abstractmethod def _get_conversion_items(self) -> Set[ConversionItem]: - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" def __iter__(self) -> Iterator[ConversionItem]: # noqa: D105 return iter(self._conversion_items) @@ -172,7 +172,7 @@ def __init__( module: str = "ralph.models.edx.converters.xapi", **conversion_set_kwargs: Any, ) -> None: - """Initializes the Converter.""" + """Initialize the Converter.""" self.model_selector = model_selector self.src_conversion_set = self.get_src_conversion_set( import_module(module), **conversion_set_kwargs diff --git a/src/ralph/models/selector.py b/src/ralph/models/selector.py index a39980d87..9375a3cfe 100644 --- a/src/ralph/models/selector.py +++ b/src/ralph/models/selector.py @@ -67,7 +67,7 @@ class ModelSelector: """ def __init__(self, module: str = "ralph.models.edx") -> None: - """Instantiates ModelSelector.""" + """Instantiate ModelSelector.""" self.model_rules = ModelSelector.build_model_rules(import_module(module)) self.decision_tree = self.get_decision_tree(self.model_rules) diff --git a/src/ralph/models/validator.py b/src/ralph/models/validator.py index fe970e46e..78bebe7d5 100644 --- a/src/ralph/models/validator.py +++ b/src/ralph/models/validator.py @@ -17,13 +17,13 @@ class Validator: """Events validator using pydantic models.""" def __init__(self, model_selector: ModelSelector): - """Initializes Validator.""" + """Initialize Validator.""" self.model_selector = model_selector def validate( self, input_file: TextIO, ignore_errors: bool, fail_on_unknown: bool ) -> Generator: - """Validates JSON event strings line by line.""" + """Validate JSON event strings line by line.""" total = 0 success = 0 for event_str in input_file: @@ -48,7 +48,7 @@ def validate( logger.info("Total events: %d, Invalid events: %d", total, total - success) def get_first_valid_model(self, event: dict) -> Any: - """Returns the first successfully instantiated model for the event. + """Return the first successfully instantiated model for the event. Raises: UnknownEventException: When the event does not match any model. diff --git a/src/ralph/parsers.py b/src/ralph/parsers.py index 545b4edfc..8552afc32 100644 --- a/src/ralph/parsers.py +++ b/src/ralph/parsers.py @@ -35,7 +35,7 @@ class GELFParser(BaseParser): name = "gelf" def parse(self, input_file: Union[TextIO, BinaryIO]) -> Generator: - """Parses GELF formatted logs (one JSON string event per row). + """Parse GELF formatted logs (one JSON string event per row). Args: input_file (file-like): The log file to parse. @@ -67,7 +67,7 @@ class ElasticSearchParser(BaseParser): name = "es" def parse(self, input_file: Union[TextIO, BinaryIO]) -> Generator: - """Parses Elasticsearch JSON documents. + """Parse Elasticsearch JSON documents. Args: input_file (file-like): The file containing Elasticsearch JSON documents. diff --git a/tests/api/auth/test_basic.py b/tests/api/auth/test_basic.py index 211f5e411..d692fb619 100644 --- a/tests/api/auth/test_basic.py +++ b/tests/api/auth/test_basic.py @@ -213,7 +213,7 @@ def test_get_whoami_wrong_password(basic_auth_test_client, fs): def test_get_whoami_correct_credentials(basic_auth_test_client, fs): """Whoami returns a 200 response when the credentials are correct. - Returns the username and associated scopes. + Return the username and associated scopes. """ credential_bytes = base64.b64encode("ralph:admin".encode("utf-8")) credentials = str(credential_bytes, "utf-8") diff --git a/tests/api/test_forwarding.py b/tests/api/test_forwarding.py index 2aeb019e1..5ed686195 100644 --- a/tests/api/test_forwarding.py +++ b/tests/api/test_forwarding.py @@ -200,7 +200,7 @@ def raise_for_status(): raise RequestError("Failure during request.") async def post_fail(*args, **kwargs): # pylint: disable=unused-argument - """Returns a MockUnsuccessfulResponse instance.""" + """Return a MockUnsuccessfulResponse instance.""" return MockUnsuccessfulResponse() monkeypatch.setattr("ralph.api.forwarding.AsyncClient.post", post_fail) diff --git a/tests/api/test_statements.py b/tests/api/test_statements.py index 1a468875c..d05f0d3a9 100644 --- a/tests/api/test_statements.py +++ b/tests/api/test_statements.py @@ -12,7 +12,7 @@ def test_api_statements_backend_instance_with_runserver_backend_env(monkeypatch): - """Tests that given the RALPH_RUNSERVER_BACKEND environment variable, the backend + """Test that given the RALPH_RUNSERVER_BACKEND environment variable, the backend instance `BACKEND_CLIENT` should be updated accordingly. """ # Default backend diff --git a/tests/api/test_statements_get.py b/tests/api/test_statements_get.py index 856bf3e6b..8d675fb90 100644 --- a/tests/api/test_statements_get.py +++ b/tests/api/test_statements_get.py @@ -70,7 +70,7 @@ def insert_mongo_statements(mongo_client, statements): def insert_clickhouse_statements(statements): - """Inserts a bunch of example statements into ClickHouse for testing.""" + """Insert a bunch of example statements into ClickHouse for testing.""" settings = ClickHouseDataBackend.settings_class( HOST=CLICKHOUSE_TEST_HOST, PORT=CLICKHOUSE_TEST_PORT, @@ -90,7 +90,7 @@ def insert_statements_and_monkeypatch_backend( # pylint: disable=invalid-name,unused-argument def _insert_statements_and_monkeypatch_backend(statements): - """Inserts statements once into each backend.""" + """Insert statements once into each backend.""" backend_client_class_path = "ralph.api.routers.statements.BACKEND_CLIENT" if request.param == "async_es": insert_es_statements(es, statements) diff --git a/tests/api/test_statements_post.py b/tests/api/test_statements_post.py index 7b7858042..1a040a0df 100644 --- a/tests/api/test_statements_post.py +++ b/tests/api/test_statements_post.py @@ -465,7 +465,7 @@ async def test_api_statements_post_with_failure_during_storage( # pylint: disable=invalid-name,unused-argument,too-many-arguments async def write_mock(*args, **kwargs): - """Raises an exception. Mocks the database.write method.""" + """Raise an exception. Mocks the database.write method.""" raise BackendException() backend_instance = backend() diff --git a/tests/api/test_statements_put.py b/tests/api/test_statements_put.py index 5512987b6..f65966f90 100644 --- a/tests/api/test_statements_put.py +++ b/tests/api/test_statements_put.py @@ -350,7 +350,7 @@ async def test_api_statements_put_with_failure_during_storage( # pylint: disable=invalid-name,unused-argument,too-many-arguments def write_mock(*args, **kwargs): - """Raises an exception. Mocks the database.write method.""" + """Raise an exception. Mocks the database.write method.""" raise BackendException() backend_instance = backend() diff --git a/tests/backends/http/test_async_lrs.py b/tests/backends/http/test_async_lrs.py index 9bddefa0c..371f0c48f 100644 --- a/tests/backends/http/test_async_lrs.py +++ b/tests/backends/http/test_async_lrs.py @@ -798,7 +798,8 @@ async def test_backends_http_lrs_write_with_invalid_parameters( @pytest.mark.anyio async def test_backends_http_lrs_write_without_target(httpx_mock: HTTPXMock, caplog): """Test the LRS backend `write` method without target parameter value writes - statements to '/xAPI/statements' default endpoint.""" + statements to '/xAPI/statements' default endpoint. + """ base_url = "http://fake-lrs.com" @@ -872,7 +873,7 @@ async def test_backends_http_lrs_write_backend_exception( httpx_mock: HTTPXMock, caplog, ): - """Test the `LRSHTTP.write` method with HTTP error""" + """Test the `LRSHTTP.write` method with HTTP error.""" base_url = "http://fake-lrs.com" target = "/xAPI/statements" diff --git a/tests/backends/lrs/test_async_mongo.py b/tests/backends/lrs/test_async_mongo.py index b3f3a9108..b0ed2d09a 100644 --- a/tests/backends/lrs/test_async_mongo.py +++ b/tests/backends/lrs/test_async_mongo.py @@ -360,7 +360,7 @@ async def mock_read(**_): async def test_backends_lrs_mongo_lrs_backend_query_statements_by_ids_two_collections( mongo, mongo_forwarding, async_mongo_lrs_backend ): - """Tests the `AsyncMongoLRSBackend.query_statements_by_ids` method, given a valid + """Test the `AsyncMongoLRSBackend.query_statements_by_ids` method, given a valid search query, should execute the query only on the specified collection and return the expected results. """ diff --git a/tests/backends/lrs/test_mongo.py b/tests/backends/lrs/test_mongo.py index 612b9c0a7..aa643c6ff 100644 --- a/tests/backends/lrs/test_mongo.py +++ b/tests/backends/lrs/test_mongo.py @@ -352,7 +352,7 @@ def mock_read(**_): def test_backends_lrs_mongo_lrs_backend_query_statements_by_ids_with_two_collections( mongo, mongo_forwarding, mongo_lrs_backend ): - """Tests the `MongoLRSBackend.query_statements_by_ids` method, given a valid search + """Test the `MongoLRSBackend.query_statements_by_ids` method, given a valid search query, should execute the query only on the specified collection and return the expected results. """ diff --git a/tests/backends/stream/test_base.py b/tests/backends/stream/test_base.py index d6c4a3cb9..2e4282f5d 100644 --- a/tests/backends/stream/test_base.py +++ b/tests/backends/stream/test_base.py @@ -12,7 +12,7 @@ class GoodStream(BaseStreamBackend): name = "good" def stream(self, target): - """Fakes the stream method.""" + """Fake the stream method.""" GoodStream() diff --git a/tests/fixtures/backends.py b/tests/fixtures/backends.py index 46df6812c..ab73d270e 100644 --- a/tests/fixtures/backends.py +++ b/tests/fixtures/backends.py @@ -174,7 +174,10 @@ def get_es_fixture(host=ES_TEST_HOSTS, index=ES_TEST_INDEX): @pytest.fixture def es(): - """Yield an Elasticsearch test client. See get_es_fixture above.""" + """Yield an Elasticsearch test client. + + See get_es_fixture above. + """ # pylint: disable=invalid-name for es_client in get_es_fixture(): yield es_client @@ -182,7 +185,10 @@ def es(): @pytest.fixture def es_forwarding(): - """Yield a second Elasticsearch test client. See get_es_fixture above.""" + """Yield a second Elasticsearch test client. + + See get_es_fixture above. + """ for es_client in get_es_fixture(index=ES_TEST_FORWARDING_INDEX): yield es_client @@ -268,7 +274,7 @@ def get_mongo_fixture( database=MONGO_TEST_DATABASE, collection=MONGO_TEST_COLLECTION, ): - """Create / delete a Mongo test database + collection and yields an + """Create / delete a Mongo test database + collection and yield an instantiated client. """ client = MongoClient(connection_uri) @@ -286,7 +292,10 @@ def get_mongo_fixture( @pytest.fixture def mongo(): - """Yield a Mongo test client. See get_mongo_fixture above.""" + """Yield a Mongo test client. + + See get_mongo_fixture above. + """ for mongo_client in get_mongo_fixture(): yield mongo_client @@ -339,7 +348,10 @@ def get_mongo_lrs_backend( @pytest.fixture def mongo_forwarding(): - """Yield a second Mongo test client. See get_mongo_fixture above.""" + """Yield a second Mongo test client. + + See get_mongo_fixture above. + """ for mongo_client in get_mongo_fixture(collection=MONGO_TEST_FORWARDING_COLLECTION): yield mongo_client @@ -350,7 +362,7 @@ def get_clickhouse_fixture( database=CLICKHOUSE_TEST_DATABASE, event_table_name=CLICKHOUSE_TEST_TABLE_NAME, ): - """Create / delete a ClickHouse test database + table and yields an + """Create / delete a ClickHouse test database + table and yield an instantiated client. """ client_options = ClickHouseClientOptions( @@ -396,7 +408,10 @@ def get_clickhouse_fixture( @pytest.fixture def clickhouse(): - """Yield a ClickHouse test client. See get_clickhouse_fixture above.""" + """Yield a ClickHouse test client. + + See get_clickhouse_fixture above. + """ for clickhouse_client in get_clickhouse_fixture(): yield clickhouse_client @@ -455,7 +470,7 @@ def es_data_stream(): @pytest.fixture def settings_fs(fs, monkeypatch): - """Force Path instantiation with fake FS in Ralph's Settings.""" + """Force Path instantiation with fake FS in ralph settings.""" # pylint:disable=invalid-name,unused-argument monkeypatch.setattr( @@ -636,7 +651,7 @@ def get_swift_data_backend(): @pytest.fixture() def moto_fs(fs): - """Fix the incompatibility between moto and pyfakefs""" + """Fix the incompatibility between moto and pyfakefs.""" # pylint:disable=invalid-name for module in [boto3, botocore]: diff --git a/tests/fixtures/hypothesis_strategies.py b/tests/fixtures/hypothesis_strategies.py index b874cf6a4..fb5e9f30e 100644 --- a/tests/fixtures/hypothesis_strategies.py +++ b/tests/fixtures/hypothesis_strategies.py @@ -96,7 +96,7 @@ def custom_builds( def custom_given(*args: Union[st.SearchStrategy, BaseModel], **kwargs): - """Wrap the Hypothesis `given` function. Replaces st.builds with custom_builds.""" + """Wrap the Hypothesis `given` function. Replace st.builds with custom_builds.""" strategies = [] for arg in args: strategies.append(custom_builds(arg) if is_base_model(arg) else arg) diff --git a/tests/helpers.py b/tests/helpers.py index 3aceccad1..c361f1dfd 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -134,6 +134,7 @@ def mock_statement( timestamp: Optional[Union[str, int]] = None, ): """Generate fake statements with random or provided parameters. + Fields `actor`, `verb`, `object`, `timestamp` accept integer values which can be used to create distinct values identifiable by this integer. For each variable, using `None` will assign a default value. `timestamp` may be ommited diff --git a/tests/models/edx/converters/xapi/test_base.py b/tests/models/edx/converters/xapi/test_base.py index f7babb58f..ddf4975e8 100644 --- a/tests/models/edx/converters/xapi/test_base.py +++ b/tests/models/edx/converters/xapi/test_base.py @@ -18,7 +18,7 @@ class DummyBaseXapiConverter(BaseXapiConverter): """Dummy implementation of abstract BaseXapiConverter.""" def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return set() converter = DummyBaseXapiConverter(uuid_namespace, "https://fun-mooc.fr") @@ -27,13 +27,13 @@ def _get_conversion_items(self): # pylint: disable=no-self-use def test_models_edx_converters_xapi_base_xapi_converter_unsuccessful_initialization(): - """Tests BaseXapiConverter failed initialization.""" + """Test BaseXapiConverter failed initialization.""" class DummyBaseXapiConverter(BaseXapiConverter): """Dummy implementation of abstract BaseXapiConverter.""" def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return set() with pytest.raises(ConfigurationException, match="Invalid UUID namespace"): diff --git a/tests/models/edx/converters/xapi/test_video.py b/tests/models/edx/converters/xapi/test_video.py index ebafc0674..914c05a46 100644 --- a/tests/models/edx/converters/xapi/test_video.py +++ b/tests/models/edx/converters/xapi/test_video.py @@ -30,7 +30,7 @@ def test_models_edx_converters_xapi_video_ui_load_video_to_video_initialized( uuid_namespace, event, platform_url ): - """Tests that converting with `UILoadVideoToVideoInitialized` returns the + """Test that converting with `UILoadVideoToVideoInitialized` returns the expected xAPI statement. """ event.context.user_id = "1" @@ -85,7 +85,7 @@ def test_models_edx_converters_xapi_video_ui_load_video_to_video_initialized( def test_models_edx_converters_xapi_video_ui_play_video_to_video_played( uuid_namespace, event, platform_url ): - """Tests that converting with `UIPlayVideoToVideoPlayed` returns the expected + """Test that converting with `UIPlayVideoToVideoPlayed` returns the expected xAPI statement. """ event.context.user_id = "1" @@ -144,7 +144,7 @@ def test_models_edx_converters_xapi_video_ui_play_video_to_video_played( def test_models_edx_converters_xapi_video_ui_pause_video_to_video_paused( uuid_namespace, event, platform_url ): - """Tests that converting with `UIPauseVideoToVideoPaused` returns the expected xAPI + """Test that converting with `UIPauseVideoToVideoPaused` returns the expected xAPI statement. """ event.context.user_id = "1" @@ -204,7 +204,7 @@ def test_models_edx_converters_xapi_video_ui_pause_video_to_video_paused( def test_models_edx_converters_xapi_video_ui_stop_video_to_video_terminated( uuid_namespace, event, platform_url ): - """Tests that converting with `UIStopVideoToVideoTerminated` returns the expected + """Test that converting with `UIStopVideoToVideoTerminated` returns the expected xAPI statement. """ event.context.user_id = "1" @@ -265,7 +265,7 @@ def test_models_edx_converters_xapi_video_ui_stop_video_to_video_terminated( def test_models_edx_converters_xapi_video_ui_seek_video_to_video_seeked( uuid_namespace, event, platform_url ): - """Tests that converting with `UISeekVideoToVideoSeeked` returns the expected + """Test that converting with `UISeekVideoToVideoSeeked` returns the expected xAPI statement. """ event.context.user_id = "1" diff --git a/tests/models/edx/open_response_assessment/test_events.py b/tests/models/edx/open_response_assessment/test_events.py index 7af940c45..614f2bc98 100644 --- a/tests/models/edx/open_response_assessment/test_events.py +++ b/tests/models/edx/open_response_assessment/test_events.py @@ -19,7 +19,8 @@ @custom_given(ORAGetPeerSubmissionEventField) def test_models_edx_ora_get_peer_submission_event_field_with_valid_values(field): """Test that a valid `ORAGetPeerSubmissionEventField` does not raise a - `ValidationError`.""" + `ValidationError`. + """ assert re.match( r"^block-v1:.+\+.+\+.+type@openassessment+block@[a-f0-9]{32}$", field.item_id @@ -31,7 +32,8 @@ def test_models_edx_ora_get_submission_for_staff_grading_event_field_with_valid_ field, ): """Test that a valid `ORAGetSubmissionForStaffGradingEventField` does not raise a - `ValidationError`.""" + `ValidationError`. + """ assert re.match( r"^block-v1:.+\+.+\+.+type@openassessment+block@[a-f0-9]{32}$", field.item_id diff --git a/tests/models/edx/peer_instruction/test_statements.py b/tests/models/edx/peer_instruction/test_statements.py index 2aa760135..3c2841573 100644 --- a/tests/models/edx/peer_instruction/test_statements.py +++ b/tests/models/edx/peer_instruction/test_statements.py @@ -38,7 +38,8 @@ def test_models_edx_peer_instruction_accessed_with_valid_statement( statement, ): """Test that a `ubc.peer_instruction.accessed` statement has the expected - `event_type`.""" + `event_type`. + """ assert statement.event_type == "ubc.peer_instruction.accessed" assert statement.name == "ubc.peer_instruction.accessed" @@ -48,7 +49,8 @@ def test_models_edx_peer_instruction_original_submitted_with_valid_statement( statement, ): """Test that a `ubc.peer_instruction.original_submitted` statement has the - expected `event_type`.""" + expected `event_type`. + """ assert statement.event_type == "ubc.peer_instruction.original_submitted" assert statement.name == "ubc.peer_instruction.original_submitted" @@ -58,6 +60,7 @@ def test_models_edx_peer_instruction_revised_submitted_with_valid_statement( statement, ): """Test that a `ubc.peer_instruction.revised_submitted` statement has the - expected `event_type`.""" + expected `event_type`. + """ assert statement.event_type == "ubc.peer_instruction.revised_submitted" assert statement.name == "ubc.peer_instruction.revised_submitted" diff --git a/tests/models/test_converter.py b/tests/models/test_converter.py index 74d678c31..e9b8b4ef3 100644 --- a/tests/models/test_converter.py +++ b/tests/models/test_converter.py @@ -113,7 +113,7 @@ class DummyBaseConversionSet(BaseConversionSet): __dest__ = BaseModel def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return set() assert not convert_dict_event(event, "", DummyBaseConversionSet()).dict() @@ -153,7 +153,7 @@ class DummyBaseConversionSet(BaseConversionSet): __dest__ = DummyBaseModel def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return {ConversionItem("converted", source, transformer)} converted = convert_dict_event(event, "", DummyBaseConversionSet()) @@ -172,7 +172,7 @@ class DummyBaseConversionSet(BaseConversionSet): __dest__ = BaseModel def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return {item} msg = "Failed to get the transformed value for field: None" @@ -190,7 +190,7 @@ class DummyBaseConversionSet(BaseConversionSet): __dest__ = BaseModel def _get_conversion_items(self): # pylint: disable=no-self-use - """Returns a set of ConversionItems used for conversion.""" + """Return a set of ConversionItems used for conversion.""" return set() msg = "Failed to parse the event, invalid JSON string" diff --git a/tests/models/xapi/base/test_statements.py b/tests/models/xapi/base/test_statements.py index 3fd1dcfc5..a88fca426 100644 --- a/tests/models/xapi/base/test_statements.py +++ b/tests/models/xapi/base/test_statements.py @@ -40,7 +40,7 @@ def test_models_xapi_base_statement_with_invalid_null_values(path, value, statem XAPI-00001 An LRS rejects with error code 400 Bad Request any Statement having a property whose value is set to "null", an empty object, or has no value, except in an "extensions" - property + property. """ statement = statement.dict(exclude_none=True) set_dict_value_from_path(statement, path.split("__"), value) @@ -64,7 +64,7 @@ def test_models_xapi_base_statement_with_valid_null_values(path, value, statemen XAPI-00001 An LRS rejects with error code 400 Bad Request any Statement having a property whose value is set to "null", an empty object, or has no value, except in an "extensions" - property + property. """ statement = statement.dict(exclude_none=True) set_dict_value_from_path(statement, path.split("__"), value) @@ -108,13 +108,13 @@ def test_models_xapi_base_statement_must_use_actor_verb_and_object(field, statem XAPI-00003 An LRS rejects with error code 400 Bad Request a Statement which does not contain an - "actor" property + "actor" property. XAPI-00004 An LRS rejects with error code 400 Bad Request a Statement which does not contain a - "verb" property + "verb" property. XAPI-00005 An LRS rejects with error code 400 Bad Request a Statement which does not contain an - "object" property + "object" property. """ statement = statement.dict(exclude_none=True) del statement[field] @@ -142,7 +142,7 @@ def test_models_xapi_base_statement_with_invalid_data_types(path, value, stateme XAPI-00006 An LRS rejects with error code 400 Bad Request a Statement which uses the wrong data - type + type. """ statement = statement.dict(exclude_none=True) set_dict_value_from_path(statement, path.split("__"), value) @@ -469,7 +469,7 @@ def test_models_xapi_base_statement_with_invalid_version(value, statement): """Test that the statement does not accept an invalid version field. An LRS MUST reject all Statements with a version specified that does not start with - 1.0.. + 1.0. """ statement = statement.dict(exclude_none=True) set_dict_value_from_path(statement, ["version"], value) @@ -482,7 +482,7 @@ def test_models_xapi_base_statement_with_valid_version(statement): """Test that the statement does accept a valid version field. Statements returned by an LRS MUST retain the version they are accepted with. - If they lack a version, the version MUST be set to 1.0.0 + If they lack a version, the version MUST be set to 1.0.0. """ statement = statement.dict(exclude_none=True) set_dict_value_from_path(statement, ["version"], "1.0.3") diff --git a/tests/models/xapi/test_video.py b/tests/models/xapi/test_video.py index 52f25f078..52d1b974f 100644 --- a/tests/models/xapi/test_video.py +++ b/tests/models/xapi/test_video.py @@ -115,7 +115,8 @@ def test_models_xapi_video_paused_with_valid_statement(statement): @custom_given(VideoSeeked) def test_models_xapi_video_seeked_with_valid_statement(statement): """Test that a video seeked statement has the expected `verb`.`id` and - `object`.`definition`.`type` property values.""" + `object`.`definition`.`type` property values. + """ assert statement.verb.id == "https://w3id.org/xapi/video/verbs/seeked" assert ( diff --git a/tests/models/xapi/test_virtual_classroom.py b/tests/models/xapi/test_virtual_classroom.py index 854db14d9..b3eeadeb4 100644 --- a/tests/models/xapi/test_virtual_classroom.py +++ b/tests/models/xapi/test_virtual_classroom.py @@ -78,7 +78,8 @@ def test_models_xapi_virtual_classroom_initialized_with_valid_statement(statemen @custom_given(VirtualClassroomJoined) def test_models_xapi_virtual_classroom_joined_with_valid_statement(statement): """Test that a virtual classroom joined statement has the expected - `verb`.`id` and `object`.`definition`.`type` property values.""" + `verb`.`id` and `object`.`definition`.`type` property values. + """ assert statement.verb.id == "http://activitystrea.ms/join" assert ( statement.object.definition.type @@ -89,7 +90,8 @@ def test_models_xapi_virtual_classroom_joined_with_valid_statement(statement): @custom_given(VirtualClassroomLeft) def test_models_xapi_virtual_classroom_left_with_valid_statement(statement): """Test that a virtual classroom left statement has the expected - `verb`.`id` and `object`.`definition`.`type` property values.""" + `verb`.`id` and `object`.`definition`.`type` property values. + """ assert statement.verb.id == "http://activitystrea.ms/leave" assert ( statement.object.definition.type diff --git a/tests/test_cli.py b/tests/test_cli.py index 890576027..827543378 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -198,7 +198,7 @@ def _assert_matching_basic_auth_credentials( ): """Assert that credentials match other arguments. - args: + Args: credentials: credentials to match against username: username that should match credentials scopes: scopes that should match credentials @@ -236,7 +236,7 @@ def _assert_matching_basic_auth_credentials( def _ifi_type_from_command(ifi_command): - """Return the ifi_type associated to the command being passed to cli""" + """Return the ifi_type associated to the command being passed to cli.""" if ifi_command not in ["-M", "-S", "-O", "-A"]: raise ValueError('The ifi_command must be one of: "-M", "-S", "-O", "-A"') @@ -246,7 +246,7 @@ def _ifi_type_from_command(ifi_command): def _ifi_value_from_command(ifi_value, ifi_type): - """Parse ifi_value returned by cli to generate dict when `ifi_type` is `account`""" + """Parse ifi_value returned by cli to generate dict when `ifi_type` is `account`.""" if ifi_type == "account": # Parse arguments from cli return {"name": ifi_value.split()[0], "homePage": ifi_value.split()[1]} @@ -436,7 +436,7 @@ def test_cli_auth_command_when_writing_auth_file_with_incorrect_auth_file(fs): def test_cli_extract_command_with_gelf_parser(gelf_logger): - """Test the extract command using the GELF parser.""" + """Test ralph extract command using the GELF parser.""" gelf_logger.info('{"username": "foo"}') runner = CliRunner() @@ -449,7 +449,7 @@ def test_cli_extract_command_with_gelf_parser(gelf_logger): def test_cli_extract_command_with_es_parser(): - """Test the extract command using the ElasticSearchParser.""" + """Test ralph extract command using the ElasticSearchParser.""" es_output = ( "\n".join( [ @@ -476,7 +476,7 @@ def test_cli_extract_command_with_es_parser(): @custom_given(UIPageClose) def test_cli_validate_command_with_edx_format(event): - """Test the validate command using the edx format.""" + """Test ralph validate command using the edx format.""" event_str = event.json() runner = CliRunner() result = runner.invoke(cli, ["validate", "-f", "edx"], input=event_str) @@ -487,7 +487,7 @@ def test_cli_validate_command_with_edx_format(event): @custom_given(UIPageClose) @pytest.mark.parametrize("valid_uuid", ["ee241f8b-174f-5bdb-bae9-c09de5fe017f"]) def test_cli_convert_command_from_edx_to_xapi_format(valid_uuid, event): - """Test the convert command from edx to xapi format.""" + """Test ralph convert command from edx to xapi format.""" event_str = event.json() runner = CliRunner() command = f"-v ERROR convert -f edx -t xapi -u {valid_uuid} -p https://fun-mooc.fr" @@ -501,8 +501,8 @@ def test_cli_convert_command_from_edx_to_xapi_format(valid_uuid, event): @pytest.mark.parametrize("invalid_uuid", ["", None, 1, {}]) def test_cli_convert_command_with_invalid_uuid(invalid_uuid): - """Test that the convert command raises an exception when the uuid namespace is - invalid. + """Test that the ralph convert command raises an exception when the uuid namespace + is invalid. """ runner = CliRunner() command = f"convert -f edx -t xapi -u '{invalid_uuid}' -p https://fun-mooc.fr" @@ -531,7 +531,7 @@ def test_cli_verbosity_option_should_impact_logging_behaviour(verbosity): def test_cli_read_command_with_ldp_backend(monkeypatch): - """Test the read command using the LDP backend.""" + """Test ralph read command using the LDP backend.""" archive_content = {"foo": "bar"} def mock_read(*_, **__): @@ -553,7 +553,7 @@ def mock_read(*_, **__): # pylint: disable=invalid-name # pylint: disable=unused-argument def test_cli_read_command_with_fs_backend(fs, monkeypatch): - """Test the read command using the FS backend.""" + """Test ralph read command using the FS backend.""" archive_content = {"foo": "bar"} def mock_read(*_, **__): @@ -694,7 +694,7 @@ def test_cli_read_command_with_ws_backend(events, ws): def test_cli_list_command_with_ldp_backend(monkeypatch): - """Test the list command using the LDP backend.""" + """Test ralph list command using the LDP backend.""" archive_list = [ "5d5c4c93-04a4-42c5-9860-f51fa4044aa1", "997db3eb-b9ca-485d-810f-b530a6cef7c6", @@ -766,7 +766,7 @@ def mock_list(this, target=None, details=False, new=False): # pylint: disable=invalid-name # pylint: disable=unused-argument def test_cli_list_command_with_fs_backend(fs, monkeypatch): - """Test the list command using the LDP backend.""" + """Test ralph list command using the LDP backend.""" archive_list = [ "file1", "file2", @@ -827,7 +827,7 @@ def mock_list(this, target=None, details=False, new=False): # pylint: disable=invalid-name def test_cli_write_command_with_fs_backend(fs): - """Test the write command using the FS backend.""" + """Test ralph write command using the FS backend.""" fs.create_dir(str(settings.APP_DIR)) fs.create_dir("foo") diff --git a/tests/test_helpers.py b/tests/test_helpers.py index e40b8dff9..d915ed6db 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -140,7 +140,7 @@ def test_helpers_mock_statement_no_input(): def test_helpers_mock_statement_value_input(): - """Test that mocked statement have the expected fields with value input.""" + """Test that mocked statement has the expected fields with value input.""" reference_statement = { "id": str(uuid4()), diff --git a/tests/test_utils.py b/tests/test_utils.py index 654eba3c1..39e9b1ba6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -56,16 +56,16 @@ def test_utils_get_backend_instance(monkeypatch, options, expected): """Test get_backend_instance utility should return the expected result.""" class DummyTestBackendSettings(InstantiableSettingsItem): - """Represents a dummy backend setting.""" + """Represent a dummy backend setting.""" FOO: str = "FOO" # pylint: disable=disallowed-name def get_instance(self, **init_parameters): # pylint: disable=no-self-use - """Returns the init_parameters.""" + """Return the init_parameters.""" return init_parameters class DummyTestBackend(ABC): - """Represents a dummy backend instance.""" + """Represent a dummy backend instance.""" type = "test" name = "dummy" @@ -77,7 +77,7 @@ def __call__(self, *args, **kwargs): # pylint: disable=unused-argument return {} def mock_import_module(*args, **kwargs): # pylint: disable=unused-argument - """""" + """Mock import_module.""" test_module = ModuleType(name="ralph.backends.test.dummy") test_module.DummyTestBackendSettings = DummyTestBackendSettings