def test_init(): """Tests of init command w/o <folder> specified""" runner = CliRunner() """ RUN: agogosml init RESULT: Produces a manifest.json in the current working directory """ with runner.isolated_filesystem(): result = runner.invoke(init.init, input='proj_name') assert result.exit_code == 0 assert os.path.exists('./manifest.json') """ RUN: agogosml init -f RESULT: Overwrites existing manifest.json """ with runner.isolated_filesystem(): _create_test_manifest() prevmd5 = test_utils.md5('./manifest.json') result = runner.invoke(init.init, ['--force'], input='proj_name') assert result.exit_code == 0 assert os.path.exists('./manifest.json') assert prevmd5 != test_utils.md5('./manifest.json') """ RUN: agogosml init RESULT: Fail if manifest.json already exists and should NOT overwite """ with runner.isolated_filesystem(): _create_test_manifest() prevmd5 = test_utils.md5('./manifest.json') result = runner.invoke(init.init, input='proj_name') assert result.exit_code == 1 assert os.path.exists('./manifest.json') assert prevmd5 == test_utils.md5('./manifest.json')
def test_init_folder(): """Tests of init command with <folder> specified""" runner = CliRunner() """ RUN: agogosml init <folder> RESULT: Produces a manifest.json in the right folder. """ with runner.isolated_filesystem(): result = runner.invoke(init.init, ['folder'], input='proj_name') assert result.exit_code == 0 assert os.path.exists('./folder/manifest.json') """ RUN: agogosml init -f <folder> RESULT: Ovewrite a manifest.json in the right folder. """ with runner.isolated_filesystem(): _create_test_manifest('folder') prevmd5 = test_utils.md5('./folder/manifest.json') result = runner.invoke(init.init, ['--force', 'folder'], input='proj_name') assert result.exit_code == 0 assert os.path.exists('./folder/manifest.json') assert prevmd5 != test_utils.md5('./folder/manifest.json') """ RUN: agogosml init <folder> RESULT: Fail if manifest.json already exists in folder & NOT overwite """ with runner.isolated_filesystem(): _create_test_manifest('folder') prevmd5 = test_utils.md5('./folder/manifest.json') result = runner.invoke(init.init, ['folder'], input='proj_name') assert result.exit_code == 1 assert os.path.exists('./folder/manifest.json') assert prevmd5 == test_utils.md5('./folder/manifest.json')
def _get_md5_template_files(files=EXPECTED_OUTPUT_PROJ_FILES, folder='.'): """Get the md5 hashes of the project files. Used to know if files were overwritten""" allmd5 = [] for proj_file in files: outfile = os.path.join(folder, proj_file) allmd5.append(test_utils.md5(outfile)) return allmd5