Fix some bugs on windows

This commit is contained in:
Julien Duponchelle 2016-09-27 17:05:03 +02:00
parent 3a8ca1071e
commit be5d543f20
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
5 changed files with 14 additions and 8 deletions

View File

@ -472,7 +472,6 @@ def _convert_snapshots(topo_dir):
for root, dirs, files in os.walk(snapshot_dir):
for file in files:
myzip.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), snapshot_dir), compress_type=zipfile.ZIP_DEFLATED)
shutil.copy(snapshot_arc, "/tmp/test.zip")
shutil.rmtree(old_snapshots_dir)

View File

@ -17,17 +17,17 @@
import re
import os
import textwrap
import posixpath
import pathlib
def force_unix_path(path):
"""
:param path: Path to convert
"""
path = path.replace("\\", "/")
return posixpath.normpath(path)
p = pathlib.Path(os.path.normpath(path))
return p.as_posix()
def macaddress_to_int(mac_address):

View File

@ -136,7 +136,7 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={
"images_path": str(tmpdir / "images1"),
"additional_images_path": "/tmp/null24564:{}".format(tmpdir / "images2"),
"additional_images_path": "/tmp/null24564:{}".format(str(tmpdir / "images2")),
"local": False}):
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2

View File

@ -77,8 +77,13 @@ def test_convert(directory, tmpdir):
file_path = os.path.join(work_directory, directory, file)
assert os.path.exists(file_path), "{} is missing".format(os.path.join(directory, file))
# For gns3project we check if size are not too much differents
if file_path.endswith(".gns3project"):
size = os.stat(file_path).st_size
other_size = os.stat(os.path.join(os.path.join(root, file))).st_size
assert size in range(other_size - 100, other_size + 100), "File {} is different".format(os.path.join(directory, file))
# For non .gns3 file we check if the file are the same
if not file_path.endswith(".gns3"):
elif not file_path.endswith(".gns3"):
assert os.stat(file_path).st_size == os.stat(os.path.join(os.path.join(root, file))).st_size, "File {} is different".format(os.path.join(directory, file))
# Check if we don't have unexpected file in work directory

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from gns3server.utils import *
@ -23,6 +23,8 @@ def test_force_unix_path():
assert force_unix_path("a/b") == "a/b"
assert force_unix_path("a\\b") == "a/b"
assert force_unix_path("a\\b\\..\\c") == "a/c"
if sys.platform.startswith("win"):
assert force_unix_path("C:\Temp") == "C:/Temp"
def test_macaddress_to_int():