Completed
Push — master ( eb70ed...446da2 )
by Andy
59s
created

AnniesLasso.tests.TestLassoCannonModel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %
Metric Value
wmc 8
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_init() 0 2 1
A setUp() 0 14 2
A get_model() 0 4 1
A test_remind_myself_to_write_unit_tests_for_these_functions() 0 14 4
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
"""
5
Unit tests for the lasso model class and associated functions.
6
"""
7
8
import numpy as np
9
import unittest
10
from AnniesLasso import lasso, utils
11
12
13
class TestLassoCannonModel(unittest.TestCase):
14
15
    def setUp(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
        # Initialise some faux data and labels.
17
        labels = "ABCDE"
18
        N_labels = len(labels)
19
        N_stars = np.random.randint(1, 500)
20
        N_pixels = np.random.randint(1, 10000)
21
        shape = (N_stars, N_pixels)
22
23
        self.valid_training_labels = np.rec.array(
24
            np.random.uniform(size=(N_stars, N_labels)),
25
            dtype=[(label, '<f8') for label in labels])
26
27
        self.valid_fluxes = np.random.uniform(size=shape)
28
        self.valid_flux_uncertainties = np.random.uniform(size=shape)
29
30
    def get_model(self):
31
        return lasso.LassoCannonModel(
32
            self.valid_training_labels, self.valid_fluxes,
33
            self.valid_flux_uncertainties)
34
35
    def test_init(self):
36
        self.assertIsNotNone(self.get_model())
37
38
    def test_remind_myself_to_write_unit_tests_for_these_functions(self):
39
        m = self.get_model()
40
        m.label_vector = "A + B + C"
41
        self.assertIsNotNone(m.label_vector)
42
43
        with self.assertRaises(NotImplementedError):
44
            m.train()
45
46
        m._trained = True
47
        with self.assertRaises(NotImplementedError):
48
            m.predict(None)
49
50
        with self.assertRaises(NotImplementedError):
51
            m.fit([], [])
52