Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions python/grass/grassdb/testsuite/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

"""Tests of grass.grassdb.manage"""

import os
from pathlib import Path

from grass.grassdb.manage import MapsetPath, resolve_mapset_path, split_mapset_path
from grass.gunittest.case import TestCase
from grass.gunittest.gmodules import call_module
from grass.gunittest.main import test
from grass.gunittest.utils import xfail_windows


class TestMapsetPath(TestCase):
Expand All @@ -37,7 +37,6 @@ def test_mapset_from_path_object(self):
self.assertEqual(mapset_path.mapset, mapset_name)
self.assertEqual(mapset_path.path, Path(path) / location_name / mapset_name)

@xfail_windows
def test_mapset_from_str(self):
"""Check with path from str and database directory as Path"""
path = "does/not/exist"
Expand All @@ -51,7 +50,8 @@ def test_mapset_from_str(self):
mapset=mapset_name,
)
# Paths are currently stored as is (not resolved).
self.assertEqual(mapset_path.directory, path)
# pathlib uses os.sep for string representation of Path objects
self.assertEqual(mapset_path.directory, path.replace("/", os.sep))
self.assertEqual(mapset_path.location, location_name)
self.assertEqual(mapset_path.mapset, mapset_name)
self.assertEqual(mapset_path.path, Path(path) / location_name / mapset_name)
Expand All @@ -60,39 +60,36 @@ def test_mapset_from_str(self):
class TestSplitMapsetPath(TestCase):
"""Check that split works with different parameters"""

@xfail_windows
def test_split_path(self):
"""Check that pathlib.Path is correctly split"""
ref_db = "does/not/exist"
ref_location = "test_location_A"
ref_mapset = "test_mapset_1"
path = Path(ref_db) / ref_location / ref_mapset
new_db, new_location, new_mapset = split_mapset_path(path)
self.assertEqual(new_db, ref_db)
self.assertEqual(new_db, ref_db.replace("/", os.sep))
self.assertEqual(new_location, ref_location)
self.assertEqual(new_mapset, ref_mapset)

@xfail_windows
def test_split_str(self):
"""Check that path as str is correctly split"""
ref_db = "does/not/exist"
ref_location = "test_location_A"
ref_mapset = "test_mapset_1"
path = Path(ref_db) / ref_location / ref_mapset
new_db, new_location, new_mapset = split_mapset_path(str(path))
self.assertEqual(new_db, ref_db)
self.assertEqual(new_db, ref_db.replace("/", os.sep))
self.assertEqual(new_location, ref_location)
self.assertEqual(new_mapset, ref_mapset)

@xfail_windows
def test_split_str_trailing_slash(self):
"""Check that path as str with a trailing slash is correctly split"""
ref_db = "does/not/exist"
ref_location = "test_location_A"
ref_mapset = "test_mapset_1"
path = Path(ref_db) / ref_location / ref_mapset
new_db, new_location, new_mapset = split_mapset_path(str(path) + "/")
self.assertEqual(new_db, ref_db)
self.assertEqual(new_db, ref_db.replace("/", os.sep))
self.assertEqual(new_location, ref_location)
self.assertEqual(new_mapset, ref_mapset)

Expand Down
Loading