Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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
         )
     )
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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')
Ejemplo n.º 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]
Ejemplo n.º 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]
Ejemplo n.º 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))
Ejemplo n.º 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]
Ejemplo n.º 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]
Ejemplo n.º 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')
Ejemplo n.º 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'
Ejemplo n.º 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))
Ejemplo n.º 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
     )
Ejemplo n.º 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
     )
Ejemplo n.º 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))
Ejemplo n.º 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
         )
     )
Ejemplo n.º 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'
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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