Mercurial > hg-stable
comparison tests/test-simplekeyvaluefile.py @ 32309:ed2c44741190
scmutil: add simplekeyvaluefile reading test
Before this patch, mockvfs did not emulate readlines correctly
and there was no test for simplekeyvaluefile reading.
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Thu, 11 May 2017 08:39:44 -0700 |
parents | c6921568cd20 |
children | 218ca8526ec0 |
comparison
equal
deleted
inserted
replaced
32308:24f55686a63d | 32309:ed2c44741190 |
---|---|
31 | 31 |
32 def read(self, path): | 32 def read(self, path): |
33 return mockfile(path, self).read() | 33 return mockfile(path, self).read() |
34 | 34 |
35 def readlines(self, path): | 35 def readlines(self, path): |
36 return mockfile(path, self).read().split('\n') | 36 # lines need to contain the trailing '\n' to mock the real readlines |
37 return [l for l in mockfile(path, self).read().splitlines(True)] | |
37 | 38 |
38 def __call__(self, path, mode, atomictemp): | 39 def __call__(self, path, mode, atomictemp): |
39 return mockfile(path, self) | 40 return mockfile(path, self) |
40 | 41 |
41 class testsimplekeyvaluefile(unittest.TestCase): | 42 class testsimplekeyvaluefile(unittest.TestCase): |
42 def setUp(self): | 43 def setUp(self): |
43 self.vfs = mockvfs() | 44 self.vfs = mockvfs() |
44 | 45 |
45 def testbasicwriting(self): | 46 def testbasicwritingiandreading(self): |
46 d = {'key1': 'value1', 'Key2': 'value2'} | 47 dw = {'key1': 'value1', 'Key2': 'value2'} |
47 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d) | 48 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(dw) |
48 self.assertEqual(sorted(self.vfs.read('kvfile').split('\n')), | 49 self.assertEqual(sorted(self.vfs.read('kvfile').split('\n')), |
49 ['', 'Key2=value2', 'key1=value1']) | 50 ['', 'Key2=value2', 'key1=value1']) |
51 dr = scmutil.simplekeyvaluefile(self.vfs, 'kvfile').read() | |
52 self.assertEqual(dr, dw) | |
50 | 53 |
51 def testinvalidkeys(self): | 54 def testinvalidkeys(self): |
52 d = {'0key1': 'value1', 'Key2': 'value2'} | 55 d = {'0key1': 'value1', 'Key2': 'value2'} |
53 self.assertRaises(error.ProgrammingError, | 56 self.assertRaises(error.ProgrammingError, |
54 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write, | 57 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write, |