|
|
@ -6,9 +6,12 @@ import os |
|
|
|
import shutil |
|
|
|
import unittest |
|
|
|
|
|
|
|
from patacrep.tools import convert |
|
|
|
from patacrep.files import chdir |
|
|
|
from patacrep.tools.__main__ import main as tools_main |
|
|
|
from patacrep.tools.cache.__main__ import main as cache_main |
|
|
|
from patacrep.songbook.__main__ import main as songbook_main |
|
|
|
|
|
|
|
CACHEDIR = os.path.join(os.path.dirname(__file__), "test_cache_datadir", "songs", ".cache") |
|
|
|
CACHEDIR = os.path.join(os.path.dirname(__file__), "test_cache_datadir", ".cache") |
|
|
|
|
|
|
|
class TestCache(unittest.TestCase): |
|
|
|
"""Test of the "patatools cache" subcommand""" |
|
|
@ -16,26 +19,49 @@ class TestCache(unittest.TestCase): |
|
|
|
def setUp(self): |
|
|
|
"""Remove cache.""" |
|
|
|
self._remove_cache() |
|
|
|
self.assertFalse(os.path.exists(CACHEDIR)) |
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
"""Remove cache.""" |
|
|
|
self._remove_cache() |
|
|
|
self.assertFalse(os.path.exists(CACHEDIR)) |
|
|
|
|
|
|
|
def _remove_cache(self): |
|
|
|
@staticmethod |
|
|
|
def _remove_cache(): |
|
|
|
"""Delete cache.""" |
|
|
|
shutil.rmtree(CACHEDIR, ignore_errors=True) |
|
|
|
|
|
|
|
def test_clean(self): |
|
|
|
def _system(self, main, args): |
|
|
|
with chdir(os.path.dirname(__file__)): |
|
|
|
try: |
|
|
|
main(args) |
|
|
|
except SystemExit as systemexit: |
|
|
|
self.assertEqual(systemexit.code, 0) |
|
|
|
|
|
|
|
def test_clean_exists(self): |
|
|
|
"""Test of the "patatools cache clean" subcommand""" |
|
|
|
# Cache does not exist |
|
|
|
self.assertFalse(os.path.exists(CACHEDIR)) |
|
|
|
for main, args in [ |
|
|
|
(tools_main, ["patatools", "cache", "clean", "test_cache.sb"]), |
|
|
|
(cache_main, ["patatools-cache", "clean", "test_cache.sb"]), |
|
|
|
]: |
|
|
|
with self.subTest(main=main, args=args): |
|
|
|
# First compilation. Ensure that cache exists afterwards |
|
|
|
self._system(songbook_main, ["songbook", "test_cache.sb"]) |
|
|
|
self.assertTrue(os.path.exists(CACHEDIR)) |
|
|
|
|
|
|
|
# First compilation. Ensure that cache exists afterwards |
|
|
|
TODO |
|
|
|
self.assertTrue(os.path.exists(CACHEDIR)) |
|
|
|
# Clean cache |
|
|
|
self._system(main, args) |
|
|
|
|
|
|
|
# Clean cache |
|
|
|
TODO |
|
|
|
# Ensure that cache does not exist |
|
|
|
self.assertFalse(os.path.exists(CACHEDIR)) |
|
|
|
|
|
|
|
# Ensure that cache does not exist |
|
|
|
self.assertFalse(os.path.exists(CACHEDIR)) |
|
|
|
def test_clean_not_exists(self): |
|
|
|
"""Test of the "patatools cache clean" subcommand""" |
|
|
|
# Clean non-existent cache |
|
|
|
for main, args in [ |
|
|
|
(tools_main, ["patatools", "cache", "clean", "test_cache.sb"]), |
|
|
|
(cache_main, ["patatools-cache", "clean", "test_cache.sb"]), |
|
|
|
]: |
|
|
|
with self.subTest(main=main, args=args): |
|
|
|
# Clean cache |
|
|
|
self._system(main, args) |
|
|
|