Skip to main content

Rackslab Foundation Library: build package

Project description

RFL: build package

Utilities to help backport builds of Python projects.

rfl.build.testing subpackage

The rfl.build.testing subpackage provides reusable helpers for writing unit tests in downstream projects. It is installable library code shipped with RFL.build.

This is distinct from rfl.tests under src/build/rfl/tests/, which contains unit tests for the build package itself.

Unittest parameterization (rfl.build.testing.params)

The params module provides the expand decorator to run the same test logic with multiple argument sets, as a maintained alternative to the unmaintained third-party parameterized library.

Import:

from rfl.build.testing.params import expand

Apply expand on a test method with a case list. Each case is passed as positional arguments to the method (a scalar is wrapped in a one-tuple):

import unittest

from rfl.build.testing.params import expand


class TestValues(unittest.TestCase):
    @expand([1, 2, 3])
    def test_is_positive(self, value):
        self.assertGreater(value, 0)

cases may be an iterable or a callable returning an iterable. At decoration time, expand injects one test method per case into the enclosing namespace. The template method is not collected by unittest (__test__ is set to False and the binding is not kept).

Generated names follow {method}_{index:03d}_{slug}, where slug is derived from all case values (for example test_is_positive_001_1 and test_is_positive_002_2).

Options:

  • name_func(func, index, case) — return the generated method name. index is the 1-based case index.
  • skip_on_empty=True — when cases is empty, mark the template as non-runnable instead of raising ValueError.

Example with multiple argument tuples:

class TestApi(unittest.TestCase):
    @expand([("1.0", "a"), ("2.0", "b")])
    def test_response(self, version, variant):
        ...

The result of expand(cases) is itself a decorator and may be assigned to a name to reuse the same case list on several test methods (similar to parameterized.expand):

http_verbs = expand(["get", "post"])


class TestHttpMethods(unittest.TestCase):
    @http_verbs
    def test_endpoint(self, verb):
        response = self.client.open("/resource", method=verb)
        self.assertEqual(response.status_code, 200)

A callable case source works the same way when building a shared decorator:

def version_combinations():
    return [("1.0", "a"), ("2.0", "b")]


all_versions = expand(version_combinations)


class TestApi(unittest.TestCase):
    @all_versions
    def test_response(self, version, variant):
        ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rfl_build-1.8.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rfl_build-1.8.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file rfl_build-1.8.0.tar.gz.

File metadata

  • Download URL: rfl_build-1.8.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rfl_build-1.8.0.tar.gz
Algorithm Hash digest
SHA256 5fefac195813efed50dfac514c20b7713deafa9fd95d8668263cc743984b7767
MD5 a5d6487fed3e94a793da0e1064b775f5
BLAKE2b-256 7ce0efb047ab520229034f0a75a75d1297d0e70867ac1eafba98538d67a22203

See more details on using hashes here.

File details

Details for the file rfl_build-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: rfl_build-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rfl_build-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8924f4b837f9db1f0df76f88905d2ade41958b60285c71afae0a4920d867b276
MD5 3859ad0464a5cc7d00f10c1431f749f1
BLAKE2b-256 60f8170ad53c1deffa1275ac727cc52832db27c67f333a76a7c0dd613dc80f04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page