13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests of the dirstate functionality being built for WorkingTreeFormat4."""
1617
1616
class InstrumentedDirState(dirstate.DirState):
1618
1617
"""An DirState with instrumented sha1 functionality."""
1620
def __init__(self, path, sha1_provider):
1621
super(InstrumentedDirState, self).__init__(path, sha1_provider)
1619
def __init__(self, path):
1620
super(InstrumentedDirState, self).__init__(path)
1622
1621
self._time_offset = 0
1624
1623
# member is dynamically set in DirState.__init__ to turn on trace
1625
self._sha1_provider = sha1_provider
1626
1624
self._sha1_file = self._sha1_file_and_log
1628
1626
def _sha_cutoff_time(self):
1632
1630
def _sha1_file_and_log(self, abspath):
1633
1631
self._log.append(('sha1', abspath))
1634
return self._sha1_provider.sha1(abspath)
1632
return osutils.sha_file_by_name(abspath)
1636
1634
def _read_link(self, abspath, old_link):
1637
1635
self._log.append(('read_link', abspath, old_link))
2228
2221
inv_entry.symlink_target = u'link-target'
2229
2222
details = self.assertDetails(('l', 'link-target', 0, False,
2230
2223
'link-revision-id'), inv_entry)
2233
class TestSHA1Provider(TestCaseInTempDir):
2235
def test_sha1provider_is_an_interface(self):
2236
p = dirstate.SHA1Provider()
2237
self.assertRaises(NotImplementedError, p.sha1, "foo")
2238
self.assertRaises(NotImplementedError, p.stat_and_sha1, "foo")
2240
def test_defaultsha1provider_sha1(self):
2241
text = 'test\r\nwith\nall\rpossible line endings\r\n'
2242
self.build_tree_contents([('foo', text)])
2243
expected_sha = osutils.sha_string(text)
2244
p = dirstate.DefaultSHA1Provider()
2245
self.assertEqual(expected_sha, p.sha1('foo'))
2247
def test_defaultsha1provider_stat_and_sha1(self):
2248
text = 'test\r\nwith\nall\rpossible line endings\r\n'
2249
self.build_tree_contents([('foo', text)])
2250
expected_sha = osutils.sha_string(text)
2251
p = dirstate.DefaultSHA1Provider()
2252
statvalue, sha1 = p.stat_and_sha1('foo')
2253
self.assertTrue(len(statvalue) >= 10)
2254
self.assertEqual(len(text), statvalue.st_size)
2255
self.assertEqual(expected_sha, sha1)