Browse Source

Fix tests on Windows

default_compile_flags
vector-of-bool 4 years ago
parent
commit
5396821a02
4 changed files with 27 additions and 9 deletions
  1. +1
    -0
      tests/catalog/get_test.py
  2. +6
    -4
      tests/http.py
  3. +2
    -1
      tests/msvc.tc.jsonc
  4. +18
    -4
      tools/mkrepo.py

+ 1
- 0
tests/catalog/get_test.py View File

@@ -22,6 +22,7 @@ def test_get(dds: DDS, http_repo: RepoFixture):
}
})

dds.scope.enter_context(ensure_dir(dds.source_root))
dds.repo_add(http_repo.url)
dds.catalog_get('neo-sqlite3@0.3.0')
assert (dds.scratch_dir / 'neo-sqlite3@0.3.0').is_dir()

+ 6
- 4
tests/http.py View File

@@ -43,12 +43,13 @@ def run_http_server(dirpath: Path, port: int):
the given TCP port.
"""
handler = partial(DirectoryServingHTTPRequestHandler, dir=dirpath)
addr = ('localhost', port)
addr = ('127.0.0.1', port)
pool = ThreadPoolExecutor()
with HTTPServer(addr, handler) as httpd:
pool.submit(lambda: httpd.serve_forever(poll_interval=0.1))
try:
yield ServerInfo(f'http://localhost:{port}', dirpath)
print('Serving at', addr)
yield ServerInfo(f'http://127.0.0.1:{port}', dirpath)
finally:
httpd.shutdown()

@@ -78,10 +79,11 @@ class RepoFixture:
Import some packages into the repo for the given JSON data. Uses
mkrepo.py
"""
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(json.dumps(data).encode())
f.flush()
f.close()
self.import_json_file(Path(f.name))
Path(f.name).unlink()

def import_json_file(self, fpath: Path) -> None:
"""

+ 2
- 1
tests/msvc.tc.jsonc View File

@@ -1,4 +1,5 @@
{
"$schema": "../res/toolchain-schema.json",
"compiler_id": "msvc"
"compiler_id": "msvc",
"cxx_flags": "/std:c++latest"
}

+ 18
- 4
tools/mkrepo.py View File

@@ -8,6 +8,7 @@ import json
import os
import re
import shutil
import stat
import sys
import tarfile
import tempfile
@@ -191,7 +192,7 @@ class RemoveTransform(NamedTuple):
if not self.only_matching:
# Remove everything
if abspath.is_dir():
shutil.rmtree(abspath)
better_rmtree(abspath)
else:
abspath.unlink()
return
@@ -200,7 +201,7 @@ class RemoveTransform(NamedTuple):
items = glob_if_exists(abspath, pat)
for f in items:
if f.is_dir():
shutil.rmtree(f)
better_rmtree(f)
else:
f.unlink()

@@ -266,7 +267,7 @@ class GitSpec(NamedTuple):
check_call(['git', 'clone', '--quiet', self.url, f'--depth=1', f'--branch={self.ref}', str(tdir)])
yield tdir
finally:
shutil.rmtree(tdir)
better_rmtree(tdir)


class ForeignPackage(NamedTuple):
@@ -337,6 +338,19 @@ def iter_spec_packages(data: Dict[str, Any]) -> Iterable[SpecPackage]:
yield SpecPackage.parse_data(name, version, defin)


def _on_rm_error_win32(fn, filepath, _exc_info):
p = Path(filepath)
p.chmod(stat.S_IWRITE)
p.unlink()


def better_rmtree(dir: Path) -> None:
if os.name == 'nt':
shutil.rmtree(dir, onerror=_on_rm_error_win32)
else:
shutil.rmtree(dir)


@contextmanager
def http_dl_unpack(url: str) -> Iterator[Path]:
req = request.urlopen(url)
@@ -352,7 +366,7 @@ def http_dl_unpack(url: str) -> Iterator[Path]:
subdir = next(iter(Path(tdir).iterdir()))
yield subdir
finally:
shutil.rmtree(tdir)
better_rmtree(tdir)


@contextmanager

Loading…
Cancel
Save