Exemple #1
0
 def test_name_correct(self):
     """
     The database should store the name of a stored Variable.
     """
     var = Variable(int, "some_var")
     add_var(self.conn, var)
     df = get_all_rows_variables(self.conn)
     self.assertEqual(df.loc[0, "var_name"], "some_var")
Exemple #2
0
 def test_type_correct(self):
     """
     The database should store a string representation of the type
     of a Variable.
     """
     var = Variable(int, "some_var")
     add_var(self.conn, var)
     df = get_all_rows_variables(self.conn)
     self.assertEqual(df.loc[0, "var_type"], settings.TYPE_TO_STR[int])
Exemple #3
0
 def test_timestamp_correct(self):
     """
     In the database, the timestamp of the moment that the Variable
     was created should be stored.
     It needs to be an epoch time in seconds.
     """
     var = Variable(int, "some_var")
     add_var(self.conn, var)
     df = get_all_rows_variables(self.conn)
     timestamp_now = time.time()
     self.assertLess(timestamp_now - df.loc[0, "timestamp"], 2)
Exemple #4
0
    def test_two_vars_present(self):
        var_1 = Variable(int, "some_int")
        var_2 = Variable(str, "some_str")

        add_var(self.conn, var_1)
        add_var(self.conn, var_2)

        result = get_all_vars(self.conn)
        self.assertEqual(len(result), 2)

        self.assertEqual(var_1, result[0])
        self.assertEqual(var_2, result[1])
Exemple #5
0
    def test_error_if_var_exists(self):
        """
        Each variable name can be added only once.
        A RuntimeError should be raised if two Variables are added with the
        same name. The type of the Variables does not matter.
        """
        var_1 = Variable(int, "some_var")
        var_2 = Variable(str, "some_var")
        add_var(self.conn, var_1)

        with self.assertRaises(RuntimeError):
            add_var(self.conn, var_2)
Exemple #6
0
    def test_empty_table_for_var(self):
        """
        A new, empty, table should be created, with the name of the variable.
        The columns should be 'value' and 'timestamp'.
        """
        var = Variable(int, "some_var")
        add_var(self.conn, var)
        expected_cols = ("value", "timestamp")

        query = """
        SELECT *
        FROM some_var;
        """
        df = pd.read_sql(query, self.conn)

        self.assertTupleEqual(tuple(df.columns), expected_cols)
        self.assertEqual(len(df), 0, "Table should be empty")
Exemple #7
0
 def setUp(self):
     remove_database(TEST_DB_NAME)
     self.conn = connect_to_db(TEST_DB_NAME)
     self.var = Variable(int, "test_var")
     add_var(self.conn, self.var)