def setup(self): super(TestHashVersion, self).setup() self.v = HashVersion() # Create a bunch of files with known content self.create_files({'in': '', 'dep': ''}) self.bundle = self.mkbundle('in', depends=('dep'), output='out')
def test_options(self): """Test customization options.""" hunk = MemoryHunk('foo') assert HashVersion(length=None).determine_version( self.bundle, self.env, hunk) == 'acbd18db4cc2f85cedef654fccc4a4d8' assert HashVersion(length=2).determine_version( self.bundle, self.env, hunk) == 'ac' assert HashVersion(hash=hashlib.sha256).determine_version( self.bundle, self.env, hunk) == '2c26b46b'
class TestHashVersion(TempEnvironmentHelper): def setup(self): super(TestHashVersion, self).setup() self.v = HashVersion() # Create a bunch of files with known content self.create_files({'in': '', 'dep': ''}) self.bundle = self.mkbundle('in', depends=('dep'), output='out') def test_options(self): """Test customization options.""" hunk = MemoryHunk('foo') assert HashVersion(length=None).determine_version( self.bundle, self.env, hunk) == 'acbd18db4cc2f85cedef654fccc4a4d8' assert HashVersion(length=2).determine_version( self.bundle, self.env, hunk) == 'ac' assert HashVersion(hash=hashlib.sha256).determine_version( self.bundle, self.env, hunk) == '2c26b46b' def test_with_hunk(self): # If a hunk is given, the has will be based on it, not the output file self.create_files({self.bundle.output: 'bar'}) hunk = MemoryHunk('foo') assert self.v.determine_version( self.bundle, self.env, hunk) == 'acbd18db' def test_no_placeholder(self): # If output contains no placeholder, the output file will be hashed self.create_files({'out': 'rummpummpum'}) assert self.v.determine_version( self.bundle, self.env, None) == '93667b60' # What if the output file does not exist? (this should not happen, right?) self.unlink('out') assert_raises(IOError, self.v.determine_version, self.bundle, self.env, None) def test_with_placeholder(self): # The HashVersion cannot function in this case. self.bundle.output = 'out-%(version)s' assert_raises(VersionIndeterminableError, self.v.determine_version, self.bundle, self.env, None)
class TestHashVersion(TempEnvironmentHelper): def setup(self): super(TestHashVersion, self).setup() self.v = HashVersion() # Create a bunch of files with known content self.create_files({'in': '', 'dep': ''}) self.bundle = self.mkbundle('in', depends=('dep'), output='out') def test_options(self): """Test customization options.""" hunk = MemoryHunk('foo') assert HashVersion(length=None).determine_version( self.bundle, self.env, hunk) == 'acbd18db4cc2f85cedef654fccc4a4d8' assert HashVersion(length=2).determine_version( self.bundle, self.env, hunk) == 'ac' assert HashVersion(hash=hashlib.sha256).determine_version( self.bundle, self.env, hunk) == '2c26b46b' def test_with_hunk(self): # If a hunk is given, the has will be based on it, not the output file self.create_files({self.bundle.output: 'bar'}) hunk = MemoryHunk('foo') assert self.v.determine_version( self.bundle, self.env, hunk) == 'acbd18db' def test_no_placeholder(self): # If output contains no placeholder, the output file will be hashed self.create_files({'out': 'rummpummpum'}) assert self.v.determine_version( self.bundle, self.env, None) == '93667b60' # What if the output file does not exist? (this should not happen, right?) self.unlink('out') pytest.raises(IOError, self.v.determine_version, self.bundle, self.env, None) def test_with_placeholder(self): # The HashVersion cannot function in this case. self.bundle.output = 'out-%(version)s' pytest.raises(VersionIndeterminableError, self.v.determine_version, self.bundle, self.env, None)