Esempio n. 1
0
def test_init_readme_found_yes_choosen():
    responses = [
        'test_module_name',
        'Test Author',
        '*****@*****.**',
        '',  # Home page omitted
        '4',  # Skip - choose a license later
    ]
    with make_dir(["readme.md"]) as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open('rb') as f:
            data = tomli.load(f)

    assert data['project'] == {
        'authors': [{
            'name': 'Test Author',
            'email': '*****@*****.**'
        }],
        'name': 'test_module_name',
        'readme': 'readme.md',
        'dynamic': ['version', 'description'],
    }
Esempio n. 2
0
def test_init():
    responses = [
        'foo',  # Module name
        'Test Author',  # Author
        '*****@*****.**',  # Author email
        'http://example.com/',  # Home page
        '1'  # License (1 -> MIT)
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()

        generated = Path(td) / 'pyproject.toml'
        assert_isfile(generated)
        with generated.open() as f:
            data = toml.load(f)
        assert data['tool']['flit']['metadata'][
            'author-email'] == "*****@*****.**"
        license = Path(td) / 'LICENSE'
        assert_isfile(license)
        with license.open() as f:
            license_text = f.read()
        assert license_text.startswith("The MIT License (MIT)")
        assert "{year}" not in license_text
        assert "Test Author" in license_text
Esempio n. 3
0
def test_init_homepage_validator():
    responses = [
        'test_module_name',
        'Test Author',
        '*****@*****.**',
        'www.uh-oh-spagghetti-o.com',  # fails validation
        'https://www.example.org',  # passes
        '4',  # Skip - choose a license later
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open('rb') as f:
            data = tomli.load(f)
    assert data['project'] == {
        'authors': [{
            'name': 'Test Author',
            'email': '*****@*****.**'
        }],
        'name': 'test_module_name',
        'urls': {
            'Home': 'https://www.example.org'
        },
        'dynamic': ['version', 'description'],
    }
Esempio n. 4
0
def test_author_email_field_is_optional():
    responses = [
        'test_module_name',
        'Test Author',
        '',  # Author-email field is skipped
        'https://www.example.org',
        '4',
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open('rb') as f:
            data = tomli.load(f)
        assert not Path(td, 'LICENSE').exists()

    assert data['project'] == {
        'authors': [{
            'name': 'Test Author'
        }],
        'name': 'test_module_name',
        'urls': {
            'Home': 'https://www.example.org'
        },
        'dynamic': ['version', 'description'],
    }
Esempio n. 5
0
def test_init_non_ascii_author_name():
    responses = [
        'foo',  # Module name
        'Test Authôr',  # Author
        '',  # Author email omitted
        '',  # Home page omitted
        '1'  # License (1 -> MIT)
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()

        generated = Path(td) / 'pyproject.toml'
        assert_isfile(generated)
        with generated.open('r', encoding='utf-8') as f:
            raw_text = f.read()
            print(raw_text)
            assert "Test Authôr" in raw_text
            assert "\\u00f4" not in raw_text
        license = Path(td) / 'LICENSE'
        assert_isfile(license)
        with license.open(encoding='utf-8') as f:
            license_text = f.read()
        assert "Test Authôr" in license_text
Esempio n. 6
0
def test_prompt_options():
    ti = init.TerminalIniter()
    with faking_input(['4', '1']):
        res = ti.prompt_options('Pick one', [('A', 'Apple'), ('B', 'Banana')])
    assert res == 'A'

    # Test with a default
    with faking_input(['']):
        res = ti.prompt_options('Pick one', [('A', 'Apple'), ('B', 'Banana')],
                                default='B')
    assert res == 'B'
Esempio n. 7
0
def test_init():
    responses = [
        'foo',  # Module name
        'Thomas Kluyver',  # Author
        '*****@*****.**',  # Author email
        'http://example.com/',  # Home page
        '1'  # License (1 -> MIT)
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        assert_isfile('pyproject.toml')
        assert_isfile('LICENSE')
Esempio n. 8
0
def test_author_email_field_is_optional():
    responses = ['test_module_name',
                 'Test Author',
                 '',  # Author-email field is skipped
                 'https://www.example.org',
                 '4',
                ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open() as f:
            data = pytoml.load(f)
        assert not Path(td, 'LICENSE').exists()
    metadata = data['tool']['flit']['metadata']
    assert metadata == {
        'author': 'Test Author',
        'module': 'test_module_name',
        'home-page': 'https://www.example.org',
    }
Esempio n. 9
0
def test_init_homepage_and_license_are_optional():
    responses = ['test_module_name',
                 'Test Author',
                 '*****@*****.**',
                 '',   # Home page omitted
                 '4',  # Skip - choose a license later
                ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open() as f:
            data = pytoml.load(f)
        assert not Path(td, 'LICENSE').exists()
    metadata = data['tool']['flit']['metadata']
    assert metadata == {
        'author': 'Test Author',
        'author-email': '*****@*****.**',
        'module': 'test_module_name',
    }
Esempio n. 10
0
def test_init_homepage_validator():
    responses = ['test_module_name',
                 'Test Author',
                 '*****@*****.**',
                 'www.uh-oh-spagghetti-o.com',  # fails validation
                 'https://www.example.org',  # passes
                 '4',  # Skip - choose a license later
                ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open() as f:
            data = pytoml.load(f)
    metadata = data['tool']['flit']['metadata']
    assert metadata == {
        'author': 'Test Author',
        'author-email': '*****@*****.**',
        'home-page': 'https://www.example.org',
        'module': 'test_module_name',
    }
Esempio n. 11
0
def test_init_readme_found_yes_choosen():
    responses = [
        'test_module_name',
        'Test Author',
        '*****@*****.**',
        '',  # Home page omitted
        '4',  # Skip - choose a license later
    ]
    with make_dir(["readme.md"]) as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open() as f:
            data = pytoml.load(f)

    metadata = data['tool']['flit']['metadata']
    assert metadata == {
        'author': 'Test Author',
        'author-email': '*****@*****.**',
        'module': 'test_module_name',
        'description-file': 'readme.md'
    }
Esempio n. 12
0
def test_init_homepage_and_license_are_optional():
    responses = [
        'test_module_name',
        'Test Author',
        '*****@*****.**',
        '',  # Home page omitted
        '4',  # Skip - choose a license later
    ]
    with TemporaryDirectory() as td, \
          patch_data_dir(), \
          faking_input(responses):
        ti = init.TerminalIniter(td)
        ti.initialise()
        with Path(td, 'pyproject.toml').open('rb') as f:
            data = tomli.load(f)
        assert not Path(td, 'LICENSE').exists()
    assert data['project'] == {
        'authors': [{
            'name': 'Test Author',
            'email': '*****@*****.**'
        }],
        'name': 'test_module_name',
        'dynamic': ['version', 'description'],
    }