import sys
import os
from shutil import copyfile
import unittest
from click.testing import CliRunner
sys.path.append("../scripts")
import srcget
from srcget import _make_dest

class TestSrcGet(unittest.TestCase):

    def setUp(self):
        runner = CliRunner()
        result = runner.invoke(srcget.init)
        self.assertEqual(result.exit_code, 0)
        # Use the mokecppsrc.json file
        os.remove('cppsrc.json')
        copyfile('mokecppsrc.json', 'cppsrc.json')

    def test_init(self):
        self.assertTrue( os.path.exists('cppsrc.json'))

    def test_make_dest(self):
        destFiles = _make_dest(['single_include/catch.hpp'], 'thirdParty')
        self.assertListEqual(destFiles, ['thirdParty/catch.hpp'])

    def test_install(self):
        runner = CliRunner()
        result = runner.invoke(srcget.install)
        self.assertEqual(result.exit_code, 0)
        self.assertTrue (os.path.exists('thirdParty/catch/catch.hpp'))
        self.assertTrue (os.path.exists('thirdParty/cliarg/include/cliapp.h'))
        self.assertTrue (os.path.exists('thirdParty/cliarg/include/clicmd.h'))
        self.assertTrue (os.path.exists('thirdParty/cliarg/src/cliapp.cpp'))
        self.assertTrue (os.path.exists('thirdParty/cliarg/src/clicmd.cpp'))

    def tearDown(self):
        os.remove('cppsrc.json')

if __name__ == '__main__':
    unittest.main()


