Example #1
0
    def test_detects_existing_dest(self, tmpdir, monkeypatch):
        """
        Exit with EEXIST if the selected destination already exists.
        """
        monkeypatch.chdir(tmpdir)
        os.mkdir("foo")
        os.mkdir("foo.docset")
        with pytest.raises(SystemExit) as e:
            main.setup_paths(
                source="foo",
                force=False,
                name=None,
                destination=None,
                add_to_global=False,
            )
        assert e.value.code == errno.EEXIST

        main.setup_paths(
            source="foo",
            force=True,
            name=None,
            destination=None,
            add_to_global=False,
        )
        assert not os.path.lexists("foo.docset")
Example #2
0
    def test_detects_existing_dest(self, tmpdir, monkeypatch):
        """
        Exit with EEXIST if the selected destination already exists.
        """
        monkeypatch.chdir(tmpdir)
        os.mkdir("foo")
        os.mkdir("foo.docset")
        with pytest.raises(SystemExit) as e:
            main.setup_paths(
                source="foo",
                force=False,
                name=None,
                destination=None,
                add_to_global=False,
            )
        assert e.value.code == errno.EEXIST

        main.setup_paths(
            source="foo",
            force=True,
            name=None,
            destination=None,
            add_to_global=False,
        )
        assert not os.path.lexists("foo.docset")
Example #3
0
 def test_works(self, tmpdir):
     """
     Integration tests with fake paths.
     """
     foo_path = str(tmpdir.join('foo'))
     os.mkdir(foo_path)
     assert (
         (foo_path, str(tmpdir.join('foo.docset')), "foo")
         == main.setup_paths(
             foo_path, str(tmpdir), name=None, add_to_global=False,
             force=False
         )
     )
     abs_foo = os.path.abspath(foo_path)
     assert (
         (abs_foo, str(tmpdir.join('foo.docset')), "foo") ==
         main.setup_paths(
             abs_foo, str(tmpdir), name=None, add_to_global=False,
             force=False
         )
     )
     assert (
         (abs_foo, str(tmpdir.join('baz.docset')), "baz") ==
         main.setup_paths(
             abs_foo, str(tmpdir), name="baz", add_to_global=False,
             force=False
         )
     )
Example #4
0
 def test_works(self, tmpdir):
     """
     Integration tests with fake paths.
     """
     foo_path = str(tmpdir.join('foo'))
     os.mkdir(foo_path)
     assert ((foo_path, str(tmpdir.join('foo.docset')),
              "foo") == main.setup_paths(foo_path,
                                         str(tmpdir),
                                         name=None,
                                         add_to_global=False,
                                         force=False))
     abs_foo = os.path.abspath(foo_path)
     assert ((abs_foo, str(tmpdir.join('foo.docset')),
              "foo") == main.setup_paths(abs_foo,
                                         str(tmpdir),
                                         name=None,
                                         add_to_global=False,
                                         force=False))
     assert ((abs_foo, str(tmpdir.join('baz.docset')),
              "baz") == main.setup_paths(abs_foo,
                                         str(tmpdir),
                                         name="baz",
                                         add_to_global=False,
                                         force=False))
Example #5
0
 def test_detects_source_is_file(self, args):
     """
     Exit with ENOTDIR if a file is passed as source.
     """
     args.configure_mock(source='setup.py', name=None)
     with pytest.raises(SystemExit) as e:
         main.setup_paths(args)
     assert e.value.code == errno.ENOTDIR
Example #6
0
 def test_detects_missing_source(self, args):
     """
     Exit wie ENOENT if source doesn't exist.
     """
     args.configure_mock(source='doesnotexist', name=None)
     with pytest.raises(SystemExit) as e:
         main.setup_paths(args)
     assert e.value.code == errno.ENOENT
Example #7
0
 def test_detects_source_is_file(self, args):
     """
     Exit with ENOTDIR if a file is passed as source.
     """
     args.configure_mock(source='setup.py', name=None)
     with pytest.raises(SystemExit) as e:
         main.setup_paths(args)
     assert e.value.code == errno.ENOTDIR
Example #8
0
 def test_detects_missing_source(self, args):
     """
     Exit wie ENOENT if source doesn't exist.
     """
     args.configure_mock(source='doesnotexist', name=None)
     with pytest.raises(SystemExit) as e:
         main.setup_paths(args)
     assert e.value.code == errno.ENOENT
Example #9
0
def test_setup_paths_detects_existing_dest(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        monkeypatch.chdir(td)
        os.mkdir('foo')
        os.mkdir('foo.docset')
        args.configure_mock(source='foo', force=False, name=None,
                            destination=None, A=False)
        with pytest.raises(SystemExit) as e:
            main.setup_paths(args)
        assert e.value.code == errno.EEXIST

        args.force = True
        main.setup_paths(args)
        assert not os.path.lexists('foo.docset')
Example #10
0
def test_setup_paths_detects_existing_dest(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        monkeypatch.chdir(td)
        os.mkdir('foo')
        os.mkdir('foo.docset')
        args.configure_mock(source='foo', force=False, name=None,
                            destination=None, A=False)
        with pytest.raises(SystemExit) as e:
            main.setup_paths(args)
        assert e.value.code == errno.EEXIST

        args.force = True
        main.setup_paths(args)
        assert not os.path.lexists('foo.docset')
Example #11
0
def test_setup_paths_works(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        foo_path = os.path.join(td, 'foo')
        os.mkdir(foo_path)
        args.configure_mock(source=foo_path, name=None, destination=td)
        assert ((foo_path, os.path.join(td, 'foo.docset')) ==
                main.setup_paths(args))
        abs_foo = os.path.abspath(foo_path)
        args.source = abs_foo
        assert ((abs_foo, os.path.join(td, 'foo.docset')) ==
                main.setup_paths(args))
        assert args.name == 'foo'
        args.name = 'baz.docset'
        assert ((abs_foo, os.path.join(td, 'baz.docset')) ==
                main.setup_paths(args))
        assert args.name == 'baz'
Example #12
0
def test_setup_paths_works(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        foo_path = os.path.join(td, 'foo')
        os.mkdir(foo_path)
        args.configure_mock(source=foo_path, name=None, destination=td)
        assert ((foo_path, os.path.join(td, 'foo.docset')) ==
                main.setup_paths(args))
        abs_foo = os.path.abspath(foo_path)
        args.source = abs_foo
        assert ((abs_foo, os.path.join(td, 'foo.docset')) ==
                main.setup_paths(args))
        assert args.name == 'foo'
        args.name = 'baz.docset'
        assert ((abs_foo, os.path.join(td, 'baz.docset')) ==
                main.setup_paths(args))
        assert args.name == 'baz'
Example #13
0
    def test_detects_existing_dest(self, args, tmpdir, monkeypatch):
        """
        Exit with EEXIST if the selected destination already exists.
        """
        monkeypatch.chdir(tmpdir)
        os.mkdir('foo')
        os.mkdir('foo.docset')
        args.configure_mock(source='foo', force=False, name=None,
                            destination=None, A=False)
        with pytest.raises(SystemExit) as e:
            main.setup_paths(args)
        assert e.value.code == errno.EEXIST

        args.force = True
        main.setup_paths(args)
        assert not os.path.lexists('foo.docset')
Example #14
0
 def test_cleans_name(self, tmpdir):
     """
     If the name ends with .docset, remove it.
     """
     d = tmpdir.mkdir("foo")
     assert "baz" == main.setup_paths(
         source=str(d), force=False, name="baz.docset", destination="bar",
         add_to_global=False,
     )[2]
Example #15
0
 def test_deducts_name_with_trailing_slash(self, tmpdir, monkeypatch):
     """
     If the source path ends with a /, the name is still correctly deducted.
     """
     monkeypatch.chdir(tmpdir)
     os.mkdir('foo')
     assert "foo" == main.setup_paths(
         source='foo/', force=False, name=None,
         destination=None, add_to_global=False)[0]
Example #16
0
 def test_A_overrides_destination(self, args, monkeypatch):
     """
     Passing A computes the destination and overrides an argument.
     """
     assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
     args.configure_mock(source='doc2dash', name=None, destination='foobar',
                         A=True)
     assert ('foo', os.path.join(main.DEFAULT_DOCSET_PATH, 'foo.docset') ==
             main.setup_paths(args))
Example #17
0
 def test_cleans_name(self, tmpdir):
     """
     If the name ends with .docset, remove it.
     """
     d = tmpdir.mkdir("foo")
     assert "baz" == main.setup_paths(
         source=str(d), force=False, name="baz.docset", destination="bar",
         add_to_global=False,
     )[2]
Example #18
0
 def test_deducts_name_with_trailing_slash(self, tmpdir, monkeypatch):
     """
     If the source path ends with a /, the name is still correctly deducted.
     """
     monkeypatch.chdir(tmpdir)
     os.mkdir('foo')
     assert "foo" == main.setup_paths(
         source='foo/', force=False, name=None,
         destination=None, add_to_global=False)[0]
Example #19
0
    def test_detects_existing_dest(self, args, tmpdir, monkeypatch):
        """
        Exit with EEXIST if the selected destination already exists.
        """
        monkeypatch.chdir(tmpdir)
        os.mkdir('foo')
        os.mkdir('foo.docset')
        args.configure_mock(source='foo',
                            force=False,
                            name=None,
                            destination=None,
                            A=False)
        with pytest.raises(SystemExit) as e:
            main.setup_paths(args)
        assert e.value.code == errno.EEXIST

        args.force = True
        main.setup_paths(args)
        assert not os.path.lexists('foo.docset')
Example #20
0
 def test_works(self, args, monkeypatch, tmpdir):
     """
     Integration test with mocked-out parser.
     """
     foo_path = str(tmpdir.join('foo'))
     os.mkdir(foo_path)
     args.configure_mock(source=foo_path,
                         name=None,
                         destination=str(tmpdir))
     assert ((foo_path,
              str(tmpdir.join('foo.docset'))) == main.setup_paths(args))
     abs_foo = os.path.abspath(foo_path)
     args.source = abs_foo
     assert ((abs_foo,
              str(tmpdir.join('foo.docset')) == main.setup_paths(args)))
     assert args.name == 'foo'
     args.name = 'baz.docset'
     assert ((abs_foo,
              str(tmpdir.join('baz.docset')) == main.setup_paths(args)))
     assert args.name == 'baz'
Example #21
0
 def test_A_overrides_destination(self, args, monkeypatch):
     """
     Passing A computes the destination and overrides an argument.
     """
     assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
     args.configure_mock(source='doc2dash',
                         name=None,
                         destination='foobar',
                         A=True)
     assert ('foo', os.path.join(main.DEFAULT_DOCSET_PATH,
                                 'foo.docset') == main.setup_paths(args))
Example #22
0
 def test_add_to_global_overrides_destination(self):
     """
     Passing -A computes the destination and overrides an argument.
     """
     assert "~" not in main.DEFAULT_DOCSET_PATH  # resolved?
     assert (
         "foo", os.path.join(main.DEFAULT_DOCSET_PATH, "foo.docset"), "foo"
     ) == main.setup_paths(
         source="foo", name=None, destination="foobar",
         add_to_global=True, force=False
     )
Example #23
0
 def test_add_to_global_overrides_destination(self):
     """
     Passing -A computes the destination and overrides an argument.
     """
     assert "~" not in main.DEFAULT_DOCSET_PATH  # resolved?
     assert (
         "foo", os.path.join(main.DEFAULT_DOCSET_PATH, "foo.docset"), "foo"
     ) == main.setup_paths(
         source="foo", name=None, destination="foobar",
         add_to_global=True, force=False
     )
Example #24
0
 def test_A_overrides_destination(self):
     """
     Passing A computes the destination and overrides an argument.
     """
     assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
     assert ('foo', os.path.join(main.DEFAULT_DOCSET_PATH, 'foo.docset'),
             "foo" == main.setup_paths(source='doc2dash',
                                       name=None,
                                       destination='foobar',
                                       add_to_global=True,
                                       force=False))
Example #25
0
 def test_A_overrides_destination(self):
     """
     Passing A computes the destination and overrides an argument.
     """
     assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
     assert (
         'foo', os.path.join(main.DEFAULT_DOCSET_PATH, 'foo.docset'), "foo"
         == main.setup_paths(
             source='doc2dash', name=None, destination='foobar',
             add_to_global=True, force=False
         )
     )
Example #26
0
 def test_works(self, args, monkeypatch, tmpdir):
     """
     Integration test with mocked-out parser.
     """
     foo_path = str(tmpdir.join('foo'))
     os.mkdir(foo_path)
     args.configure_mock(
         source=foo_path, name=None, destination=str(tmpdir)
     )
     assert (
         (foo_path, str(tmpdir.join('foo.docset')))
         == main.setup_paths(args)
     )
     abs_foo = os.path.abspath(foo_path)
     args.source = abs_foo
     assert ((abs_foo, str(tmpdir.join('foo.docset')) ==
             main.setup_paths(args)))
     assert args.name == 'foo'
     args.name = 'baz.docset'
     assert ((abs_foo, str(tmpdir.join('baz.docset')) ==
             main.setup_paths(args)))
     assert args.name == 'baz'
Example #27
0
def test_setup_paths_detects_source_is_file():
    args.configure_mock(source='setup.py', name=None)
    with pytest.raises(SystemExit) as e:
        main.setup_paths(args)
    assert e.value.code == errno.ENOTDIR
Example #28
0
def test_setup_paths_detects_missing_source():
    args.configure_mock(source='doesnotexist', name=None)
    with pytest.raises(SystemExit) as e:
        main.setup_paths(args)
    assert e.value.code == errno.ENOENT
Example #29
0
def test_A_overrides_destination(monkeypatch):
    assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
    args.configure_mock(source='doc2dash', name=None, destination='foobar',
                        A=True)
    assert ('foo', os.path.join(main.DEFAULT_DOCSET_PATH, 'foo.docset') ==
            main.setup_paths(args))
Example #30
0
def test_A_overrides_destination(monkeypatch):
    assert '~' not in main.DEFAULT_DOCSET_PATH  # resolved?
    args.configure_mock(source='doc2dash', name=None, destination='foobar',
                        A=True)
    assert ('foo', os.path.join(main.DEFAULT_DOCSET_PATH, 'foo.docset') ==
            main.setup_paths(args))
Example #31
0
def test_setup_paths_detects_missing_source():
    args.configure_mock(source='doesnotexist', name=None)
    with pytest.raises(SystemExit) as e:
        main.setup_paths(args)
    assert e.value.code == errno.ENOENT
Example #32
0
def test_setup_paths_detects_source_is_file():
    args.configure_mock(source='setup.py', name=None)
    with pytest.raises(SystemExit) as e:
        main.setup_paths(args)
    assert e.value.code == errno.ENOTDIR