Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(description="Setup the build environment for %s"
                                                 % STOIRIDH_PROJECT_NAME)
    prepare_arguments(parser)

    args = parser.parse_args()

    if args.version:
        print(STOIRIDH_PROJECT_VERSION)
        exit(0)

    if args.command == 'init':
        loop = asyncio.get_event_loop()
        sdk = SDK(STOIRIDH_SUPPORTED_VERSIONS)
        if args.force:
            sdk.clean()
        print('There are %d supported version(s) of %s...' % (len(STOIRIDH_SUPPORTED_VERSIONS),
                                                              STOIRIDH_PROJECT_NAME))
        # start the install of the SDK in an asynchronous way
        loop.run_until_complete(sdk.install())
        loop.close()
    else:
        parser.print_help()
Esempio n. 2
0
 def setUp(self):
     self.sdk = SDK(TestSDK.VERSIONS)
Esempio n. 3
0
class TestSDK(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # versions found within the 'data' subdirectory
        cls.VERSIONS = ['1.2.0', '1.1.0']
        cls.STOIRIDH_PROJECT_TEST_DIR = 'StoiridhProject-Test'

        # since there is no official release for now, we'll modify the url of the Stòiridh Qbs
        # Tools in order to be able to test the stoiridh.qbs.tools.SDK class.
        datadir = Path('tests/data').resolve()
        SDK.URL = str(datadir.as_uri()) + '/{version}.tar.gz'

        # modify the SDK's ROOT_DIR class attribute in order to avoid to remove the installed
        # versions of the SDK from a release environment.
        SDK.ROOT_DIR = Path(cls.STOIRIDH_PROJECT_TEST_DIR, 'StoiridhQbsTools')

        if sys.platform.startswith('linux'):
            cls.INSTALL_ROOT_PATH = Path(os.environ['HOME'], '.config', SDK.ROOT_DIR)
        elif sys.platform.startswith('win32'):
            cls.INSTALL_ROOT_PATH = Path(os.environ['APPDATA'], SDK.ROOT_DIR)

        cls.QBS_ROOT_PATH = cls.INSTALL_ROOT_PATH.joinpath('qbs')

    def setUp(self):
        self.sdk = SDK(TestSDK.VERSIONS)

    def tearDown(self):
        # remove the testing root directory each time a test is completed.
        d = TestSDK.INSTALL_ROOT_PATH.parts[-2]

        if TestSDK.INSTALL_ROOT_PATH.exists() and d == TestSDK.STOIRIDH_PROJECT_TEST_DIR:
            shutil.rmtree(str(TestSDK.INSTALL_ROOT_PATH.parent))

    def test_install_root_path(self):
        self.assertEqual(self.sdk.install_root_path, TestSDK.INSTALL_ROOT_PATH)

    def test_qbs_root_path(self):
        self.assertEqual(self.sdk.qbs_root_path, TestSDK.QBS_ROOT_PATH)

    def test_packages(self):
        packages = self.sdk.packages
        self.assertEqual(len(packages), len(TestSDK.VERSIONS))

        for i in range(len(packages)):
            self.assertEqual(packages[i].url,
                             SDK.URL.format(version=TestSDK.VERSIONS[i]))

    def test_noninstalled_packages(self):
        packages = list(self.sdk.noninstalled_packages)
        self.assertEqual(len(packages), len(TestSDK.VERSIONS))

        TestSDK.loop.run_until_complete(self.sdk.install())

        packages = list(self.sdk.noninstalled_packages)
        self.assertEqual(len(packages), 0)

    def test_clean(self):
        self.sdk.clean()
        if TestSDK.QBS_ROOT_PATH.exists():
            self.assertTrue(False)

    def test_install(self):
        TestSDK.loop.run_until_complete(self.sdk.install())

        for version in TestSDK.VERSIONS:
            package = TestSDK.QBS_ROOT_PATH.joinpath(version)
            self.assertTrue(package.exists())