Ejemplo n.º 1
0
    def start(self):
        self._func = self.id().split('.')[-1]
        gx.gx().log('\n' + self._func)
        self._result_dir = os.path.join(self._result_base_dir, self._func)
        result_run_dir = os.path.join(self._result_dir, 'result')
        if os.path.exists(result_run_dir):
            shutil.rmtree(result_run_dir)

        gxu._uuid_callable = self._uuid
        self._unique_id_count = 0
Ejemplo n.º 2
0
    def test_annotate_ll_local(self):
        self.start()

        cs = gxcs.Coordinate_system({
            'type': 'local',
            'lon_lat': (-96, 45),
            'datum': 'nad83',
            'azimuth': -30
        })
        cs = gxcs.Coordinate_system(
            "NAD27 / UTM zone 15N <425000,6500145,0,0,0,-30>")
        name = os.path.join(gx.gx().temp_folder(), "test")
        with gxmap.Map.new(file_name='mapplot_anoxy_rotated_cs_bug_UTM',
                           overwrite=True,
                           data_area=(0, 0, 5000, 3500),
                           coordinate_system=cs,
                           media="A3",
                           margins=(3, 3, 4, 3)) as map:

            mapfile = map.file_name

            map.scale_bar(location=(2, 0, 2), length=6, sections=5)
            map.surround()
            map.annotate_data_xy(grid=gxmap.GRID_LINES)
            map.annotate_data_ll(grid=gxmap.GRID_LINES,
                                 grid_pen=gxg.Pen(line_color='b',
                                                  line_thick=0.025),
                                 text_def=gxg.Text_def(height=0.18,
                                                       italics=True),
                                 top=gxmap.TOP_IN)

            map.surround()

        self.crc_map(mapfile)
        gxmap.delete_files(mapfile)
Ejemplo n.º 3
0
    def test_entitlements(self):
        with gx.gx() as gxc:
            ent = gxc.entitlements()
            self.assertTrue(ent['1000'], 'Oasis montaj™ Base')
            self.assertTrue(gxc.has_entitlement(1000))
            self.assertTrue(gxc.has_entitlement('Oasis montaj™ Base'))
            self.assertTrue(gxc.has_entitlement(2000))
            self.assertTrue(gxc.has_entitlement("ArcGIS"))
            self.assertTrue(gxc.has_entitlement(3000))
            self.assertTrue(gxc.has_entitlement("MapInfo"))
            self.assertFalse(gxc.has_entitlement("bogus"))
            #for e in ent:
            #    print('{}: "{}"'.format(e, ent[e]))

            if gxc.entitled:
                self.assertTrue(
                    gxc.has_entitlement(10000) or gxc.has_entitlement(30000)
                    or gxc.has_entitlement(30101) or gxc.has_entitlement(40000)
                    or gxc.has_entitlement(41000))
            else:
                self.assertTrue(
                    gxc.has_entitlement(1000) and gxc.has_entitlement(2000)
                    and gxc.has_entitlement(3000))
                self.assertFalse(gxc.has_entitlement(10000))
                self.assertFalse(gxc.has_entitlement(30000))
                self.assertFalse(gxc.has_entitlement(30101))
                self.assertFalse(gxc.has_entitlement(40000))
                self.assertFalse(gxc.has_entitlement(41000))
Ejemplo n.º 4
0
    def test_file_manipulation(self):
        self.start()

        fn = gx.gx().temp_file()
        with open(fn, '+w') as f:
            f.write('maki')
        self.assertFalse(gxu.is_file_locked(fn))
        self.assertFalse(gxu.is_path_locked(fn))
        dir = os.path.dirname(fn)
        self.assertFalse(gxu.is_path_locked(dir))
        self.assertTrue(gxu.is_path_locked(dir, age=1000. * 60 * 60))
        self.assertEqual(gxu.file_age('a completely bogus file name'), -1)
        time.sleep(0.1)
        self.assertTrue(gxu.file_age(fn) > 0.)
Ejemplo n.º 5
0
    def test_xml(self):
        self.start()

        d = {'my_root':{'a':1, 'b':'text_string', 'c':(1, 2), 'd':[1, 2, 'txt']},
             'more':{'a':1, 'b':'text_string', 'c':(1, 2), 'd':[1, 2, 'txt']}}
        xml = gxu.xml_from_dict(d, pretty=True)
        dxml = gxu.dict_from_xml(xml)

        self.assertEqual(len(dxml), 2)
        self.assertTrue('my_root' in dxml)
        self.assertEqual(dxml['my_root']['b'], 'text_string')
        self.assertEqual(dxml['my_root']['c'], ['1', '2'])
        self.assertEqual(dxml['my_root']['d'], ['1', '2', 'txt'])
        self.assertEqual(dxml['more']['b'], 'text_string')
        self.assertEqual(dxml['more']['c'], ['1', '2'])
        self.assertEqual(dxml['more']['d'], ['1', '2', 'txt'])

        xml = '<?xml version="1.0" encoding="UTF-8"?>\
                <gmd:MD_Metadata xsi:schemaLocation="http://www.isotc211.org/2005/gmd ../schemas/iso19139fra/gmd/gmd.xsd">\
                    <geosoft xmlns="http://www.geosoft.com/schema/geo">\
                        <dataset version="1" beta="abc">\
                            <title>test_grid_1</title>\
                            <file_format>Geosoft Grid</file_format>\
                        </dataset>\
                    </geosoft>\
                </gmd:MD_Metadata>'
        d = gxu.dict_from_xml(xml)
        self.assertEqual(d['gmd:MD_Metadata']['geosoft']['dataset']['@version'], "1")
        xml = gxu.xml_from_dict(d, pretty=True)
        self.assertTrue('<dataset ' in xml)

        d = {'geosoft': d['gmd:MD_Metadata']['geosoft']}
        d['geosoft'].pop('@xmlns', None)
        xml = gxu.xml_from_dict(d, pretty=True)
        self.assertFalse('xmlns=' in xml)
        xml = gxu.geosoft_xml_from_dict(d, pretty=True)
        self.assertTrue('xmlns=' in xml)
        xml = gxu.geosoft_xml_from_dict(d['geosoft'], pretty=True)
        self.assertTrue('<geosoft xmlns=' in xml)

        folder, files = gsys.unzip(os.path.join(os.path.dirname(self._test_case_py), 'testgrids.zip'),
                                   folder=gx.gx().temp_folder())
        gxml = os.path.join(folder, 'test_grid_1.grd.xml')
        with open(gxml) as f:
            m = gxu.dict_from_xml(f.read())
        xml = gxu.xml_from_dict(m, pretty=True)
        m2 = gxu.dict_from_xml(xml)
        self.assertEqual(m2['gmd:MD_Metadata']['idinfo']['status']['update'], 'None planned')
Ejemplo n.º 6
0
    def test_temp(self):
        with gx.gx() as gxc:
            tf = gxc.temp_folder()
            self.assertTrue(os.path.isdir(tf))

            tf = gxc.temp_file()
            self.assertFalse(os.path.exists(tf))

            tf = gxc.temp_file(ext=".dummy")
            self.assertFalse(os.path.exists(tf))
            self.assertEqual(tf[-6:], ".dummy")
            try:
                with open(tf, 'x'):
                    pass
            except:
                self.assertTrue(False)
Ejemplo n.º 7
0
 def test_env(self):
     with gx.gx() as gxc:
         self.assertFalse(gxc.gid is None)
         self.assertFalse(gxc.current_date is None)
         self.assertFalse(gxc.current_utc_date is None)
         self.assertFalse(gxc.current_time is None)
         self.assertFalse(gxc.current_utc_time is None)
         self.assertFalse(gxc.license_class is None)
         self.assertFalse(gxc.folder_workspace is None)
         self.assertFalse(gxc.folder_temp is None)
         self.assertFalse(gxc.folder_user is None)
         self.assertTrue(gxc.geosoft_version_label)
         self.assertTrue(gxc.geosoft_version_major >= 9)
         self.assertTrue(gxc.geosoft_version_minor >= 0)
         self.assertTrue(gxc.geosoft_version_micro >= 0)
         self.assertTrue(gxc.geosoft_build_label)
         self.assertTrue(gxc.geosoft_build_number)
         self.assertTrue(gxc.geosoft_name)
Ejemplo n.º 8
0
    def test_remove_temp_files(self):
        def make_file(name):
            with open(name, 'w+') as f:
                f.write('ok')

        with gx.gx() as gxc:
            files = []
            for i in range(3):
                fn = gxc.temp_file()
                make_file(fn)
                files.append(fn)

            gxc.remove_stale_temporary_files()
            for f in files:
                self.assertTrue(os.path.exists(f))

            gxc.remove_stale_temporary_files(age=0)
            for f in files:
                self.assertFalse(os.path.exists(f))
Ejemplo n.º 9
0
    def test_from_xml(self):
        self.start()

        temp_grid = gx.gx().temp_file('grd')
        cs = gxcs.Coordinate_system('NAD27 / UTM zone 18N')
        gxgrd.Grid.new(temp_grid,
                       properties={
                           'dtype': np.int16,
                           'nx': 100,
                           'ny': 50,
                           'x0': 4,
                           'y0': 8,
                           'dx': 0.1,
                           'dy': 0.2,
                           'rot': 5,
                           'coordinate_system': cs
                       }).close()
        cs = gxspd.coordinate_system_from_metadata_file(temp_grid)
        self.assertEqual(str(cs), 'NAD27 / UTM zone 18N')

        gxf = cs.gxf.copy()
        gxf[0] = 'crazy'
        gxf[1] = 'weird,6378206.4,0.0822718542230039,0'
        cs = gxcs.Coordinate_system(gxf)
        with gxgrd.Grid.new(temp_grid,
                            overwrite=True,
                            properties={
                                'dtype': np.int16,
                                'nx': 100,
                                'ny': 50,
                                'x0': 4,
                                'y0': 8,
                                'dx': 0.1,
                                'dy': 0.2,
                                'rot': 5,
                                'coordinate_system': cs
                            }) as grd:
            pass
        cs = gxspd.coordinate_system_from_metadata_file(temp_grid)
        self.assertEqual(str(cs), 'weird / UTM zone 18N')

        with gxcs.Coordinate_system('WGS 84') as cs:
            xml = cs.xml
            xml_dict = gxu.dict_from_xml(xml)
            with gxcs.Coordinate_system(xml_dict) as wgs:
                self.assertEqual(str(wgs), 'WGS 84')
        with gxcs.Coordinate_system() as cs:
            cs.xml = xml
            self.assertEqual(str(cs), 'WGS 84')
        with gxcs.Coordinate_system(xml) as cs:
            self.assertEqual(str(cs), 'WGS 84')

        with gxcs.Coordinate_system.local(lon_lat=(-96, 43),
                                          azimuth=25) as csd:
            self.assertEqual(csd.name,
                             'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>')
            self.assertEqual(csd.gxf[2],
                             '"Oblique Stereographic",43,-96,0.9996,0,0')
            xml = csd.xml
            with gxcs.Coordinate_system() as csxml:
                csxml.xml = xml
                self.assertEqual(csxml.name,
                                 'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>')
                self.assertEqual(csxml.gxf[2],
                                 '"Oblique Stereographic",43,-96,0.9996,0,0')
            with gxcs.Coordinate_system(xml) as csxml:
                self.assertEqual(csxml.name,
                                 'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>')
                self.assertEqual(csxml.gxf[2],
                                 '"Oblique Stereographic",43,-96,0.9996,0,0')
Ejemplo n.º 10
0
    def test_media(self):
        self.start()

        def crc_media(map_file, test_number):
            with gxmap.Map.open(map_file) as map:
                with gxv.View(map, "base") as v:
                    with gxg.Draw(v) as g:
                        g.rectangle(v.extent_clip,
                                    pen=gxg.Pen(line_thick=0.2,
                                                line_color='K'))
                with gxv.View(map, "data") as v:
                    with gxg.Draw(v) as g:
                        g.rectangle(v.extent_clip,
                                    pen=gxg.Pen(line_thick=0.2,
                                                line_color='R'))
            self.crc_map(map_file,
                         pix_width=256,
                         alt_crc_name='{}_{}'.format(gxsys.func_name(1),
                                                     test_number))

        test_media_map = os.path.join(gx.gx().temp_folder(), 'test_media')

        test_number = 0
        with gxmap.Map.new(test_media_map + 'scale_800',
                           overwrite=True,
                           scale=800,
                           data_area=(5, 10, 50, 100)) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'scale_100',
                           overwrite=True,
                           scale=100,
                           data_area=(5, 10, 50, 100)) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'a4_portrait',
                           overwrite=True,
                           media='A4',
                           layout=gxmap.MAP_PORTRAIT) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'portrait_a4',
                           overwrite=True,
                           media='a4',
                           fixed_size=True,
                           layout=gxmap.MAP_PORTRAIT) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'a4_landscape',
                           overwrite=True,
                           media='A4',
                           fixed_size=True,
                           layout=gxmap.MAP_LANDSCAPE) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'A4_1',
                           overwrite=True,
                           media='A4',
                           fixed_size=True,
                           data_area=(10, 5, 100, 50)) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'A4_2',
                           overwrite=True,
                           media='A4',
                           fixed_size=True,
                           data_area=(5, 10, 50, 100),
                           layout=gxmap.MAP_LANDSCAPE) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        with gxmap.Map.new(test_media_map + 'A4_3',
                           overwrite=True,
                           media='A4',
                           data_area=(5, 10, 50, 100)) as map:
            file_name = map.file_name
        crc_media(file_name, test_number)
        test_number += 1

        for m in (None, (60, 50), 'unlimited', 'bogus', 'A4', 'A3', 'A2', 'A1',
                  'A0', 'A', 'B', 'C', 'D', 'E'):
            with gxmap.Map.new(media=m) as map:
                pass

        self.assertRaises(gxmap.MapException,
                          gxmap.Map.new,
                          test_media_map,
                          overwrite=True,
                          media='A4',
                          data_area=(100, 50, 10, 5),
                          layout='landscape')
Ejemplo n.º 11
0
 def start(self):
     self._func = self.id().split('.')[-1]
     gx.gx().log('\n' + self._func)
Ejemplo n.º 12
0
 def test_elapsed_time(self):
     with gx.gx() as gxc:
         self.assertTrue(gxc.elapsed_seconds("startup") > 0.0)
         time.sleep(0.25)
         self.assertTrue(gxc.elapsed_seconds("0.25 seconds later") > 0.25)
Ejemplo n.º 13
0
 def test_profile(self):
     self.start()
     with gx.gx() as gxc:
         self.assertTrue(len(gxc.profile_name))
         self.assertTrue(len(gxc.profile_url))