コード例 #1
0
ファイル: test_map.py プロジェクト: velocirobbie/greengraph
def test_count_green(mock_string):
    with patch.object(matplotlib.image,'imread') as mock_get:
        with open(os.path.join(os.path.dirname(__file__),'fixtures','green.yaml')) as fixtures_file:
            fixtures=yaml.load(fixtures_file)
            for fixture in fixtures:
                mock_get.return_value = np.array(fixture.pop('pixles'))
                expected_count = fixture.pop('count_answer')
                trial_map = Map('junk','junk')
                actual_count = trial_map.count_green(1)
                assert_equal(expected_count,actual_count)
コード例 #2
0
ファイル: test_map.py プロジェクト: velocirobbie/greengraph
def test_green(mock_string):
    with patch.object(matplotlib.image,'imread') as mock_get:
        with open(os.path.join(os.path.dirname(__file__),'fixtures','green.yaml')) as fixtures_file:
            fixtures=yaml.load(fixtures_file)
            for fixture in fixtures:
                mock_get.return_value = np.array(fixture.pop('pixles'))
                expected_green = fixture.pop('answer')
                trial_map = Map('junk','junk')
                actual_green = trial_map.green(1)
                # cannot assert_equal on arrays, instead loop over elements
                for x in range(2):
                    for y in range(2):
                        assert_equal(expected_green[x][y],actual_green[x][y])
コード例 #3
0
def test_count_green(mock_get, mock_imread, mock_StringIO):

    testMap = Map(lat, lon)

    # Test that the number sum of the green pixels with values greater than
    # the values of both the red and blue pixels is zero for an empty image
    # (zeros everywhere)
    green = np.zeros(size)
    red = np.zeros(size)
    blue = np.zeros(size)
    testMap.pixels = np.dstack((red, green, blue))
    assert_equal(testMap.count_green(), 0)

    # Test that the sum of the green pixels with values greater than the
    # values of both the red and blue pixels is n*m for a n*m*3 array with the
    # value of green pixels equal to one and red/blue pixels equal to zero
    green = np.ones(size)
    testMap.pixels = np.dstack((red, green, blue))
    assert_equal(testMap.count_green(), size[0] * size[1])