<s> """<STR_LIT>""" <EOL> from unittest import TestCase <EOL> import os <EOL> from datetime import datetime <EOL> import tempfile , shutil <EOL> from ecohydrolib . context import Context <EOL> from ecohydrolib . metadata import GenericMetadata <EOL> from ecohydrolib . metadata import ClimatePointStation <EOL> from ecohydrolib . metadata import AssetProvenance <EOL> from ecohydrolib . metadata import MetadataVersionError <EOL> class TestMetadata ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . projectDir = tempfile . mkdtemp ( ) <EOL> self . testMetadataPath = os . path . join ( self . projectDir , GenericMetadata . METADATA_FILENAME ) <EOL> if os . path . exists ( self . testMetadataPath ) : <EOL> os . unlink ( self . testMetadataPath ) <EOL> lockFilePath = os . path . join ( self . projectDir , GenericMetadata . METADATA_LOCKFILE ) <EOL> if os . path . exists ( lockFilePath ) : <EOL> os . unlink ( lockFilePath ) <EOL> self . context = Context ( projectDir = self . projectDir ) <EOL> def tearDown ( self ) : <EOL> if os . path . exists ( self . testMetadataPath ) : <EOL> os . unlink ( self . testMetadataPath ) <EOL> lockFilePath = os . path . join ( "<STR_LIT>" , GenericMetadata . METADATA_LOCKFILE ) <EOL> if os . path . exists ( lockFilePath ) : <EOL> os . unlink ( lockFilePath ) <EOL> shutil . rmtree ( self . projectDir ) <EOL> def test_empty_read ( self ) : <EOL> manifest = GenericMetadata . readManifestEntries ( self . context ) <EOL> self . assertTrue ( len ( manifest ) == <NUM_LIT:0> ) <EOL> studyArea = GenericMetadata . readStudyAreaEntries ( self . context ) <EOL> self . assertTrue ( len ( studyArea ) == <NUM_LIT:0> ) <EOL> climatePoint = GenericMetadata . readClimatePointEntries ( self . context ) <EOL> self . assertTrue ( len ( climatePoint ) == <NUM_LIT:0> ) <EOL> climateGrid = GenericMetadata . readClimateGridEntries ( self . context ) <EOL> self . assertTrue ( len ( climateGrid ) == <NUM_LIT:0> ) <EOL> def test_write_and_read ( self ) : <EOL> GenericMetadata . writeManifestEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> GenericMetadata . writeManifestEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> manifest = GenericMetadata . readManifestEntries ( self . context ) <EOL> self . assertTrue ( manifest [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . writeStudyAreaEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> GenericMetadata . writeStudyAreaEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> studyArea = GenericMetadata . readStudyAreaEntries ( self . context ) <EOL> self . assertTrue ( studyArea [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . writeClimatePointEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> GenericMetadata . writeClimatePointEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> climatePoint = GenericMetadata . readClimatePointEntries ( self . context ) <EOL> self . assertTrue ( climatePoint [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . writeClimateGridEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> GenericMetadata . writeClimateGridEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> climateGrid = GenericMetadata . readClimateGridEntries ( self . context ) <EOL> self . assertTrue ( climateGrid [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . writeHydroShareEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> hydroshare = GenericMetadata . readHydroShareEntries ( self . context ) <EOL> self . assertTrue ( hydroshare [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> def test_delete ( self ) : <EOL> GenericMetadata . writeManifestEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> manifest = GenericMetadata . readManifestEntries ( self . context ) <EOL> self . assertTrue ( manifest [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . deleteManifestEntry ( self . context , "<STR_LIT>" ) <EOL> manifest = GenericMetadata . readManifestEntries ( self . context ) <EOL> self . assertTrue ( not '<STR_LIT>' in manifest ) <EOL> GenericMetadata . writeStudyAreaEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> studyArea = GenericMetadata . readStudyAreaEntries ( self . context ) <EOL> self . assertTrue ( studyArea [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . deleteStudyAreaEntry ( self . context , '<STR_LIT>' ) <EOL> studyArea = GenericMetadata . readStudyAreaEntries ( self . context ) <EOL> self . assertTrue ( not '<STR_LIT>' in studyArea ) <EOL> GenericMetadata . writeClimatePointEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> climatePoint = GenericMetadata . readClimatePointEntries ( self . context ) <EOL> self . assertTrue ( climatePoint [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . deleteClimatePointEntry ( self . context , '<STR_LIT>' ) <EOL> climatePoint = GenericMetadata . readClimatePointEntries ( self . context ) <EOL> self . assertTrue ( not '<STR_LIT>' in climatePoint ) <EOL> GenericMetadata . writeClimateGridEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> climateGrid = GenericMetadata . readClimateGridEntries ( self . context ) <EOL> self . assertTrue ( climateGrid [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . deleteClimateGridEntry ( self . context , '<STR_LIT>' ) <EOL> climateGrid = GenericMetadata . readClimateGridEntries ( self . context ) <EOL> self . assertTrue ( not '<STR_LIT>' in climateGrid ) <EOL> GenericMetadata . deleteClimateGridEntry ( self . context , "<STR_LIT>" ) <EOL> GenericMetadata . writeHydroShareEntry ( self . context , "<STR_LIT>" , "<STR_LIT>" ) <EOL> hydroshare = GenericMetadata . readHydroShareEntries ( self . context ) <EOL> self . assertTrue ( hydroshare [ "<STR_LIT>" ] == "<STR_LIT>" ) <EOL> GenericMetadata . deleteHydroShareEntry ( self . context , "<STR_LIT>" ) <EOL> hydroshare = GenericMetadata . readHydroShareEntries ( self . context ) <EOL> self . assertTrue ( not '<STR_LIT>' in hydroshare ) <EOL> def test_write_climate_point1 ( self ) : <EOL> """<STR_LIT>""" <EOL> station = ClimatePointStation ( ) <EOL> station . type = "<STR_LIT>" <EOL> station . id = "<STR_LIT>" <EOL> station . longitude = - <NUM_LIT> <EOL> station . latitude = <NUM_LIT> <EOL> station . elevation = <NUM_LIT> <EOL> station . name = "<STR_LIT>" <EOL> station . data = "<STR_LIT>" <EOL> station . startDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . endDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . variables = [ ClimatePointStation . VAR_PRECIP , ClimatePointStation . VAR_SNOW ] <EOL> station . writeToMetadata ( self . context ) <EOL> climatePointStation = GenericMetadata . readClimatePointStations ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( station . type . lower ( ) == climatePointStation . type ) <EOL> self . assertTrue ( station . id . lower ( ) == climatePointStation . id ) <EOL> self . assertTrue ( station . longitude == climatePointStation . longitude ) <EOL> self . assertTrue ( station . latitude == climatePointStation . latitude ) <EOL> self . assertTrue ( station . elevation == climatePointStation . elevation ) <EOL> self . assertTrue ( station . name == climatePointStation . name ) <EOL> self . assertTrue ( station . data == climatePointStation . data ) <EOL> self . assertTrue ( station . startDate == climatePointStation . startDate ) <EOL> self . assertTrue ( station . endDate == climatePointStation . endDate ) <EOL> self . assertTrue ( station . variables == climatePointStation . variables ) <EOL> def test_write_climate_point1_overwrite ( self ) : <EOL> """<STR_LIT>""" <EOL> station = ClimatePointStation ( ) <EOL> station . type = "<STR_LIT>" <EOL> station . id = "<STR_LIT>" <EOL> station . longitude = - <NUM_LIT> <EOL> station . latitude = <NUM_LIT> <EOL> station . elevation = <NUM_LIT> <EOL> station . name = "<STR_LIT>" <EOL> station . data = "<STR_LIT>" <EOL> station . startDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . endDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . variables = [ ClimatePointStation . VAR_PRECIP , ClimatePointStation . VAR_SNOW ] <EOL> station . writeToMetadata ( self . context ) <EOL> climatePointStation = GenericMetadata . readClimatePointStations ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( station . type . lower ( ) == climatePointStation . type ) <EOL> self . assertTrue ( station . id . lower ( ) == climatePointStation . id ) <EOL> self . assertTrue ( station . longitude == climatePointStation . longitude ) <EOL> self . assertTrue ( station . latitude == climatePointStation . latitude ) <EOL> self . assertTrue ( station . elevation == climatePointStation . elevation ) <EOL> self . assertTrue ( station . name == climatePointStation . name ) <EOL> self . assertTrue ( station . data == climatePointStation . data ) <EOL> self . assertTrue ( station . startDate == climatePointStation . startDate ) <EOL> self . assertTrue ( station . endDate == climatePointStation . endDate ) <EOL> self . assertTrue ( station . variables == climatePointStation . variables ) <EOL> station . longitude = - <NUM_LIT> <EOL> station . latitude = <NUM_LIT> <EOL> station . elevation = <NUM_LIT> <EOL> station . name = "<STR_LIT>" <EOL> station . data = "<STR_LIT>" <EOL> station . startDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . endDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . variables = [ ClimatePointStation . VAR_PRECIP , ClimatePointStation . VAR_SNOW ] <EOL> station . writeToMetadata ( self . context ) <EOL> climatePointStation = GenericMetadata . readClimatePointStations ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( station . type . lower ( ) == climatePointStation . type ) <EOL> self . assertTrue ( station . id . lower ( ) == climatePointStation . id ) <EOL> self . assertTrue ( station . longitude == climatePointStation . longitude ) <EOL> self . assertTrue ( station . latitude == climatePointStation . latitude ) <EOL> self . assertTrue ( station . elevation == climatePointStation . elevation ) <EOL> self . assertTrue ( station . name == climatePointStation . name ) <EOL> self . assertTrue ( station . data == climatePointStation . data ) <EOL> self . assertTrue ( station . startDate == climatePointStation . startDate ) <EOL> self . assertTrue ( station . endDate == climatePointStation . endDate ) <EOL> self . assertTrue ( station . variables == climatePointStation . variables ) <EOL> def test_write_climate_point2 ( self ) : <EOL> """<STR_LIT>""" <EOL> station = ClimatePointStation ( ) <EOL> station . type = "<STR_LIT>" <EOL> station . id = "<STR_LIT>" <EOL> station . longitude = - <NUM_LIT> <EOL> station . latitude = <NUM_LIT> <EOL> station . elevation = <NUM_LIT> <EOL> station . name = "<STR_LIT>" <EOL> station . startDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . endDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station . variables = [ ClimatePointStation . VAR_PRECIP , ClimatePointStation . VAR_SNOW ] <EOL> station . variablesData [ ClimatePointStation . VAR_PRECIP ] = ClimatePointStation . VAR_PRECIP + '<STR_LIT>' <EOL> station . variablesData [ ClimatePointStation . VAR_SNOW ] = ClimatePointStation . VAR_SNOW + '<STR_LIT>' <EOL> station . writeToMetadata ( self . context ) <EOL> station2 = ClimatePointStation ( ) <EOL> station2 . type = "<STR_LIT>" <EOL> station2 . id = "<STR_LIT>" <EOL> station2 . longitude = - <NUM_LIT> <EOL> station2 . latitude = <NUM_LIT> <EOL> station2 . elevation = <NUM_LIT> <EOL> station2 . name = "<STR_LIT>" <EOL> station2 . startDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station2 . endDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> station2 . variables = [ ClimatePointStation . VAR_PRECIP , ClimatePointStation . VAR_SNOW ] <EOL> station2 . variablesData [ ClimatePointStation . VAR_PRECIP ] = ClimatePointStation . VAR_PRECIP + '<STR_LIT>' <EOL> station2 . variablesData [ ClimatePointStation . VAR_SNOW ] = ClimatePointStation . VAR_SNOW + '<STR_LIT>' <EOL> station2 . writeToMetadata ( self . context ) <EOL> climatePointStation = GenericMetadata . readClimatePointStations ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( station . type . lower ( ) == climatePointStation . type ) <EOL> self . assertTrue ( station . id . lower ( ) == climatePointStation . id ) <EOL> self . assertTrue ( station . longitude == climatePointStation . longitude ) <EOL> self . assertTrue ( station . latitude == climatePointStation . latitude ) <EOL> self . assertTrue ( station . elevation == climatePointStation . elevation ) <EOL> self . assertTrue ( station . name == climatePointStation . name ) <EOL> self . assertTrue ( station . startDate == climatePointStation . startDate ) <EOL> self . assertTrue ( station . endDate == climatePointStation . endDate ) <EOL> self . assertTrue ( station . variables == climatePointStation . variables ) <EOL> self . assertTrue ( station . variablesData [ ClimatePointStation . VAR_PRECIP ] == climatePointStation . variablesData [ ClimatePointStation . VAR_PRECIP ] ) <EOL> self . assertTrue ( station . variablesData [ ClimatePointStation . VAR_SNOW ] == climatePointStation . variablesData [ ClimatePointStation . VAR_SNOW ] ) <EOL> def test_provenance ( self ) : <EOL> """<STR_LIT>""" <EOL> asset = AssetProvenance ( ) <EOL> asset . section = GenericMetadata . MANIFEST_SECTION <EOL> asset . name = "<STR_LIT>" <EOL> asset . dcIdentifier = "<STR_LIT>" <EOL> asset . dcSource = "<STR_LIT>" <EOL> asset . dcTitle = "<STR_LIT>" <EOL> asset . dcDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> asset . dcPublisher = "<STR_LIT>" <EOL> asset . dcDescription = "<STR_LIT>" <EOL> asset . writeToMetadata ( self . context ) <EOL> assetProvenance = GenericMetadata . readAssetProvenanceObjects ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( asset . section == assetProvenance . section ) <EOL> self . assertTrue ( asset . name == assetProvenance . name ) <EOL> self . assertTrue ( asset . dcIdentifier == assetProvenance . dcIdentifier ) <EOL> self . assertTrue ( asset . dcSource == assetProvenance . dcSource ) <EOL> self . assertTrue ( asset . dcTitle == assetProvenance . dcTitle ) <EOL> self . assertTrue ( asset . dcDate == assetProvenance . dcDate ) <EOL> self . assertTrue ( asset . dcPublisher == assetProvenance . dcPublisher ) <EOL> self . assertTrue ( asset . dcDescription == assetProvenance . dcDescription ) <EOL> def test_provenance_overwrite ( self ) : <EOL> """<STR_LIT>""" <EOL> asset = AssetProvenance ( ) <EOL> asset . section = GenericMetadata . MANIFEST_SECTION <EOL> asset . name = "<STR_LIT>" <EOL> asset . dcIdentifier = "<STR_LIT>" <EOL> asset . dcSource = "<STR_LIT>" <EOL> asset . dcTitle = "<STR_LIT>" <EOL> asset . dcDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> asset . dcPublisher = "<STR_LIT>" <EOL> asset . dcDescription = "<STR_LIT>" <EOL> asset . writeToMetadata ( self . context ) <EOL> assetProvenance = GenericMetadata . readAssetProvenanceObjects ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( asset . section == assetProvenance . section ) <EOL> self . assertTrue ( asset . name == assetProvenance . name ) <EOL> self . assertTrue ( asset . dcIdentifier == assetProvenance . dcIdentifier ) <EOL> self . assertTrue ( asset . dcSource == assetProvenance . dcSource ) <EOL> self . assertTrue ( asset . dcTitle == assetProvenance . dcTitle ) <EOL> self . assertTrue ( asset . dcDate == assetProvenance . dcDate ) <EOL> self . assertTrue ( asset . dcPublisher == assetProvenance . dcPublisher ) <EOL> self . assertTrue ( asset . dcDescription == assetProvenance . dcDescription ) <EOL> asset . dcIdentifier = '<STR_LIT>' <EOL> asset . dcSource = "<STR_LIT>" <EOL> asset . dcTitle = "<STR_LIT>" <EOL> asset . dcDate = datetime . strptime ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> asset . dcPublisher = "<STR_LIT>" <EOL> asset . dcDescription = "<STR_LIT>" <EOL> asset . writeToMetadata ( self . context ) <EOL> assetProvenance = GenericMetadata . readAssetProvenanceObjects ( self . context ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( asset . section == assetProvenance . section ) <EOL> self . assertTrue ( asset . name == assetProvenance . name ) <EOL> self . assertTrue ( asset . dcIdentifier == assetProvenance . dcIdentifier ) <EOL> self . assertTrue ( asset . dcSource == assetProvenance . dcSource ) <EOL> self . assertTrue ( asset . dcTitle == assetProvenance . dcTitle ) <EOL> self . assertTrue ( asset . dcDate == assetProvenance . dcDate ) <EOL> self . assertTrue ( asset . dcPublisher == assetProvenance . dcPublisher ) <EOL> self . assertTrue ( asset . dcDescription == assetProvenance . dcDescription ) <EOL> def test_processing_history ( self ) : <EOL> """<STR_LIT>""" <EOL> projectDir = "<STR_LIT>" <EOL> step1 = "<STR_LIT>" <EOL> step2 = "<STR_LIT>" <EOL> step3 = "<STR_LIT>" <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step1 ) <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step2 ) <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step3 ) <EOL> history = GenericMetadata . getProcessingHistoryList ( self . context ) <EOL> self . assertTrue ( len ( history ) == <NUM_LIT:3> , "<STR_LIT>" % ( len ( history ) , ) ) <EOL> self . assertTrue ( history [ <NUM_LIT:0> ] == step1 ) <EOL> self . assertTrue ( history [ <NUM_LIT:1> ] == step2 ) <EOL> self . assertTrue ( history [ <NUM_LIT:2> ] == step3 ) <EOL> def test_version_conflict ( self ) : <EOL> """<STR_LIT>""" <EOL> step1 = "<STR_LIT>" <EOL> step2 = "<STR_LIT>" <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step1 ) <EOL> _prevVersion = GenericMetadata . _ecohydrolibVersion <EOL> GenericMetadata . _ecohydrolibVersion = '<STR_LIT>' <EOL> caughtMetadataVersionError = False <EOL> try : <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step2 ) <EOL> except MetadataVersionError : <EOL> caughtMetadataVersionError = True <EOL> self . assertTrue ( caughtMetadataVersionError , "<STR_LIT>" ) <EOL> GenericMetadata . _ecohydrolibVersion = _prevVersion <EOL> def test_check_metadata_version ( self ) : <EOL> """<STR_LIT>""" <EOL> step1 = "<STR_LIT>" <EOL> GenericMetadata . appendProcessingHistoryItem ( self . context , step1 ) <EOL> GenericMetadata . checkMetadataVersion ( self . context . projectDir ) <EOL> _prevVersion = GenericMetadata . _ecohydrolibVersion <EOL> GenericMetadata . _ecohydrolibVersion = '<STR_LIT>' <EOL> caughtMetadataVersionError = False <EOL> try : <EOL> GenericMetadata . checkMetadataVersion ( self . context . projectDir ) <EOL> except MetadataVersionError : <EOL> caughtMetadataVersionError = True <EOL> self . assertTrue ( caughtMetadataVersionError , "<STR_LIT>" ) <EOL> GenericMetadata . _ecohydrolibVersion = _prevVersion </s>
