• Stars
    star
    119
  • Rank 287,461 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Genty, pronounced "gen-tee", stands for "generate tests". It promotes generative testing, where a single test can execute over a variety of input.

genty

https://travis-ci.org/box/genty.png?branch=master

About

Genty, pronounced "gen-tee", stands for "generate tests". It promotes generative testing, where a single test can execute over a variety of input. Genty makes this a breeze.

For example, consider a file sample.py containing both the code under test and the tests:

from genty import genty, genty_repeat, genty_dataset
from unittest import TestCase

# Here's the class under test
class MyClass(object):
    def add_one(self, x):
        return x + 1

# Here's the test code
@genty
class MyClassTests(TestCase):
    @genty_dataset(
        (0, 1),
        (100000, 100001),
    )
    def test_add_one(self, value, expected_result):
        actual_result = MyClass().add_one(value)
        self.assertEqual(expected_result, actual_result)

Running the MyClassTests using the default unittest runner

$ python -m unittest -v sample
test_add_one(0, 1) (sample.MyClassTests) ... ok
test_add_one(100000, 100001) (sample.MyClassTests) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

Instead of having to write multiple independent tests for various test cases, code can be refactored and parametrized using genty!

It produces readable tests. It produces maintainable tests. It produces expressive tests.

Another option is running the same test multiple times. This is useful in stress tests or when exercising code looking for race conditions. This particular test

@genty_repeat(3)
def test_adding_one_to_zero(self):
    self.assertEqual(1, MyClass().add_one(0))

would be run 3 times, producing output like

$ python -m unittest -v sample
test_adding_one() iteration_1 (sample.MyClassTests) ... ok
test_adding_one() iteration_2 (sample.MyClassTests) ... ok
test_adding_one() iteration_3 (sample.MyClassTests) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK

The 2 techniques can be combined:

@genty_repeat(2)
@genty_dataset(
    (0, 1),
    (100000, 100001),
)
def test_add_one(self, value, expected_result):
    actual_result = MyClass().add_one(value)
    self.assertEqual(expected_result, actual_result)

There are more options to explore including naming your datasets and genty_args.

@genty_dataset(
    default_case=(0, 1),
    limit_case=(999, 1000),
    error_case=genty_args(-1, -1, is_something=False),
)
def test_complex(self, value1, value2, optional_value=None, is_something=True):
    ...

would run 3 tests, producing output like

$ python -m unittest -v sample
test_complex(default_case) (sample.MyClassTests) ... ok
test_complex(limit_case) (sample.MyClassTests) ... ok
test_complex(error_case) (sample.MyClassTests) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK

The @genty_datasets can be chained together. This is useful, for example, if there are semantically different datasets so keeping them separate would help expressiveness.

@genty_dataset(10, 100)
@genty_dataset('first', 'second')
def test_composing(self, parameter_value):
        ...

would run 4 tests, producing output like

$ python -m unittest -v sample
test_composing(10) (sample.MyClassTests) ... ok
test_composing(100) (sample.MyClassTests) ... ok
test_composing(u'first') (sample.MyClassTests) ... ok
test_composing(u'second') (sample.MyClassTests) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.000s

OK

Sometimes the parameters to a test can't be determined at module load time. For example, some test might be based on results from some http request. And first the test needs to authenticate, etc. This is supported using the @genty_dataprovider decorator like so:

def setUp(self):
    super(MyClassTests, self).setUp()

    # http authentication happens
    # And imagine that _some_function is actually some http request
    self._some_function = lambda x, y: ((x + y), (x - y), (x * y))

@genty_dataset((1000, 100), (100, 1))
def calculate(self, x_val, y_val):
    # when this is called... we've been authenticated
    return self._some_function(x_val, y_val)

@genty_dataprovider(calculate)
def test_heavy(self, data1, data2, data3):
    ...

would run 4 tests, producing output like

$ python -m unittest -v sample
test_heavy_calculate(100, 1) (sample.MyClassTests) ... ok
test_heavy_calculate(1000, 100) (sample.MyClassTests) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

Notice here how the name of the helper (calculate) is added to the names of the 2 executed test cases.

Like @genty_dataset, @genty_dataprovider can be chained together.

Enjoy!

Deferred Parameterization

Parametrized tests where the final parameters are not determined until test execution time. It looks like so:

@genty_dataset((1000, 100), (100, 1))
def calculate(self, x_val, y_val):
    # when this is called... we've been authenticated, perhaps in
    # some Test.setUp() method.

    # Let's imagine that _some_function requires that authentication.
    # And it returns a 3-tuple, matching that signature of
    # of the test(s) decorated with this 'calculate' method.
    return self._some_function(x_val, y_val)

@genty_dataprovider(calculate)
def test_heavy(self, data1, data2, data3):
    ...

The calculate() method is called 2 times based on the @genty_dataset decorator, and each of it's return values define the final parameters that will be given to the method test_heavy(...).

Installation

To install, simply:

pip install genty

Contributing

See CONTRIBUTING.rst.

Setup

Create a virtual environment and install packages -

mkvirtualenv genty
pip install -r requirements-dev.txt

Testing

Run all tests using -

tox

The tox tests include code style checks via pep8 and pylint.

The tox tests are configured to run on Python 2.6, 2.7, 3.3, 3.4, 3.5, and PyPy 2.6.

Copyright and License

Copyright 2015 Box, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

spout

Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
PHP
4,194
star
2

t3js

DEPRECATED - A minimal component-based JavaScript framework
JavaScript
1,560
star
3

Anemometer

Box SQL Slow Query Monitor
JavaScript
1,369
star
4

kube-applier

kube-applier enables automated deployment and declarative configuration for your Kubernetes cluster.
Go
627
star
5

kube-iptables-tailer

A service for better network visibility for your Kubernetes clusters.
Go
538
star
6

box-ui-elements

React Components for Box's Design System and Pluggable Components
JavaScript
532
star
7

box-python-sdk

Box SDK for Python
Python
407
star
8

mojito

An automation platform that enables continuous localization.
Java
354
star
9

flaky

Plugin for nose or pytest that automatically reruns flaky tests.
Python
347
star
10

viewer.js

A viewer for documents converted with the Box View API
JavaScript
335
star
11

stalker

A jQuery plugin allowing elements to follow the user as they scroll a page.
JavaScript
227
star
12

boxcli

A command line interface for interacting with the Box API.
JavaScript
197
star
13

box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5
C#
186
star
14

ClusterRunner

ClusterRunner makes it easy to parallelize test suites across your infrastructure in the fastest and most efficient way possible.
Python
180
star
15

box-node-sdk

A Javascript interface for interacting with the Box API. You can find the node package at
JavaScript
177
star
16

augmented_types

A PHP extension to enforce parameter and return type annotations
C++
166
star
17

bart

A collection of our critical PHP tools
PHP
163
star
18

box-java-sdk

The Box SDK for Java.
Java
153
star
19

memsniff

A tool for recording and displaying statistics on memcached traffic written in golang.
Go
143
star
20

box-ios-sdk

iOS SDK for the Box Content API
Swift
117
star
21

kube-exec-controller

An admission controller service and kubectl plugin to handle container drift in K8s clusters
Go
109
star
22

RainGauge

RainGauge
JavaScript
107
star
23

leche

DEPRECATED - Testing extensions for Mocha and Sinon
JavaScript
103
star
24

box-content-preview

JavaScript library for rendering files stored on Box
JavaScript
100
star
25

box-openapi

OpenAPI 3.0 Specification for the Box APIs
JavaScript
92
star
26

rotunicode

Python library for converting between a string of ASCII and Unicode chars maintaining readability
Python
77
star
27

brainy

A faster, safer templating library for PHP
PHP
66
star
28

mysqlutilities

Box's MySQL Utilities
Shell
65
star
29

samples

Code snippets and samples to demonstrate how to get the most out of the Box platform & API
JavaScript
64
star
30

box-android-sdk

Java
62
star
31

box-android-apptoapp-sdk

This SDK supports Box OneCloud integrations on Android that handle file โ€˜roundtripsโ€™. That is, it enables file open-edit-save scenarios between the Box app and partner apps without the need for partner apps to authenticate a Box user independently.
Java
57
star
32

box-salesforce-sdk

This is the Salesforce SDK for integrating with the Box Platform.
Apex
53
star
33

fast_assert

PHP
37
star
34

StatusWolf

Configurable operations dashboard designed to bring together the disparate datasources that operations teams need to manage and present them in a flexible and beautiful way.
PHP
36
star
35

shmock

SHorthand for MOCKing in PHPUnit
PHP
34
star
36

Makefile.test

A makefile used for running test executables
Python
32
star
37

error-reporting-with-kubernetes-events

A demonstration of how Box utilizes Kubernetes CustomResourceDefinitions and Events
Go
32
star
38

box-skills-kit-nodejs

Official toolkit library and boilerplate code for developing Box Skills.
JavaScript
27
star
39

shalam

DEPRECATED - A friendly tool for CSS spriting
JavaScript
25
star
40

developer.box.com

Box Developer Documentation - Content & Configuration
JavaScript
23
star
41

box-ios-browse-sdk

Objective-C
18
star
42

wavectl

Command Line Client For Wavefront
Python
18
star
43

box-ios-preview-sdk

Box iOS Preview SDK
Swift
17
star
44

clusterrunner-javascript-sdk

ClusterRunner JavaScript SDK that works in both node and browsers
HTML
16
star
45

box-ui-elements-demo

Demo react app for UI Elements
JavaScript
14
star
46

box-python-sdk-gen

Repository for generated Box Python SDK
Python
14
star
47

sdks

SDKs, CLI and other tools for using Box Platform
14
star
48

box-android-preview-sdk

Box Android Preview SDK
Java
13
star
49

box-android-browse-sdk

Java
12
star
50

hdrCompressor

Tool for saving HDR file as RGBM, RGBD, RGBE or LogLuv TGA file.
C
12
star
51

box-typescript-sdk-gen

Repository for generated Box TS SDK
TypeScript
11
star
52

box-annotations

JavaScript library for annotations on files rendered with Box Content Preview
TypeScript
11
star
53

etcdb

Etcd PEP 249 driver.
Python
10
star
54

box-content-preview-demo

Demo React App using the Preview UI Element
JavaScript
8
star
55

box-postman

The official Box Postman Collection
JavaScript
7
star
56

verold.github.io

Verold developer docs and tutorials
JavaScript
5
star
57

box-ios-share-sdk

Objective-C
4
star
58

box-windows-metadata-sdk-v2

Box Metadata C# SDK Plugin
C#
4
star
59

box-dotnet-sdk-gen

Repository for Box .NET autogenerated SDK
C#
4
star
60

uploaders

Write your own custom uploader to send 3D models/textures to Verold Studio.
4
star
61

homebrew-mojito

Homebrew tap for Box/mojito
Ruby
3
star
62

box-developer-changelog

Box Developer Changelog
JavaScript
3
star
63

box-java-sdk-samples

Sample apps for the Box Java SDK.
Java
2
star
64

box-languages

Languages used by other box projects
JavaScript
2
star
65

box-android-share-sdk

Java
2
star
66

puppet-clusterrunner

Installs ClusterRunner using Puppet
Puppet
2
star
67

cla

Landing page for CLA Agreements
1
star