コード例 #1
0
ファイル: test_utilities.py プロジェクト: vck/inasafe
 def test_base_data_dir(self):
     """Test we can get the realtime data dir."""
     data_dir = base_data_dir()
     expected_dir = INASAFE_WORK_DIR
     self.assertTrue(os.path.exists(expected_dir))
     message = 'Got %s, Expectation %s' % (expected_dir, data_dir)
     self.assertEqual(data_dir, expected_dir, message)
コード例 #2
0
ファイル: test_shake_event.py プロジェクト: mahardika/inasafe
    def test_calculate_fatalities(self):
        """Test that we can calculate fatalities."""
        LOGGER.debug(QGIS_APP.showSettings())
        shake_event = ShakeEvent(SHAKE_ID, data_is_local_flag=True)
        result, fatalities_html = shake_event.calculate_impacts()

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()

        expected_result = ('%s/shakemaps-extracted/20131105060809/impact'
                           '-nearest.tif') % inasafe_work_dir
        message = 'Got: %s, Expected: %s' % (result, expected_result)
        self.assertEqual(result, expected_result, message)

        expected_result = ('%s/shakemaps-extracted/20131105060809/impacts'
                           '.html') % inasafe_work_dir

        message = 'Got: %s, Expected: %s' % (fatalities_html, expected_result)
        self.assertEqual(fatalities_html, expected_result, message)

        expected_fatalities = {2: 0.0,
                               3: 0.0,
                               4: 0.000036387775168853676,
                               5: 0.0,
                               6: 0.0,
                               7: 0.0,
                               8: 0.0,
                               9: 0.0}
        message = 'Got: %s, Expected: %s' % (
            shake_event.fatality_counts, expected_fatalities)
        self.assertEqual(
            shake_event.fatality_counts, expected_fatalities, message)
コード例 #3
0
ファイル: test_utilities.py プロジェクト: mahardika/inasafe
 def test_base_data_dir(self):
     """Test we can get the realtime data dir."""
     data_dir = base_data_dir()
     expected_dir = INASAFE_WORK_DIR
     self.assertTrue(os.path.exists(expected_dir))
     message = 'Got %s, Expectation %s' % (expected_dir, data_dir)
     self.assertEqual(data_dir, expected_dir, message)
コード例 #4
0
ファイル: test_shake_event.py プロジェクト: sopac/inasafe
    def test_impacted_cities_table(self):
        """Test getting impacted cities table."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir,
                                 event_id=SHAKE_ID,
                                 data_is_local_flag=True)
        table, path = shake_event.impacted_cities_table()
        table_dict = table.to_dict()
        expected_string = [{
            'name': 'Jayapura',
            'population': '256'
        }, {
            'name': 'Sentani',
            'population': '111'
        }, {
            'name': 'Waris',
            'population': '48'
        }]
        for i in range(1, len(table.rows)):
            self.assertEqual(
                table_dict['rows'][i]['cells'][1]['content']['text'][0]
                ['text'], expected_string[i - 1].get('name'))
            self.assertEqual(
                table_dict['rows'][i]['cells'][2]['content']['text'][0]
                ['text'], expected_string[i - 1].get('population'))

        self.max_diff = None

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_path = os.path.join(
            inasafe_work_dir,
            'shakemaps-extracted/20131105060809/affected-cities.html')
        message = 'Got:\n%s\nExpected:\n%s\n' % (path, expected_path)
        self.assertEqual(path, expected_path, message)
コード例 #5
0
    def test_calculate_fatalities(self):
        """Test that we can calculate fatalities."""
        LOGGER.debug(QGIS_APP.showSettings())
        shake_event = ShakeEvent(SHAKE_ID, data_is_local_flag=True)
        result, fatalities_html = shake_event.calculate_impacts()

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()

        expected_result = ('%s/shakemaps-extracted/20131105060809/impact'
                           '-nearest.tif') % inasafe_work_dir
        message = 'Got: %s, Expected: %s' % (result, expected_result)
        self.assertEqual(result, expected_result, message)

        expected_result = ('%s/shakemaps-extracted/20131105060809/impacts'
                           '.html') % inasafe_work_dir

        message = 'Got: %s, Expected: %s' % (fatalities_html, expected_result)
        self.assertEqual(fatalities_html, expected_result, message)

        expected_fatalities = {2: 0.0,
                               3: 0.0,
                               4: 0.000036387775168847936,
                               5: 0.0,
                               6: 0.0,
                               7: 0.0,
                               8: 0.0,
                               9: 0.0}
        message = 'Got: %s, Expected: %s' % (
            shake_event.fatality_counts, expected_fatalities)
        self.assertEqual(
            shake_event.fatality_counts, expected_fatalities, message)
コード例 #6
0
    def test_fatalities_table(self):
        """Test rendering a fatalities table."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True)
        shake_event.calculate_impacts()
        result = shake_event.impact_table()

        # TODO compare actual content of impact table...

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_result = "%s/shakemaps-extracted/20131105060809/impacts.html" % inasafe_work_dir
        message = "Got:\n%s\nExpected:\n%s" % (result, expected_result)
        self.assertEqual(result, expected_result, message)
コード例 #7
0
    def test_fatalities_table(self):
        """Test rendering a fatalities table."""
        shake_event = ShakeEvent(SHAKE_ID, data_is_local_flag=True)
        shake_event.calculate_impacts()
        result = shake_event.impact_table()

        # TODO compare actual content of impact table...

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_result = (
            '%s/shakemaps-extracted/20131105060809/impacts.html' %
            inasafe_work_dir)
        message = 'Got:\n%s\nExpected:\n%s' % (result, expected_result)
        self.assertEqual(result, expected_result, message)
コード例 #8
0
    def test_impacted_cities_table(self):
        """Test getting impacted cities table."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True)
        table, path = shake_event.impacted_cities_table()
        expected_string = ["<td>Jayapura</td><td>134</td><td>I</td>", "<td>Abepura</td><td>62</td><td>I</td>"]
        table = table.toNewlineFreeString().replace("   ", "")
        for string in expected_string:
            self.assertIn(string, table)

        self.max_diff = None

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_path = "%s/shakemaps-extracted/20131105060809/affected-cities.html" % inasafe_work_dir
        message = "Got:\n%s\nExpected:\n%s\n" % (path, expected_path)
        self.assertEqual(path, expected_path, message)
コード例 #9
0
    def test_impacted_cities_table(self):
        """Test getting impacted cities table."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(
            working_dir=working_dir,
            event_id=SHAKE_ID,
            data_is_local_flag=True)
        table, path = shake_event.impacted_cities_table()
        table_dict = table.to_dict()
        expected_string = [
            {
                'name': 'Jayapura',
                'population': '256'
            },
            {
                'name': 'Sentani',
                'population': '111'
            },
            {
                'name': 'Waris',
                'population': '48'
            }
        ]
        for i in range(1, len(table.rows)):
            self.assertEqual(
                table_dict['rows'][i]['cells'][1]
                ['content']['text'][0]['text'],
                expected_string[i - 1].get('name'))
            self.assertEqual(
                table_dict['rows'][i]['cells'][2]
                ['content']['text'][0]['text'],
                expected_string[i - 1].get('population'))

        self.max_diff = None

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_path = os.path.join(
            inasafe_work_dir,
            'shakemaps-extracted/20131105060809/affected-cities.html')
        message = 'Got:\n%s\nExpected:\n%s\n' % (path, expected_path)
        self.assertEqual(path, expected_path, message)
コード例 #10
0
    def test_impacted_cities_table(self):
        """Test getting impacted cities table."""
        shake_event = ShakeEvent(SHAKE_ID, data_is_local_flag=True)
        table, path = shake_event.impacted_cities_table()
        expected_string = [
            '<td>Jayapura</td><td>134</td><td>I</td>',
            '<td>Abepura</td><td>62</td><td>I</td>']
        table = table.toNewlineFreeString().replace('   ', '')
        for string in expected_string:
            self.assertIn(string, table)

        self.max_diff = None

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()
        expected_path = (
            '%s/shakemaps-extracted/20131105060809/affected-cities.html' %
            inasafe_work_dir)
        message = 'Got:\n%s\nExpected:\n%s\n' % (path, expected_path)
        self.assertEqual(path, expected_path, message)
コード例 #11
0
ファイル: test_shake_event.py プロジェクト: sopac/inasafe
    def test_calculate_fatalities(self):
        """Test that we can calculate fatalities."""
        LOGGER.debug(QGIS_APP.showSettings())
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir,
                                 event_id=SHAKE_ID,
                                 data_is_local_flag=True)
        result, fatalities_html = shake_event.calculate_impacts()

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()

        expected_result = os.path.join(
            inasafe_work_dir,
            'shakemaps-extracted/20131105060809/impact-nearest.tif')
        message = 'Got: %s, Expected: %s' % (result, expected_result)
        self.assertEqual(result, expected_result, message)

        expected_result = os.path.join(
            inasafe_work_dir,
            'shakemaps-extracted/20131105060809/impacts.html')

        message = 'Got: %s, Expected: %s' % (fatalities_html, expected_result)
        self.assertEqual(fatalities_html, expected_result, message)

        expected_fatalities = {
            2: 0.0,
            3: 0.0,
            4: 0.0,
            5: 0.0,
            6: 0.0,
            7: 0.0,
            8: 0.0,
            9: 0.0,
            10: 0.0
        }
        message = 'Got: %s, Expected: %s' % (shake_event.fatality_counts,
                                             expected_fatalities)
        self.assertDictEqual(shake_event.fatality_counts, expected_fatalities,
                             message)
コード例 #12
0
    def test_calculate_fatalities(self):
        """Test that we can calculate fatalities."""
        LOGGER.debug(QGIS_APP.showSettings())
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True)
        result, fatalities_html = shake_event.calculate_impacts()

        # Get the os environment INASAFE_WORK_DIR if it exists
        inasafe_work_dir = base_data_dir()

        expected_result = ("%s/shakemaps-extracted/20131105060809/impact" "-nearest.tif") % inasafe_work_dir
        message = "Got: %s, Expected: %s" % (result, expected_result)
        self.assertEqual(result, expected_result, message)

        expected_result = ("%s/shakemaps-extracted/20131105060809/impacts" ".html") % inasafe_work_dir

        message = "Got: %s, Expected: %s" % (fatalities_html, expected_result)
        self.assertEqual(fatalities_html, expected_result, message)

        expected_fatalities = {2: 0.0, 3: 0.0, 4: 3.6387775168847936e-05, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}
        message = "Got: %s, Expected: %s" % (shake_event.fatality_counts, expected_fatalities)
        self.assertEqual(shake_event.fatality_counts, expected_fatalities, message)
コード例 #13
0
ファイル: test_shake_data.py プロジェクト: SamudraYe/inasafe
import unittest

from realtime.shake_data import ShakeData
from realtime.utilities import (
    shakemap_zip_dir,
    purge_working_data,
    shakemap_extract_dir,
    base_data_dir)
from realtime.test.test_ftp_client import run_monkey_patching_ftp_client

# Clear away working dirs so we can be sure they are
# actually created
purge_working_data()

# The InaSAFE Working Directory
INASAFE_WORK_DIR = base_data_dir()

# Shake ID for this test
SHAKE_ID = '20120726022003'


class TestShakeMap(unittest.TestCase):
    """Testing for the shakemap class"""

    #noinspection PyPep8Naming
    def setUp(self):
        """Copy our cached dataset from the fixture dir to the cache dir."""
        # Run monkey patching to ftp_client
        run_monkey_patching_ftp_client()

        output_file = '20120726022003.out.zip'
コード例 #14
0
ファイル: test_utilities.py プロジェクト: vck/inasafe
from safe.common.utilities import log_file_path
from realtime.utilities import (base_data_dir, shakemap_zip_dir,
                                shakemap_extract_dir, shakemap_data_dir,
                                report_data_dir, is_event_id,
                                purge_working_data, get_path_tail,
                                realtime_logger_name)

# Clear away working dirs so we can be sure they
# are actually created
purge_working_data()

# The logger is initialised in utilities.py by init
LOGGER = logging.getLogger(realtime_logger_name())

# InaSAFE Working Directory
INASAFE_WORK_DIR = base_data_dir()


class UtilsTest(unittest.TestCase):
    def test_base_data_dir(self):
        """Test we can get the realtime data dir."""
        data_dir = base_data_dir()
        expected_dir = INASAFE_WORK_DIR
        self.assertTrue(os.path.exists(expected_dir))
        message = 'Got %s, Expectation %s' % (expected_dir, data_dir)
        self.assertEqual(data_dir, expected_dir, message)

    def test_shakemap_zip_dir(self):
        """Test we can get the shakemap zip dir."""
        data_dir = shakemap_zip_dir()
        expected_dir = os.path.join(INASAFE_WORK_DIR, 'shakemaps-zipped')