gpkit.tests package¶
Submodules¶
gpkit.tests.diff_output module¶
Function to diff example output and allow small numerical errors
-
gpkit.tests.diff_output.
diff
(output1, output2, tol=0.001)¶ check that output1 and output2 are same up to small errors in numbers
gpkit.tests.from_paths module¶
Runs each file listed in pwd/TESTS as a test
-
class
gpkit.tests.from_paths.
TestFiles
(methodName='runTest')¶ Bases:
unittest.case.TestCase
Stub to be filled with files in $pwd/TESTS
-
gpkit.tests.from_paths.
add_filetest
(testclass, path)¶ Add test that imports the given path and runs its test() function
TODO: make work for subdirectories, using os.chdir
-
gpkit.tests.from_paths.
clean
(string)¶ Parses string into valid python variable name
https://stackoverflow.com/questions/3303312/ how-do-i-convert-a-string-to-a-valid-variable-name-in-python
-
gpkit.tests.from_paths.
newtest_fn
(name, solver, import_dict, path)¶ Doubly nested callbacks to run the test with getattr(self, name)()
-
gpkit.tests.from_paths.
run
(filename='TESTS', xmloutput=False, skipsolvers=None)¶ Parse and run paths from a given file for each solver
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_evalfn
()¶
-
test_exclude_vector
()¶
-
test_init
()¶ Test Constraint __init__
-
test_link_conflict
()¶ 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
-
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_autosweep
(example)¶
-
test_beam
(example)¶
-
test_debug
(example)¶
-
test_external_sp
(example)¶
-
test_external_sp2
(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_examples.
assert_logtol
(first, second, logtol=1e-06)¶ Asserts that the logs of two arrays have a given abstol
gpkit.tests.t_keydict module¶
Test KeyDict class
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_bounded
()¶
-
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_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
-
gpkit.tests.t_small module¶
Tests for small_classes.py and small_scripts.py
gpkit.tests.t_solution_array module¶
Tests for SolutionArray class
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_calcconst
()¶
-
test_getkey
()¶
-
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_bad_gp_sub
()¶
-
test_bad_subinplace
()¶
-
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.
TestTools
(methodName='runTest')¶ Bases:
unittest.case.TestCase
TestCase for math models
-
test_binary_sweep_tree
()¶
-
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_tools.
assert_logtol
(first, second, logtol=1e-06)¶ Asserts that the logs of two arrays have a given abstol
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__
-
gpkit.tests.test_repo module¶
Implements tests for all external repositories.
-
gpkit.tests.test_repo.
call_and_retry
(cmd, max_iterations=5, delay=5)¶ Tries max_iterations times (waiting d each time) to run a command
-
gpkit.tests.test_repo.
get_settings
()¶ Gets settings from a TESTCONFIG file
-
gpkit.tests.test_repo.
git_clone
(repo, branch='master')¶ Tries several times to clone a given repository
-
gpkit.tests.test_repo.
pip_install
(package, local=False)¶ Tries several times to install a pip package
-
gpkit.tests.test_repo.
test_repo
(repo='.', xmloutput=False)¶ Test repository.
If no repo name given, runs in current directory. Otherwise, assumes is in directory above the repo with a shared gpkit-models repository.
-
gpkit.tests.test_repo.
test_repos
(repos=None, xmloutput=False)¶ Get the list of external repos to test, and test.
Module contents¶
GPkit testing module