tests/test-propertycache.py
changeset 28839 de7802c3a1df
parent 28838 a9a8b3f29544
child 30559 d83ca854fa21
equal deleted inserted replaced
28838:a9a8b3f29544 28839:de7802c3a1df
     5 regression."""
     5 regression."""
     6 
     6 
     7 from __future__ import absolute_import, print_function
     7 from __future__ import absolute_import, print_function
     8 import os
     8 import os
     9 import subprocess
     9 import subprocess
    10 import mercurial.localrepo
       
    11 import mercurial.util
       
    12 import mercurial.hg
       
    13 import mercurial.ui as uimod
       
    14 
    10 
       
    11 from mercurial import (
       
    12     hg,
       
    13     localrepo,
       
    14     ui as uimod,
       
    15     util,
       
    16 )
    15 
    17 
    16 # create some special property cache that trace they call
    18 # create some special property cache that trace they call
    17 
    19 
    18 calllog = []
    20 calllog = []
    19 @mercurial.util.propertycache
    21 @util.propertycache
    20 def testcachedfoobar(repo):
    22 def testcachedfoobar(repo):
    21     name = repo.filtername
    23     name = repo.filtername
    22     if name is None:
    24     if name is None:
    23         name = ''
    25         name = ''
    24     val = len(name)
    26     val = len(name)
    25     calllog.append(val)
    27     calllog.append(val)
    26     return val
    28     return val
    27 
    29 
    28 unficalllog = []
    30 unficalllog = []
    29 @mercurial.localrepo.unfilteredpropertycache
    31 @localrepo.unfilteredpropertycache
    30 def testcachedunfifoobar(repo):
    32 def testcachedunfifoobar(repo):
    31     name = repo.filtername
    33     name = repo.filtername
    32     if name is None:
    34     if name is None:
    33         name = ''
    35         name = ''
    34     val = 100 + len(name)
    36     val = 100 + len(name)
    35     unficalllog.append(val)
    37     unficalllog.append(val)
    36     return val
    38     return val
    37 
    39 
    38 #plug them on repo
    40 #plug them on repo
    39 mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar
    41 localrepo.localrepository.testcachedfoobar = testcachedfoobar
    40 mercurial.localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
    42 localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
    41 
    43 
    42 
    44 
    43 # Create an empty repo and instantiate it. It is important to run
    45 # Create an empty repo and instantiate it. It is important to run
    44 # these tests on the real object to detect regression.
    46 # these tests on the real object to detect regression.
    45 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
    47 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
    46 assert subprocess.call(['hg', 'init', repopath]) == 0
    48 assert subprocess.call(['hg', 'init', repopath]) == 0
    47 ui = uimod.ui()
    49 ui = uimod.ui()
    48 repo = mercurial.hg.repository(ui, path=repopath).unfiltered()
    50 repo = hg.repository(ui, path=repopath).unfiltered()
    49 
    51 
    50 
    52 
    51 print('')
    53 print('')
    52 print('=== property cache ===')
    54 print('=== property cache ===')
    53 print('')
    55 print('')