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")
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 ) )
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))
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
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
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')
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'
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')
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]
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]
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))
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'
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 )
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))
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 ) )
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'
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
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
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))