object_function_examples

Script demonstrating how we can use the test helper package to validate object-oriented functions. By default, (i.e., if you do not include any of the optional runtime flags described below) executing this script will run all of the built-in demos for object-oriented tests.

Parameters

—run_empty_class_demobool, default False

Boolean flag for whether the empty class example should be run.

—run_one_int_attr_demobool, default False

Boolean flag for whether the integer attribute class example should be run.

—run_no_attr_one_method_demobool, default False

Boolean flag for whether the class with no attributes and one method example should be run.

—run_one_attr_one_method_demobool, default False

Boolean flag for whether the class with one attribute and one method example should be run.

—run_two_attr_two_method_demobool, default False

Boolean flag for whether the class with two attributes and two methods example should be run.

—run_list_attr_demobool, default False

Boolean flag for whether the list attribute class example should be run.

Module Contents

Classes

EmptyClass

Class with no attributes and no instance methods.

OneIntAttrClass

Class with one integer attribute.

NoAttrOneStatMethodClass

Class with no attributes and one static method.

OneAttrOneMethodClass

Class with one attribute and one get instance method.

TwoAttrTwoMethodClass

Class with two attributes and two get instance methods.

ListAttrClass

Class with one integer list attribute and a get list sum function.

Data

parser

Parser for runtime arguments

args

Parsed runtime arguments

run_empty_class_demo

Runtime flag for whether we should run the empty class (no attributes & no methods) example.

run_one_int_attr_demo

Runtime flag for whether we should run the one integer attribute class example.

run_no_attr_one_method_demo

Runtime flag for whether we should run the no attributes and one static method class example.

run_one_attr_one_method_demo

Runtime flag for whether we should run the one attribute and one method class example.

run_two_attr_two_method_demo

Runtime flag for whether we should run the two attributes and two methods class example.

run_list_attr_demo

Runtime flag for whether we should run the list attribute class example.

any_demos

Boolean for whether any demos were requested by the user (through the runtime arguments).

run_all_demos

Boolean for whether all demos should be run (default behaviour if no specific demos are requested).

API

object_function_examples.parser = 'ArgumentParser(...)'

Parser for runtime arguments

object_function_examples.args = 'parse_args(...)'

Parsed runtime arguments

object_function_examples.run_empty_class_demo = None

Runtime flag for whether we should run the empty class (no attributes & no methods) example.

object_function_examples.run_one_int_attr_demo = None

Runtime flag for whether we should run the one integer attribute class example.

object_function_examples.run_no_attr_one_method_demo = None

Runtime flag for whether we should run the no attributes and one static method class example.

object_function_examples.run_one_attr_one_method_demo = None

Runtime flag for whether we should run the one attribute and one method class example.

object_function_examples.run_two_attr_two_method_demo = None

Runtime flag for whether we should run the two attributes and two methods class example.

object_function_examples.run_list_attr_demo = None

Runtime flag for whether we should run the list attribute class example.

object_function_examples.any_demos = None

Boolean for whether any demos were requested by the user (through the runtime arguments).

object_function_examples.run_all_demos = None

Boolean for whether all demos should be run (default behaviour if no specific demos are requested).

class object_function_examples.EmptyClass

Class with no attributes and no instance methods.

Initialization

Empty class constructor.

class object_function_examples.OneIntAttrClass(int_val)

Class with one integer attribute.

Attributes

int_valint

Integer attribute value.

Initialization

OneIntAttrClass constructor.

Parameters

int_valint

The integer that should be stored in the new object.

__eq__(other)

Equality instance method (checks equality with another object).

This equality function concludes that two OneIntAttrClass instances are equal if their integer attributes are equal. Parameters ———- other : OneIntAttrClass

The other instance of this class (which contains the integer attribute that must be compared against the attribute value of the calling object).

Returns

bool

Returns True if the two instance have the same integer attribute value.

__str__()

Convert-to-string instance method.

class object_function_examples.NoAttrOneStatMethodClass

Class with no attributes and one static method.

Initialization

NoAttrOneStatMethodClass constructor (empty).

static return_zero()

Static method that always returns zero.

class object_function_examples.OneAttrOneMethodClass(int_val)

Class with one attribute and one get instance method.

Initialization

OneAttrOneMethodClass constructor.

Parameters

int_valint

The integer that should be stored in the new object.

return_int_val()

Get method for the integer attribute.

__eq__(other)

Equality instance method (checks equality with another object).

This equality function concludes that two OneAttrOneMethodClass instances are equal if their integer attributes are equal.

Parameters

otherOneAttrOneMethodClass

The other instance of this class (which contains the integer attribute that must be compared against the attribute value of the calling object).

__str__()

Convert-to-string instance method.

class object_function_examples.TwoAttrTwoMethodClass(int_val, str_val)

Class with two attributes and two get instance methods.

Attributes

int_valint

An integer attribute.

str_valstr

A string attribute.

Initialization

TwoAttrTwoMethodClass constructor.

Parameters

int_valint

The integer that should be stored in the new object.

str_valstr

The string that should be stored in the new object.

return_int_val()

Get method for the integer attribute.

return_str_val()

Get method for the string attribute.

__eq__(other)

Equality instance method (checks equality with another object).

This equality function concludes that two TwoAttrTwoMethodClass instances are equal if their integer attributes and their string attributes are both identical.

Parameters

otherTwoAttrTwoMethodClass

The other instance of this class (which contains the integer and string attributes that must be compared against the attributes values of the calling object).

Returns

bool

Returns True if the two instance have the same integer and string attribute values.

__str__()

Convert-to-string instance method.

class object_function_examples.ListAttrClass(input_list)

Class with one integer list attribute and a get list sum function.

Attributes

my_listlist[int]

A list of integers.

Initialization

ListAttrClass constructor.

Parameters

input_listlist[int]

The list of integers that should be stored in the new object.

__eq__(other)

Equality instance method (checks equality with another object).

This equality function concludes that two TwoAttrTwoMethodClass instances are equal if their integer attributes and their string attributes are both identical.

Parameters

otherListAttrClass

The other instance of this class (which contains the list attribute that must be compared against the list attribute of the calling object).

Returns

bool

Returns True if the two instance have the same integer and string attribute values.

calc_list_sum()

Instance method for calculating the sum of all the values in the integer list.