aboutsummaryrefslogtreecommitdiff
blob: 5f0bd2ddc50ea43bfb64e26b6fefdd4b2a95e9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import importlib
import os
from shutil import rmtree
import unittest

import portage

from pomu.repo.init import init_plain_repo, init_pomu, init_portage_repo
from pomu.repo.repo import pomu_status, portage_repos, pomu_active_repo

REPO_DIR = 'test_repo'
REPO_PATH = os.path.join(os.getcwd(), REPO_DIR)

class PlainRepoInitialization(unittest.TestCase):

    def setUp(self):
        self.REPO_DIR = REPO_DIR

    def tearDown(self):
        rmtree(self.REPO_DIR)

    def testPlainInitializationAndStatus(self):
        init_plain_repo(True, self.REPO_DIR).expect()
        self.assertEqual(pomu_status(self.REPO_DIR), True)

    def testNonGitInitialization(self):
        os.makedirs(self.REPO_DIR)
        self.assertEqual(init_pomu(self.REPO_DIR).err(), 'target repository should be a git repo')

class PortageRepoInitialization(unittest.TestCase):

    def setUp(self):
        os.environ['EROOT'] = REPO_PATH
        os.environ['ROOT'] = REPO_PATH
        os.environ['PORTAGE_CONFIGROOT'] = REPO_PATH
        rcp = os.path.join(REPO_PATH, 'etc/portage/repos.conf')
        os.makedirs(rcp)
        with open(os.path.join(rcp, 'gentoo.conf'), 'w') as f:
            f.write('[DEFAULT]\nmain-repo = gentoo\n[gentoo]\nlocation=/usr/portage\n')
        importlib.reload(portage)
        self.REPO_DIR = REPO_DIR

    def tearDown(self):
        rmtree(REPO_PATH)

    def testRepoList(self):
        self.assertEqual(list(portage_repos()), ['gentoo'])

    def testPortageCreate(self):
        self.assertTrue(init_portage_repo(True, REPO_DIR, REPO_PATH).is_ok())
        importlib.reload(portage)
        self.assertEqual(pomu_active_repo(), REPO_DIR)