Exemple #1
0
def test_gh_url(cookie_cutter_handler, mocked_project):
    from moban.exceptions import FileNotFound

    args = ["yehua", "gh:org/repo"]
    cookie_cutter_handler.side_effect = FileNotFound
    with patch.object(sys, "argv", args):
        main()
        mocked_project.assert_called_with("git://github.com/org/repo.git")
Exemple #2
0
def test_main(copy, save, mkdir, inputs, os_system):
    copy.return_value = 0
    save.return_value = 0
    mkdir.return_value = 0
    inputs.return_value = dict(project_name="test-me")
    main()
    calls = mkdir.call_args_list
    calls = [str(call) for call in calls]
    expected = [
        "call('test-me')",
        "call('test-me/test_me')",
        "call('test-me/tests')",
        "call('test-me/docs')",
        "call('test-me/docs/source')",
        "call('test-me/.moban.d')",
        "call('test-me/.moban.d/tests')",
        "call('test-me/.moban.d/docs')",
        "call('test-me/.moban.d/docs/source')",
    ]
    eq_(calls, expected)
def test_reference_pypi_package(fake_inputs):
    project_name = "project_s"
    fake_inputs.return_value = {
        "full_name": "full_n",
        "email": "email_",
        "github_username": "******",
        "project_name": "project_n",
        "project_slug": "project_s",
        "project_short_description": "project_sd",
        "pypi_username": "******",
        "version": "1.0",
        "use_pytest": "y",
        "use_pypi_deployment_with_travis": "y",
        "add_pyup_badge": "y",
        "command_line_interface": "Click",
        "create_author_file": "y",
        "open_source_license": "MIT license",
    }
    path = "gh:moremoban/cookiecutter-pypackage"
    with patch.object(sys, "argv", ["yh", path]):
        main()

    assert os.path.exists(os.path.join("project_s", ".git"))

    for a_file in find_files("project_s"):
        reference = url_join("tests/fixtures", a_file)
        if ".git" in a_file:
            continue
        if fs.path.basename(a_file) in [
            ".moban.yml",
            "HISTORY.rst",
            ".moban.hashes",
        ]:
            # no way to compare them
            continue
        r = read_unicode(reference)
        a = read_unicode(a_file)
        eq_(r, a, f"{a_file} differs")
        os.unlink(a_file)

    shutil.rmtree(project_name)
def test_github_package(fake_inputs):
    project_name = "git_package_test"
    file_name = "yehua_test"
    fake_inputs.return_value = {
        "directory_name": project_name,
        "file_name": file_name,
        "greeting_recipient": "yehua",
    }

    path = "git://github.com/moremoban/cookiecutter-helloworld.git"
    with patch.object(sys, "argv", ["yh", path]):
        main()

    with open(os.path.join(project_name, f"{file_name}.py")) as f:
        content = f.read()

    assert content == 'print("Hello, yehua!")\n'
    os.unlink(os.path.join(project_name, f"{file_name}.py"))
    os.unlink(os.path.join(project_name, f"{project_name}.yml"))
    os.unlink(os.path.join(project_name, ".moban.yml"))
    os.unlink(os.path.join(project_name, ".moban.hashes"))
    shutil.rmtree(project_name)
def test_local_cookie_cutter_package(fake_inputs):
    project_name = "my_test"
    file_name = "yehua_test"
    fake_inputs.return_value = {
        "directory_name": project_name,
        "file_name": file_name,
        "greeting_recipient": "yehua",
    }

    path = os.path.join("docs", "source", "hello_cookie_cutter")
    with patch.object(sys, "argv", ["yh", path]):
        main()

    with open(os.path.join(project_name, f"{file_name}.py")) as f:
        content = f.read()

    assert content == 'print("Hello, yehua!")\n'
    os.unlink(os.path.join(project_name, f"{file_name}.py"))
    os.unlink(os.path.join(project_name, f"{project_name}.yml"))
    os.unlink(os.path.join(project_name, ".moban.yml"))
    os.unlink(os.path.join(project_name, ".moban.hashes"))
    shutil.rmtree(project_name)
Exemple #6
0
def test_reference_pypi_package(fake_inputs):
    project_name = "project_yehua"
    fake_inputs.return_value = {
        "project_name": project_name,
        "description": "description",
        "license": "mit",
        "author": "author",
        "contact": "contact",
        "organisation": "github",
        "company": "copyright",
        "project_type": "command line interface",
        "cli": "cli",
    }
    with patch.object(sys, "argv", ["yh"]):
        main()

    assert os.path.exists(os.path.join("project_yehua", ".git"))
    shutil.rmtree(os.path.join("project_yehua", ".git"))

    c = dircmp("project_yehua", "tests/fixtures/project_yehua")
    assert len(c.diff_files) == 0, "\n".join(c.diff_files)
    shutil.rmtree("project_yehua")
Exemple #7
0
def test_main(copy, save, mkdir, inputs):
    copy.return_value = 0
    save.return_value = 0
    mkdir.return_value = 0
    inputs.return_value = dict(
        project_name='test-me'
    )
    main()
    calls = mkdir.call_args_list
    calls = [str(call) for call in calls]
    expected = [
        "call('test-me')",
        "call('test-me/test_me')",
        "call('test-me/tests')",
        "call('test-me/docs')",
        "call('test-me/docs/source')",
        "call('test-me/.moban.d')",
        "call('test-me/.moban.d/tests')",
        "call('test-me/.moban.d/docs')",
        "call('test-me/.moban.d/docs/source')"
    ]
    eq_(calls, expected)
Exemple #8
0
from yehua.main import main

if __name__ == "__main__":
    main()
Exemple #9
0
def test_yehua_file_passed_in_command_line():
    args = ["yehua", "/tmp/yehua.yml"]
    with patch("yehua.main.Project") as mocked_project:
        with patch.object(sys, "argv", args):
            main()
            mocked_project.assert_called()
Exemple #10
0
def test_main_help():
    args = ["yehua", "help"]
    with patch("sys.stdout", new_callable=StringIO) as out:
        with patch.object(sys, "argv", args):
            main()
            eq_(out.getvalue(), HELP_TEXT)
Exemple #11
0
def test_yehua_file_passed_in_command_line():
    args = ['yehua', '/tmp/yehua.yml']
    with patch('yehua.main.Project') as mocked_project:
        with patch.object(sys, 'argv', args):
            main()
            mocked_project.assert_called()
Exemple #12
0
def test_main_help():
    args = ['yehua', 'help']
    with patch('sys.stdout', new_callable=StringIO) as out:
        with patch.object(sys, 'argv', args):
            main()
            eq_(out.getvalue(), HELP_TEXT)
Exemple #13
0
def test_a_directory_is_passed_in_command_line():
    args = ["yehua", "/"]
    with patch.object(sys, "argv", args):
        main()