From 052d918908b4e571a42cd3fc539933f9db139e0c Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Fri, 8 Nov 2019 03:43:49 -0500 Subject: add fs.with_suffix --- docs/markdown/Fs-module.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index e68bf6884..3332b1ee8 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -8,6 +8,8 @@ available starting with version 0.53.0. Non-absolute paths are looked up relative to the directory where the current `meson.build` file is. +If specified, `~` is expanded to the user home directory. + ### exists Takes a single string argument and returns true if an entity with that @@ -29,3 +31,16 @@ name exists on the file system. This method follows symbolic links. Takes a single string argument and returns true if the path pointed to by the string is a symbolic link. + +## Filename modification + +### with_suffix + +The `with_suffix` method allows changing the filename suffix + +```meson +original = '/opt/foo.ini' +new = fs.with_suffix('.txt') +``` + +The files need not actually exist yet for this method. \ No newline at end of file -- cgit v1.2.3 From 1a0b4ddf340130d270a4c96a36f915eb5b0399f3 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 22:49:39 -0500 Subject: fs: further document and test behavior --- docs/markdown/Fs-module.md | 30 ++++++++++++++++++++++++++--- test cases/common/227 fs module/meson.build | 12 ++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 3332b1ee8..7c2925f90 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -36,11 +36,35 @@ by the string is a symbolic link. ### with_suffix -The `with_suffix` method allows changing the filename suffix +The `with_suffix` method is a *string manipulation* convenient for filename modifications. +It allows changing the filename suffix like: + +## swap suffix ```meson original = '/opt/foo.ini' -new = fs.with_suffix('.txt') +new = fs.with_suffix('.txt') # /opt/foo.txt +``` + +#### add suffix + +```meson +original = '/opt/foo' +new = fs.with_suffix('.txt') # /opt/foo.txt +``` + +#### compound suffix swap + +```meson +original = '/opt/foo.dll.a' +new = fs.with_suffix('.so') # /opt/foo.dll.so +``` + +#### delete suffix + +```meson +original = '/opt/foo.dll.a' +new = fs.with_suffix('') # /opt/foo.dll ``` -The files need not actually exist yet for this method. \ No newline at end of file +The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index 75f4a99b4..f111d466b 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -27,6 +27,18 @@ original = 'foo.txt' new = fs.with_suffix(original, '.ini') assert(new.endswith('foo.ini') and not new.contains('.txt'), 'with_suffix failed') +original = 'foo' +new = fs.with_suffix(original, '.ini') +assert(new.endswith('foo.ini'), 'with_suffix did not add suffix to suffixless file') + +original = 'foo.dll.a' +new = fs.with_suffix(original, '.so') +assert(new.endswith('foo.dll.so'), 'with_suffix did not only modify last suffix') + +original = 'foo.dll' +new = fs.with_suffix(original, '') +assert(new.endswith('foo'), 'with_suffix did not only delete last suffix') + # `/` on windows is interpreted like `.drive` which in general may not be `c:/` # the files need not exist for fs.with_suffix() original = is_windows ? 'j:/foo/bar.txt' : '/foo/bar.txt' -- cgit v1.2.3 From 67651271f60347b2d3cadd235a4abac0b3a1bc16 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 23:24:02 -0500 Subject: fs: add hash compute method --- docs/markdown/Fs-module.md | 8 ++++++++ mesonbuild/modules/fs.py | 18 ++++++++++++++++++ test cases/common/227 fs module/meson.build | 8 ++++++++ 3 files changed, 34 insertions(+) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 7c2925f90..499b8d272 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -32,6 +32,14 @@ name exists on the file system. This method follows symbolic links. Takes a single string argument and returns true if the path pointed to by the string is a symbolic link. +## File Parameters + +### hash + +The `hash` method computes the requested hash sum of a file. +The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. + + ## Filename modification ### with_suffix diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 1687d0d80..56496251f 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -13,8 +13,10 @@ # limitations under the License. import typing +import hashlib from pathlib import Path, PurePath +from .. import mlog from . import ExtensionModule from . import ModuleReturnValue from ..mesonlib import MesonException @@ -55,6 +57,22 @@ class FSModule(ExtensionModule): def is_dir(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: return self._check('is_dir', state, args) + @stringArgs + @noKwargs + def hash(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: + if len(args) != 2: + MesonException('method takes exactly two arguments.') + file = Path(state.source_root) / state.subdir / Path(args[0]).expanduser() + if not file.is_file(): + raise MesonException('{} is not a file and therefore cannot be hashed'.format(file)) + try: + h = hashlib.new(args[1]) + except ValueError: + raise MesonException('hash algorithm {} is not available'.format(args[1])) + mlog.debug('computing {} sum of {} size {} bytes'.format(args[1], file, file.stat().st_size)) + h.update(file.read_bytes()) + return ModuleReturnValue(h.hexdigest(), []) + @stringArgs @noKwargs def with_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index f111d466b..a98ed5601 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -47,4 +47,12 @@ new_check = is_windows ? 'j:\\foo\\bar.ini' : '/foo/bar.ini' new = fs.with_suffix(original, '.ini') assert(new == new_check, 'absolute path with_suffix failed') +# -- hash + +md5 = fs.hash('subdir/subdirfile.txt', 'md5') +sha256 = fs.hash('subdir/subdirfile.txt', 'sha256') +assert(md5 == 'd0795db41614d25affdd548314b30b3b', 'md5sum did not match') +assert(sha256 == 'be2170b0dae535b73f6775694fffa3fd726a43b5fabea11b7342f0605917a42a', 'sha256sum did not match') + + subdir('subdir') -- cgit v1.2.3 From a320274179ef36aa5aeb4827f777027c3ab3d785 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 23:38:16 -0500 Subject: fs: get file size fs: add samefile --- docs/markdown/Fs-module.md | 20 ++++++++++++++- mesonbuild/modules/fs.py | 40 +++++++++++++++++++++++++++-- test cases/common/227 fs module/meson.build | 14 ++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 499b8d272..8ce5e3274 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -36,9 +36,27 @@ by the string is a symbolic link. ### hash -The `hash` method computes the requested hash sum of a file. +The `fs.hash(filename)` method computes the requested hash sum of a file. The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +### samefile + +The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. +Perhaps a meson.build file in one place refer to a symlink and in another place a +relative path and/or absolute path. The `samefile` method allows determining if these +are the same file. + +Examples: + +```meson +x = 'foo.txt' +y = 'sub/../foo.txt' +z = 'bar.txt' # a symlink pointing to foo.txt + +fs.samefile(x, y) # true +fs.samefile(x, z) # true +``` + ## Filename modification diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 56496251f..571fe8a39 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -31,10 +31,17 @@ class FSModule(ExtensionModule): super().__init__(interpreter) self.snippets.add('generate_dub_file') + def _resolve_dir(self, state: 'ModuleState', arg: str) -> Path: + """ + resolves (makes absolute) a directory relative to calling meson.build, + if not already absolute + """ + return Path(state.source_root) / state.subdir / Path(arg).expanduser() + def _check(self, check: str, state: 'ModuleState', args: typing.Sequence[str]) -> ModuleReturnValue: if len(args) != 1: MesonException('fs.{} takes exactly one argument.'.format(check)) - test_file = Path(state.source_root) / state.subdir / Path(args[0]).expanduser() + test_file = self._resolve_dir(state, args[0]) return ModuleReturnValue(getattr(test_file, check)(), []) @stringArgs @@ -62,7 +69,7 @@ class FSModule(ExtensionModule): def hash(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: if len(args) != 2: MesonException('method takes exactly two arguments.') - file = Path(state.source_root) / state.subdir / Path(args[0]).expanduser() + file = self._resolve_dir(state, args[0]) if not file.is_file(): raise MesonException('{} is not a file and therefore cannot be hashed'.format(file)) try: @@ -73,6 +80,35 @@ class FSModule(ExtensionModule): h.update(file.read_bytes()) return ModuleReturnValue(h.hexdigest(), []) + @stringArgs + @noKwargs + def size(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: + if len(args) != 1: + MesonException('method takes exactly one argument.') + file = self._resolve_dir(state, args[0]) + if not file.is_file(): + raise MesonException('{} is not a file and therefore cannot be sized'.format(file)) + try: + return ModuleReturnValue(file.stat().st_size, []) + except ValueError: + raise MesonException('{} size could not be determined'.format(args[0])) + + @stringArgs + @noKwargs + def samefile(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: + if len(args) != 2: + MesonException('method takes exactly two arguments.') + file1 = self._resolve_dir(state, args[0]) + file2 = self._resolve_dir(state, args[1]) + if not file1.exists(): + raise MesonException('{} is not a file, symlink or directory and therefore cannot be compared'.format(file1)) + if not file2.exists(): + raise MesonException('{} is not a file, symlink or directory and therefore cannot be compared'.format(file2)) + try: + return ModuleReturnValue(file1.samefile(file2), []) + except OSError: + raise MesonException('{} could not be compared to {}'.format(file1, file2)) + @stringArgs @noKwargs def with_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index a98ed5601..2143699fb 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -54,5 +54,19 @@ sha256 = fs.hash('subdir/subdirfile.txt', 'sha256') assert(md5 == 'd0795db41614d25affdd548314b30b3b', 'md5sum did not match') assert(sha256 == 'be2170b0dae535b73f6775694fffa3fd726a43b5fabea11b7342f0605917a42a', 'sha256sum did not match') +# -- size + +size = fs.size('subdir/subdirfile.txt') +assert(size == 19, 'file size not found correctly') + +# -- are filenames referring to the same file? +f1 = 'meson.build' +f2 = 'subdir/../meson.build' +assert(fs.samefile(f1, f2), 'samefile not realized') +assert(not fs.samefile(f1, 'subdir/subdirfile.txt'), 'samefile known bad comparison') + +if not is_windows and build_machine.system() != 'cygwin' + assert(fs.samefile('a_symlink', 'meson.build'), 'symlink samefile fail') +endif subdir('subdir') -- cgit v1.2.3 From 5db3f8ac3ddfcf8ceb92db6ce69884ad5ffaa498 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Mon, 11 Nov 2019 20:34:04 -0500 Subject: fs: correct docs --- docs/markdown/Fs-module.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 8ce5e3274..423ec8e39 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -69,28 +69,28 @@ It allows changing the filename suffix like: ```meson original = '/opt/foo.ini' -new = fs.with_suffix('.txt') # /opt/foo.txt +new = fs.with_suffix(original, '.txt') # /opt/foo.txt ``` #### add suffix ```meson original = '/opt/foo' -new = fs.with_suffix('.txt') # /opt/foo.txt +new = fs.with_suffix(original, '.txt') # /opt/foo.txt ``` #### compound suffix swap ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix('.so') # /opt/foo.dll.so +new = fs.with_suffix(original, '.so') # /opt/foo.dll.so ``` #### delete suffix ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix('') # /opt/foo.dll +new = fs.with_suffix(original, '') # /opt/foo.dll ``` The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file -- cgit v1.2.3 From 4997d93b498094248bdc0669d9515f28f7a156ef Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Mon, 11 Nov 2019 20:39:37 -0500 Subject: fs: add docs for fs.size() --- docs/markdown/Fs-module.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 423ec8e39..87cbe1a06 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -39,6 +39,11 @@ by the string is a symbolic link. The `fs.hash(filename)` method computes the requested hash sum of a file. The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +### size + +The `fs.size(filename)` method returns the size of the file in bytes. +Symlinks will be resolved if possible. + ### samefile The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. -- cgit v1.2.3 From 2ae96f859583ed1aa1e78df73ba2895a2604fa8b Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Wed, 13 Nov 2019 00:00:15 -0500 Subject: fs: replace_suffix --- docs/markdown/Fs-module.md | 31 ++++++++++++++++------------- mesonbuild/modules/fs.py | 2 +- test cases/common/227 fs module/meson.build | 22 ++++++++++---------- 3 files changed, 29 insertions(+), 26 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 87cbe1a06..9a3ab1040 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -8,7 +8,7 @@ available starting with version 0.53.0. Non-absolute paths are looked up relative to the directory where the current `meson.build` file is. -If specified, `~` is expanded to the user home directory. +If specified, a leading `~` is expanded to the user home directory. ### exists @@ -36,20 +36,23 @@ by the string is a symbolic link. ### hash -The `fs.hash(filename)` method computes the requested hash sum of a file. -The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +The `fs.hash(filename, hash_algorithm)` method returns a string containing +the hexidecimal `hash_algorithm` digest of a file. +`hash_algorithm` is a string; the available hash algorithms include: +md5, sha1, sha224, sha256, sha384, sha512. ### size -The `fs.size(filename)` method returns the size of the file in bytes. +The `fs.size(filename)` method returns the size of the file in integer bytes. Symlinks will be resolved if possible. ### samefile -The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. -Perhaps a meson.build file in one place refer to a symlink and in another place a -relative path and/or absolute path. The `samefile` method allows determining if these -are the same file. +The `fs.samefile(filename1, filename2)` returns boolean `true` if the input filenames refer to the same file. +For example, suppose filename1 is a symlink and filename2 is a relative path. +If filename1 can be resolved to a file that is the same file as filename2, then `true` is returned. +If filename1 is not resolved to be the same as filename2, `false` is returned. +If either filename does not exist, an error message is raised. Examples: @@ -65,37 +68,37 @@ fs.samefile(x, z) # true ## Filename modification -### with_suffix +### replace_suffix -The `with_suffix` method is a *string manipulation* convenient for filename modifications. +The `replace_suffix` method is a *string manipulation* convenient for filename modifications. It allows changing the filename suffix like: ## swap suffix ```meson original = '/opt/foo.ini' -new = fs.with_suffix(original, '.txt') # /opt/foo.txt +new = fs.replace_suffix(original, '.txt') # /opt/foo.txt ``` #### add suffix ```meson original = '/opt/foo' -new = fs.with_suffix(original, '.txt') # /opt/foo.txt +new = fs.replace_suffix(original, '.txt') # /opt/foo.txt ``` #### compound suffix swap ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix(original, '.so') # /opt/foo.dll.so +new = fs.replace_suffix(original, '.so') # /opt/foo.dll.so ``` #### delete suffix ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix(original, '') # /opt/foo.dll +new = fs.replace_suffix(original, '') # /opt/foo.dll ``` The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 571fe8a39..0c8ed8e1b 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -111,7 +111,7 @@ class FSModule(ExtensionModule): @stringArgs @noKwargs - def with_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: + def replace_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: if len(args) != 2: MesonException('method takes exactly two arguments.') original = PurePath(state.source_root) / state.subdir / args[0] diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index 2143699fb..ec9ca935a 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -24,28 +24,28 @@ assert(fs.is_dir('~'), 'expanduser not working') assert(not fs.is_file('~'), 'expanduser not working') original = 'foo.txt' -new = fs.with_suffix(original, '.ini') -assert(new.endswith('foo.ini') and not new.contains('.txt'), 'with_suffix failed') +new = fs.replace_suffix(original, '.ini') +assert(new.endswith('foo.ini') and not new.contains('.txt'), 'replace_suffix failed') original = 'foo' -new = fs.with_suffix(original, '.ini') -assert(new.endswith('foo.ini'), 'with_suffix did not add suffix to suffixless file') +new = fs.replace_suffix(original, '.ini') +assert(new.endswith('foo.ini'), 'replace_suffix did not add suffix to suffixless file') original = 'foo.dll.a' -new = fs.with_suffix(original, '.so') -assert(new.endswith('foo.dll.so'), 'with_suffix did not only modify last suffix') +new = fs.replace_suffix(original, '.so') +assert(new.endswith('foo.dll.so'), 'replace_suffix did not only modify last suffix') original = 'foo.dll' -new = fs.with_suffix(original, '') -assert(new.endswith('foo'), 'with_suffix did not only delete last suffix') +new = fs.replace_suffix(original, '') +assert(new.endswith('foo'), 'replace_suffix did not only delete last suffix') # `/` on windows is interpreted like `.drive` which in general may not be `c:/` -# the files need not exist for fs.with_suffix() +# the files need not exist for fs.replace_suffix() original = is_windows ? 'j:/foo/bar.txt' : '/foo/bar.txt' new_check = is_windows ? 'j:\\foo\\bar.ini' : '/foo/bar.ini' -new = fs.with_suffix(original, '.ini') -assert(new == new_check, 'absolute path with_suffix failed') +new = fs.replace_suffix(original, '.ini') +assert(new == new_check, 'absolute path replace_suffix failed') # -- hash -- cgit v1.2.3 From 0cb48cdc793dfce8c5eeb17e447cbe169e1836d7 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 17 Nov 2019 00:22:53 -0500 Subject: fs: make replace_suffix not expand file to absolute path, just manipulate the string --- docs/markdown/Fs-module.md | 2 +- mesonbuild/modules/fs.py | 2 +- test cases/common/227 fs module/meson.build | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 9a3ab1040..45cb589da 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -73,7 +73,7 @@ fs.samefile(x, z) # true The `replace_suffix` method is a *string manipulation* convenient for filename modifications. It allows changing the filename suffix like: -## swap suffix +#### swap suffix ```meson original = '/opt/foo.ini' diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 0c8ed8e1b..86861ae08 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -114,7 +114,7 @@ class FSModule(ExtensionModule): def replace_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: if len(args) != 2: MesonException('method takes exactly two arguments.') - original = PurePath(state.source_root) / state.subdir / args[0] + original = PurePath(args[0]) new = original.with_suffix(args[1]) return ModuleReturnValue(str(new), []) diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index ec9ca935a..3c452d08c 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -25,19 +25,19 @@ assert(not fs.is_file('~'), 'expanduser not working') original = 'foo.txt' new = fs.replace_suffix(original, '.ini') -assert(new.endswith('foo.ini') and not new.contains('.txt'), 'replace_suffix failed') +assert(new == 'foo.ini', 'replace_suffix failed') original = 'foo' new = fs.replace_suffix(original, '.ini') -assert(new.endswith('foo.ini'), 'replace_suffix did not add suffix to suffixless file') +assert(new == 'foo.ini', 'replace_suffix did not add suffix to suffixless file') original = 'foo.dll.a' new = fs.replace_suffix(original, '.so') -assert(new.endswith('foo.dll.so'), 'replace_suffix did not only modify last suffix') +assert(new == 'foo.dll.so', 'replace_suffix did not only modify last suffix') original = 'foo.dll' new = fs.replace_suffix(original, '') -assert(new.endswith('foo'), 'replace_suffix did not only delete last suffix') +assert(new == 'foo', 'replace_suffix did not only delete last suffix') # `/` on windows is interpreted like `.drive` which in general may not be `c:/` # the files need not exist for fs.replace_suffix() -- cgit v1.2.3