gpkit.tests package

Submodules

gpkit.tests.helpers module

Convenience classes and functions for unit testing

class gpkit.tests.helpers.NewDefaultSolver(solver)

Bases: object

Creates an environment with a different default solver

class gpkit.tests.helpers.NullFile

Bases: object

A fake file interface that does nothing

close()

Having not written, cease.

write(string)

Do not write, do not pass go.

class gpkit.tests.helpers.StdoutCaptured(logfilepath=None)

Bases: object

Puts everything that would have printed to stdout in a log file instead

gpkit.tests.helpers.generate_example_tests(path, testclasses, solvers=None, newtest_fn=None)

Mutate TestCase class so it behaves as described in TestExamples docstring

path : str
directory containing example modules to test
testclass : class
class that inherits from unittest.TestCase
newtest_fn : function
function that returns new tests. defaults to import_test_and_log_output
solvers : iterable
solvers to run for; or only for default if solvers is None
gpkit.tests.helpers.logged_example_testcase(name, imported, path)

Returns a method for attaching to a unittest.TestCase that imports or reloads module ‘name’ and stores in imported[name]. Runs top-level code, which is typically a docs example, in the process.

Returns a method.

gpkit.tests.helpers.new_test(name, solver, import_dict, path, testfn=None)

logged_example_testcase with a NewDefaultSolver

gpkit.tests.helpers.run_tests(tests, xmloutput=None, verbosity=2)

Default way to run tests, to be used in __main__.

tests: iterable of unittest.TestCase xmloutput: string or None

if not None, generate xml output for continuous integration, with name given by the input string
verbosity: int
verbosity level for unittest.TextTestRunner

gpkit.tests.run_tests module

Script for running all gpkit unit tests

gpkit.tests.run_tests.import_tests()

Get a list of all GPkit unit test TestCases

gpkit.tests.run_tests.run(xmloutput=False, tests=None, unitless=True)

Run all gpkit unit tests.

xmloutput: bool
If true, generate xml output files for continuous integration

gpkit.tests.t_constraints module

Unit tests for Constraint, MonomialEquality and SignomialInequality

class gpkit.tests.t_constraints.TestBounded(methodName='runTest')

Bases: unittest.case.TestCase

Test bounded constraint set

test_substitution_issue905()
class gpkit.tests.t_constraints.TestConstraint(methodName='runTest')

Bases: unittest.case.TestCase

Tests for Constraint class

test_additive_scalar()

Make sure additive scalars simplify properly

test_additive_scalar_gt1()

1 can’t be greater than (1 + something positive)

test_bad_elements()
test_constraintget()
test_equality_relaxation()
test_exclude_vector()
test_init()

Test Constraint __init__

Check that substitution conflicts are flagged during linking.

test_oper_overload()

Test Constraint initialization by operator overloading

class gpkit.tests.t_constraints.TestMonomialEquality(methodName='runTest')

Bases: unittest.case.TestCase

Test monomial equality constraint class

test_inheritance()

Make sure MonomialEquality inherits from the right things

test_init()

Test initialization via both operator overloading and __init__

test_non_monomial()

Try to initialize a MonomialEquality with non-monomial args

test_str()

Test that MonomialEquality.__str__ returns a string

class gpkit.tests.t_constraints.TestSignomialInequality(methodName='runTest')

Bases: unittest.case.TestCase

Test Signomial constraints

test_init()

Test initialization and types

test_posyslt1()
class gpkit.tests.t_constraints.TestTight(methodName='runTest')

Bases: unittest.case.TestCase

Test tight constraint set

test_posyconstr_in_gp()

Tests tight constraint set with solve()

test_posyconstr_in_sp()
test_sigconstr_in_sp()

Tests tight constraint set with localsolve()

gpkit.tests.t_examples module

Unit testing of tests in docs/source/examples

class gpkit.tests.t_examples.TestExamples(methodName='runTest')

Bases: unittest.case.TestCase

To test a new example, add a function called test_$EXAMPLENAME, where $EXAMPLENAME is the name of your example in docs/source/examples without the file extension.

This function should accept two arguments (e.g. ‘self’ and ‘example’). The imported example script will be passed to the second: anything that was a global variable (e.g, “sol”) in the original script is available as an attribute (e.g., “example.sol”)

If you don’t want to perform any checks on the example besides making sure it runs, just put “pass” as the function’s body, e.g.:

def test_dummy_example(self, example):
pass

But it’s good practice to ensure the example’s solution as well, e.g.:

def test_dummy_example(self, example):
self.assertAlmostEqual(example.sol[“cost”], 3.121)
test_beam(example)
test_debug(example)
test_external_sp(example)
test_performance_modeling(example)
test_primal_infeasible_ex1(example)
test_primal_infeasible_ex2(example)
test_relaxation(example)
test_simple_box(example)
test_simple_sp(example)
test_simpleflight(example)
test_sin_approx_example(example)
test_unbounded(example)
test_vectorize(example)
test_water_tank(example)
test_x_greaterthan_1(example)

gpkit.tests.t_keydict module

Test KeyDict class

class gpkit.tests.t_keydict.TestKeyDict(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the KeyDict class

test_dictlike()
test_failed_getattr()
test_getattr()
test_setattr()
test_vector()

gpkit.tests.t_model module

Tests for GP and SP classes

class gpkit.tests.t_model.Box(cost=None, constraints=None, *args, **kwargs)

Bases: gpkit.constraints.model.Model

simple box for model testing

setup()
class gpkit.tests.t_model.BoxAreaBounds(cost=None, constraints=None, *args, **kwargs)

Bases: gpkit.constraints.model.Model

for testing functionality of separate analysis models

setup(box)
class gpkit.tests.t_model.TestGP(methodName='runTest')

Bases: unittest.case.TestCase

Test GeometricPrograms. This TestCase gets run once for each installed solver.

name = 'TestGP_'
ndig = None
solver = None
test_601()
test_additive_constants()
test_constants_in_objective_1()

Issue 296

test_constants_in_objective_2()

Issue 296

test_cost_freeing()

Test freeing a variable that’s in the cost.

test_exps_is_tuple()

issue 407

test_mdd_example()
test_posy_simplification()

issue 525

test_sigeq()
test_simple_united_gp()
test_singular()

Create and solve GP with a singular A matrix

test_terminating_constant_()
test_trivial_gp()
Create and solve a trivial GP:
minimize x + 2y subject to xy >= 1

The global optimum is (x, y) = (sqrt(2), 1/sqrt(2)).

test_trivial_vector_gp()

Create and solve a trivial GP with VectorVariables

test_zero_lower_unbounded()
test_zeroing()
class gpkit.tests.t_model.TestModelNoSolve(methodName='runTest')

Bases: unittest.case.TestCase

model tests that don’t require a solver

test_modelname_added()
test_no_naming_on_var_access()
class gpkit.tests.t_model.TestModelSolverSpecific(methodName='runTest')

Bases: unittest.case.TestCase

test cases run only for specific solvers

test_cvxopt_kwargs()
class gpkit.tests.t_model.TestSP(methodName='runTest')

Bases: unittest.case.TestCase

test case for SP class – gets run for each installed solver

name = 'TestSP_'
ndig = None
solver = None
test_initially_infeasible()
test_issue180()
test_partial_sub_signomial()

Test SP partial x0 initialization

test_relaxation()
test_sigs_not_allowed_in_cost()
test_small_named_signomial()
test_sp_initial_guess_sub()
test_sp_substitutions()
test_trivial_sp()
test_trivial_sp2()
test_unbounded_debugging()

Test nearly-dual-feasible problems

test_values_vs_subs()
class gpkit.tests.t_model.Thing(cost=None, constraints=None, *args, **kwargs)

Bases: gpkit.constraints.model.Model

a thing, for model testing

setup(length)
gpkit.tests.t_model.test

alias of TestSP_cvxopt

gpkit.tests.t_model.testcase

alias of TestSP

gpkit.tests.t_nomial_array module

Tests for NomialArray class

class gpkit.tests.t_nomial_array.TestNomialArray(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the NomialArray class. Also tests VectorVariable, since VectorVariable returns a NomialArray

test_array_mult()
test_constraint_gen()
test_elementwise_mult()
test_empty()
test_getitem()
test_left_right()
test_ndim()
test_outer()
test_prod()
test_shape()
test_substition()
test_sum()
test_units()

gpkit.tests.t_nomials module

Tests for Monomial, Posynomial, and Signomial classes

class gpkit.tests.t_nomials.TestMonomial(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the Monomial class

test_div()

Test Monomial division

test_eq_ne()

Test equality and inequality comparators

test_init()

Test multiple ways to create a Monomial

test_latex()

Test latex string creation

test_mul()

Test monomial multiplication

test_numerical_precision()

not sure what to test here, placeholder for now

test_pow()

Test Monomial exponentiation

test_repr()

Simple tests for __repr__, which prints more than str

test_str_with_units()

Make sure __str__() works when units are involved

test_units()

make sure multiplication with units works (issue 492)

class gpkit.tests.t_nomials.TestPosynomial(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the Posynomial class

test_constraint_gen()

Test creation of Constraints via operator overloading

test_diff()

Test differentiation (!!)

test_eq()

Test Posynomial __eq__

test_eq_units()
test_init()

Test Posynomial construction

test_integer_division()

Make sure division by integer doesn’t use Python integer division

test_mono_lower_bound()

Test monomial approximation

test_posyposy_mult()

Test multiplication of Posynomial with Posynomial

test_simplification()

Make sure like monomial terms get automatically combined

class gpkit.tests.t_nomials.TestSignomial(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the Signomial class

test_eq_ne()

Test Signomial equality and inequality operators

test_init()

Test Signomial construction

gpkit.tests.t_small module

Tests for small_classes.py and small_scripts.py

class gpkit.tests.t_small.TestHashVector(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the HashVector class

test_init()

Make sure HashVector acts like a dict

test_mul_add()

Test multiplication and addition

test_neg()

Test negation

test_pow()

Test exponentiation

class gpkit.tests.t_small.TestSmallScripts(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for gpkit.small_scripts

test_pint_366()
test_unitstr()

gpkit.tests.t_solution_array module

Tests for SolutionArray class

class gpkit.tests.t_solution_array.TestResultsTable(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for results_table()

test_nan_printing()

Test that solution prints when it contains nans

test_result_access()
class gpkit.tests.t_solution_array.TestSolutionArray(methodName='runTest')

Bases: unittest.case.TestCase

Unit tests for the SolutionArray class

test_call()
test_call_time()
test_call_units()
test_call_vector()
test_subinto()
test_table()
test_units_sub()

gpkit.tests.t_sub module

Test substitution capability across gpkit

class gpkit.tests.t_sub.TestGPSubs(methodName='runTest')

Bases: unittest.case.TestCase

Test substitution for Model and GP objects

test_getkey()
test_linked_sweep()
test_model_composition_units()
test_model_recursion()
test_persistence()
test_phantoms()
test_skipfailures()
test_united_sub_sweep()
test_vector_init()
test_vector_sweep()

Test sweep involving VectorVariables

class gpkit.tests.t_sub.TestNomialSubs(methodName='runTest')

Bases: unittest.case.TestCase

Test substitution for nomial-family objects

test_basic()

Basic substitution, symbolic

test_dimensionless_units()
test_numeric()

Basic substitution of numeric value

test_quantity_sub()
test_scalar_units()
test_signomial()

Test Signomial substitution

test_string_mutation()
test_unitless_monomial_sub()

Tests that dimensionless and undimensioned subs can interact.

test_variable()

Test special single-argument substitution for Variable

test_vector()

gpkit.tests.t_tools module

Tests for tools module

class gpkit.tests.t_tools.TestMathModels(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for math models

test_composite_objective()
test_fmincon_generator()

Test fmincon comparison tool

test_te_exp_minus1()

Test Taylor expansion of e^x - 1

test_te_secant()

Test Taylor expansion of secant(var)

test_te_tangent()

Test Taylor expansion of tangent(var)

gpkit.tests.t_vars module

Test VarKey, Variable, VectorVariable, and ArrayVariable classes

class gpkit.tests.t_vars.TestArrayVariable(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the ArrayVariable class

test_is_vector_variable()

Make sure ArrayVariable is a shortcut to VectorVariable (we want to know if this changes).

test_str()

Make sure string looks something like a numpy array

class gpkit.tests.t_vars.TestVarKey(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the VarKey class

test_dict_key()

make sure variables are well-behaved dict keys

test_eq_neq()

Test boolean equality operators

test_init()

Test VarKey initialization

test_repr()

Test __repr__ method

test_units_attr()

Make sure VarKey objects have a units attribute

class gpkit.tests.t_vars.TestVariable(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the Variable class

test_hash()

Hashes should collide independent of units

test_init()

Test Variable initialization

test_unit_parsing()
test_value()

Detailed tests for value kwarg of __init__

class gpkit.tests.t_vars.TestVectorVariable(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for the VectorVariable class. Note: more relevant tests in t_posy_array.

test_constraint_creation_units()
test_init()

Test VectorVariable initialization

class gpkit.tests.t_vars.TestVectorize(methodName='runTest')

Bases: unittest.case.TestCase

TestCase for gpkit.vectorize

test_shapes()

Module contents

GPkit testing module