def test_cache_name_change(self, _, __): # pylint: disable=invalid-name """ Make sure file name changes when program name or arguments change """ result1 = utils._get_cache_filename('linter', 'lint1', {}, 'file.txt') result2 = utils._get_cache_filename('linter', 'lint2', {}, 'file.txt') result3 = utils._get_cache_filename('linter', 'lint1', {'args': [1, 2, 3]}, 'file.txt') result4 = utils._get_cache_filename('linter', 'lint2', {}, 'file.txt') self.assertNotEqual(result1, result2) self.assertNotEqual(result1, result3) self.assertNotEqual(result2, result3) self.assertEqual(result2, result4)
def test_get_cache_filename(self, _, __): # pylint: disable=invalid-name # pylint: disable=line-too-long self.assertEqual( '/home/user/.git-lint/cache/e847a69549b9413ce543dfc2a08a26aa2fc76b41', utils._get_cache_filename('linter1', 'lint1', {}, 'bar/file.txt')) self.assertEqual( '/home/user/.git-lint/cache/71262e3079c8f3a3133f9bc5c0f4740bd3db3e2f', utils._get_cache_filename('linter2', 'lint2', {}, 'file.txt')) self.assertEqual( '/home/user/.git-lint/cache/466b0918b56b96a47446546e4cbe15019022666c', utils._get_cache_filename('linter3', 'lint3', {}, '/bar/file.txt'))
def test_get_cache_filename(self): self.fs.create_dir('/abspath') os.chdir('/abspath') with mock.patch('os.path.expanduser', return_value='/home/user'): self.assertEqual( '/home/user/.git-lint/cache/linter1/abspath/bar/file.txt', utils._get_cache_filename('linter1', 'bar/file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter2/abspath/file.txt', utils._get_cache_filename('linter2', 'file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter3/bar/file.txt', utils._get_cache_filename('linter3', '/bar/file.txt'))
def test_save_output_in_cache(self): output = 'Some content' with mock.patch('gitlint.utils._get_cache_filename', return_value='/cache/filename.txt'): utils.save_output_in_cache('linter', 'filename', output) with open(utils._get_cache_filename('linter', 'filename')) as f: self.assertEqual(output, f.read())
def test_save_output_in_cache(self): output = 'Some content' with mock.patch( 'gitlint.utils._get_cache_filename', return_value='/cache/filename.txt'): utils.save_output_in_cache('linter', 'filename', output) with open(utils._get_cache_filename('linter', 'filename')) as f: self.assertEqual(output, f.read())
def test_get_cache_filename(self): self.fs.create_dir('/abspath') os.chdir('/abspath') dummy_hash = utils.calculate_hash("some_tool", []) with mock.patch('os.path.expanduser', return_value='/home/user'): self.assertEqual( '/home/user/.git-lint/cache/linter1.%s/abspath/bar/file.txt' % dummy_hash, utils._get_cache_filename('linter1', dummy_hash, 'bar/file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter2.%s/abspath/file.txt' % dummy_hash, utils._get_cache_filename('linter2', dummy_hash, 'file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter3.%s/bar/file.txt' % dummy_hash, utils._get_cache_filename('linter3', dummy_hash, '/bar/file.txt'))
def test_get_cache_filename(self): def mock_abspath(filename): if os.path.isabs(filename): return filename return '/foo/%s' % filename with mock.patch('os.path.abspath', side_effect=mock_abspath), \ mock.patch('os.path.expanduser', side_effect=lambda a: '/home/user'): self.assertEqual( '/home/user/.git-lint/cache/linter1/foo/bar/file.txt', utils._get_cache_filename('linter1', 'bar/file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter2/foo/file.txt', utils._get_cache_filename('linter2', 'file.txt')) self.assertEqual( '/home/user/.git-lint/cache/linter3/bar/file.txt', utils._get_cache_filename('linter3', '/bar/file.txt'))
def test_save_output_in_cache(self): dummy_hash = utils.calculate_hash("some_tool", []) output = 'Some content' with mock.patch('gitlint.utils._get_cache_filename', return_value='/cache/linter.%s/filename.txt' % dummy_hash): utils.save_output_in_cache('linter', dummy_hash, 'filename', output) with open( utils._get_cache_filename('linter', dummy_hash, 'filename')) as f: self.assertEqual(output, f.read())