def __init__(self, t: str, q_list: List[str], v_list: List[str], order_of_integrator: int = 2,
                 verbose: bool = False) -> None:
        """
        We subclass from a base integrator class.
        This way we can abstract away common functionality between integrators.
        """

        Integrator.__init__(self, t, q_list, v_list, verbose, 'Polynomial Integrator')
        Assertions.assert_integer(order_of_integrator, "Order of integrator")
        self.order_of_integrator = order_of_integrator
Exemple #2
0
 def set_time_boundaries(self, t_lim_lower: float, t_lim_upper: float) -> None:
     """
     Set the boundaries in time for the integration.
     :param t_lim_lower: Lower time integration limit.
     :param t_lim_upper: Upper time integration limit.
     """
     Assertions.assert_float(t_lim_lower, 't variable lower limit')
     Assertions.assert_float(t_lim_upper, 't variable upper limit')
     self.t_lim_lower = t_lim_lower
     self.t_lim_upper = t_lim_upper
Exemple #3
0
    def discretise(self, expression, n: int, t_lim_lower: float, t_lim_upper: float) -> None:
        """
        Discretise the function that we provide on an interval [t_lim_lower, t_lim_upper].

        :param expression: Sympy expression for the function we want to discretise.
        :param n: The number of points to determine the system at.
        :param t_lim_lower: Lower time limit to sample our continuous function over.
        :param t_lim_upper: Upper time limit to sample our continuous function over.
        """

        Assertions.assert_integer(n, 'number of points to determine system at')

        self.set_time_boundaries(t_lim_lower, t_lim_upper)
        self.n = n

        self.t_list = np.linspace(t_lim_lower, t_lim_upper, n)
        self.set_expression(expression)
Exemple #4
0
    def validate_integrator(self) -> None:
        """
        Check that all the integrators parameters are as expected.
        """

        Assertions.assert_string(self.t, 'Symbol for time variable')
        Assertions.assert_list_of_strings(self.q_list, 'Generalised coordinates')
        Assertions.assert_list_of_strings(self.v_list, 'Generalised velocities')
        Assertions.assert_dimensions_match(self.q_list, 'Generalised coordinates', self.v_list,
                                           'Generalised velocities')
Exemple #5
0
    def test_assert_list_of_floats(self):
        # Array of strings should pass
        Assertions.assert_list_of_floats([1.0, 2.0, 3.0], 'list of floats')

        # Array including integers should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats(['a', 1],
                                             'list including integer')

        # Array including lists should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats([1.0, [2.0]],
                                             'list with nested list')

        # Passing any type other than a list to the assertion should throw an error
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats('yeet', 'a string')

        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats(1, 2)
Exemple #6
0
    def test_assert_list_of_strings(self):
        # Array of strings should pass
        Assertions.assert_list_of_strings(['a', 'b', 'c,'], 'list of strings')

        # Array including integers should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_strings(['a', 1],
                                              'list including integer')

        # Array including lists should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_strings(['a', ['b']],
                                              'list with nested list')

        # Passing any type other than a list to the assertion should throw an error
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_strings(1, 'an integer')

        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_strings('yess', 'a string')
Exemple #7
0
    def set_initial_conditions(self, q_initial_value_list: List[float], p_initial_value_list: List[float]):
        """
        Set the initial conditions for the integrator.
        :param q_initial_value_list:  List of initial q values.
        :param p_initial_value_list: List of initial v = $\dot{q}$ values.
        """

        Assertions.assert_list_of_floats(q_initial_value_list, 'Initial q values')
        Assertions.assert_dimensions_match(self.q_list, 'q variables', q_initial_value_list, 'Initial q values')

        Assertions.assert_list_of_floats(p_initial_value_list, 'Initial p values')
        Assertions.assert_dimensions_match(self.q_list, 'q variables', p_initial_value_list, 'Initial p values')

        self.q_initial_value_list = q_initial_value_list
        self.p_initial_value_list = p_initial_value_list
Exemple #8
0
    def test_assert_float(self):
        # Floats should pass
        Assertions.assert_float(1.5, 'an integer')

        # Integers should not pass
        with self.assertRaises(AssertionError):
            Assertions.assert_float(1, 'an integer')

        # Strings should not pass
        with self.assertRaises(AssertionError):
            Assertions.assert_float('yeet', 'a string')

        # Lists should not pass
        with self.assertRaises(AssertionError):
            Assertions.assert_float([], 'a list')
Exemple #9
0
    def setup_method(self, method):
        self.current_method = method.__name__
        c = Config()
        self.config = c.prepare()
        browser_conf = self.config["browser"]
        self.browser = browser.Browser(browser_conf, self.config)
        self.driver = self.browser.driver
        self.verification_errors = []
        self.assertions = Assertions(self.driver, self.verification_errors)

        if hasattr(self.browser, "proxy"):
            self.proxy = self.browser.proxy

        self._screenshot_number = 1
Exemple #10
0
    def test_assert_string(self):
        # Strings should pass
        Assertions.assert_string('this string should pass', 'a string')

        # Integers should not pass
        with self.assertRaises(AssertionError):
            Assertions.assert_string(1, 'an integer')

        # Lists should not pass
        with self.assertRaises(AssertionError):
            Assertions.assert_string([], 'a list')
Exemple #11
0
        if 'grid' in cf.__dict__.get(key).items():
            print('grid in cf')


if 'screenshots' in cf['sframe']:
    if cf['sframe']['screenshots']:
        print("has screenshots option")

print(cf)

default_browser = cf["browser"]
print(default_browser)
browser = browser.Browser(default_browser, cf)
driver = browser.driver
verification_errors = []
assertions = Assertions(driver, verification_errors)

print('browser is dict')
print(dir(browser))

if hasattr(browser, 'config'):
    print('has attr config')

if hasattr(browser, 'proxy'):
    print('browser hasattr proxy')
    proxy = browser.proxy
    print('closing proxy')
    proxy.close()

if hasattr(browser, "driver"):
    print('browser hasattr driver')
Exemple #12
0
    def test_assert_dimensions_match(self):
        # List with matching dimensions should pass
        Assertions.assert_dimensions_match(['a', 'n'], 'list 1', ['c', 'd'],
                                           'list 2')

        # Arrays with different dimensions should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_dimensions_match(['a'], 'list 1', ['b', 'c'],
                                               'list 2')

        # Passing in objects that aren't arrays should throw errors
        with self.assertRaises(AssertionError):
            Assertions.assert_dimensions_match('yeet', 'not an array',
                                               ['b', 'c'], 'list 2')

        with self.assertRaises(AssertionError):
            Assertions.assert_dimensions_match(['a', 'b'], 'list 1', 'yeet',
                                               'not an array')

        # Passing in non string descriptions should also throw an error
        with self.assertRaises(AssertionError):
            Assertions.assert_dimensions_match([1], None, [2], 'Description 2')

        with self.assertRaises(AssertionError):
            Assertions.assert_dimensions_match([1], 'Description 1', [2], None)