<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> from hashlib import sha1 <EOL> from pants . backend . jvm . targets . exclude import Exclude <EOL> from pants . backend . jvm . targets . jar_dependency import JarDependency <EOL> from pants . backend . python . python_requirement import PythonRequirement <EOL> from pants . base . payload_field import ( ExcludesField , FingerprintedField , FingerprintedMixin , <EOL> JarsField , PrimitiveField , PythonRequirementsField ) <EOL> from pants_test . base_test import BaseTest <EOL> class PayloadTest ( BaseTest ) : <EOL> def test_excludes_field ( self ) : <EOL> empty = ExcludesField ( ) <EOL> empty_fp = empty . fingerprint ( ) <EOL> self . assertEqual ( empty_fp , empty . fingerprint ( ) ) <EOL> normal = ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT>' ) , Exclude ( '<STR_LIT>' ) ] ) <EOL> normal_fp = normal . fingerprint ( ) <EOL> self . assertEqual ( normal_fp , normal . fingerprint ( ) ) <EOL> normal_dup = ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT>' ) , Exclude ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( normal_fp , normal_dup . fingerprint ( ) ) <EOL> self . assertNotEqual ( empty_fp , normal_fp ) <EOL> def test_jars_field_order ( self ) : <EOL> jar1 = JarDependency ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> jar2 = JarDependency ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertNotEqual ( <EOL> JarsField ( [ jar1 , jar2 ] ) . fingerprint ( ) , <EOL> JarsField ( [ jar2 , jar1 ] ) . fingerprint ( ) , <EOL> ) <EOL> def test_jars_field_apidocs ( self ) : <EOL> """<STR_LIT>""" <EOL> jar1 = JarDependency ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT>' , apidocs = '<STR_LIT>' ) <EOL> jar2 = JarDependency ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT>' , apidocs = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> JarsField ( [ jar1 ] ) . fingerprint ( ) , <EOL> JarsField ( [ jar2 ] ) . fingerprint ( ) , <EOL> ) <EOL> def test_python_requirements_field ( self ) : <EOL> req1 = PythonRequirement ( '<STR_LIT>' ) <EOL> req2 = PythonRequirement ( '<STR_LIT>' ) <EOL> self . assertNotEqual ( <EOL> PythonRequirementsField ( [ req1 ] ) . fingerprint ( ) , <EOL> PythonRequirementsField ( [ req2 ] ) . fingerprint ( ) , <EOL> ) <EOL> def test_primitive_field ( self ) : <EOL> self . assertEqual ( <EOL> PrimitiveField ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) . fingerprint ( ) , <EOL> PrimitiveField ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) . fingerprint ( ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PrimitiveField ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) . fingerprint ( ) , <EOL> PrimitiveField ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) . fingerprint ( ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PrimitiveField ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) . fingerprint ( ) , <EOL> PrimitiveField ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) . fingerprint ( ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PrimitiveField ( '<STR_LIT:foo>' ) . fingerprint ( ) , <EOL> PrimitiveField ( b'<STR_LIT:foo>' ) . fingerprint ( ) , <EOL> ) <EOL> self . assertNotEqual ( <EOL> PrimitiveField ( '<STR_LIT:foo>' ) . fingerprint ( ) , <EOL> PrimitiveField ( '<STR_LIT:bar>' ) . fingerprint ( ) , <EOL> ) <EOL> def test_excludes_field_again ( self ) : <EOL> self . assertEqual ( <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT:foo>' ) ] ) . fingerprint ( ) , <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT:foo>' ) ] ) . fingerprint ( ) , <EOL> ) <EOL> self . assertEqual ( <EOL> ExcludesField ( [ ] ) . fingerprint ( ) , <EOL> ExcludesField ( ) . fingerprint ( ) , <EOL> ) <EOL> self . assertNotEqual ( <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT:foo>' ) ] ) . fingerprint ( ) , <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' ) ] ) . fingerprint ( ) , <EOL> ) <EOL> self . assertNotEqual ( <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT:foo>' ) , Exclude ( '<STR_LIT>' , '<STR_LIT:bar>' ) ] ) . fingerprint ( ) , <EOL> ExcludesField ( [ Exclude ( '<STR_LIT>' , '<STR_LIT:bar>' ) , Exclude ( '<STR_LIT>' , '<STR_LIT:foo>' ) ] ) . fingerprint ( ) , <EOL> ) <EOL> def test_fingerprinted_field ( self ) : <EOL> class TestValue ( FingerprintedMixin ) : <EOL> def __init__ ( self , test_value ) : <EOL> self . test_value = test_value <EOL> def fingerprint ( self ) : <EOL> hasher = sha1 ( ) <EOL> hasher . update ( self . test_value ) <EOL> return hasher . hexdigest ( ) <EOL> field1 = TestValue ( '<STR_LIT>' ) <EOL> field1_same = TestValue ( '<STR_LIT>' ) <EOL> field2 = TestValue ( '<STR_LIT>' ) <EOL> self . assertEquals ( field1 . fingerprint ( ) , field1_same . fingerprint ( ) ) <EOL> self . assertNotEquals ( field1 . fingerprint ( ) , field2 . fingerprint ( ) ) <EOL> fingerprinted_field1 = FingerprintedField ( field1 ) <EOL> fingerprinted_field1_same = FingerprintedField ( field1_same ) <EOL> fingerprinted_field2 = FingerprintedField ( field2 ) <EOL> self . assertEquals ( fingerprinted_field1 . fingerprint ( ) , fingerprinted_field1_same . fingerprint ( ) ) <EOL> self . assertNotEquals ( fingerprinted_field1 . fingerprint ( ) , fingerprinted_field2 . fingerprint ( ) ) <EOL> def test_unimplemented_fingerprinted_field ( self ) : <EOL> class TestUnimplementedValue ( FingerprintedMixin ) : <EOL> pass <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> FingerprintedField ( TestUnimplementedValue ( ) ) . fingerprint ( ) </s>
