diff options
Diffstat (limited to 'share')
-rw-r--r-- | share/common/lib/files.yaml (renamed from share/rust/lib/files.yaml) | 51 | ||||
-rw-r--r-- | share/python/lib/files.md | 2 | ||||
-rw-r--r-- | share/python/lib/files.py | 35 | ||||
-rw-r--r-- | share/python/lib/files.yaml | 133 | ||||
-rw-r--r-- | share/python/lib/runcmd.md | 2 | ||||
-rw-r--r-- | share/python/lib/runcmd_test.py | 2 |
6 files changed, 62 insertions, 163 deletions
diff --git a/share/rust/lib/files.yaml b/share/common/lib/files.yaml index cabda12..40c092a 100644 --- a/share/rust/lib/files.yaml +++ b/share/common/lib/files.yaml @@ -1,10 +1,11 @@ # Bindings for the files steps -# These bind the files step library for subplotlib - given: file {embedded_file} impl: rust: function: subplotlib::steplibrary::files::create_from_embedded + python: + function: files_create_from_embedded types: embedded_file: file @@ -12,6 +13,8 @@ impl: rust: function: subplotlib::steplibrary::files::create_from_embedded_with_other_name + python: + function: files_create_from_embedded_with_other_name types: embedded_file: file @@ -20,6 +23,8 @@ impl: rust: function: subplotlib::steplibrary::files::touch_with_timestamp + python: + function: files_touch_with_timestamp types: mtime: text @@ -28,31 +33,43 @@ impl: rust: function: subplotlib::steplibrary::files::create_from_text + python: + function: files_create_from_text - when: I remember metadata for file {filename} impl: rust: function: subplotlib::steplibrary::files::remember_metadata + python: + function: files_remember_metadata - when: I touch file {filename} impl: rust: function: subplotlib::steplibrary::files::touch + python: + function: files_touch - then: file {filename} exists impl: rust: function: subplotlib::steplibrary::files::file_exists + python: + function: files_file_exists - then: file {filename} does not exist impl: rust: function: subplotlib::steplibrary::files::file_does_not_exist + python: + function: files_file_does_not_exist - then: only files (?P<filenames>.+) exist impl: rust: function: subplotlib::steplibrary::files::only_these_exist + python: + function: files_only_these_exist regex: true - then: file (?P<filename>\S+) contains "(?P<data>.*)" @@ -60,80 +77,112 @@ impl: rust: function: subplotlib::steplibrary::files::file_contains + python: + function: files_file_contains - then: file (?P<filename>\S+) matches regex /(?P<regex>.*)/ regex: true impl: rust: function: subplotlib::steplibrary::files::file_matches_regex + python: + function: files_file_matches_regex - then: file (?P<filename>\S+) matches regex "(?P<regex>.*)" regex: true impl: rust: function: subplotlib::steplibrary::files::file_matches_regex + python: + function: files_file_matches_regex - then: files {filename1} and {filename2} match impl: rust: function: subplotlib::steplibrary::files::file_match + python: + function: files_match - then: file {filename} has same metadata as before impl: rust: function: subplotlib::steplibrary::files::has_remembered_metadata + python: + function: files_has_remembered_metadata - then: file {filename} has different metadata from before impl: rust: function: subplotlib::steplibrary::files::has_different_metadata + python: + function: files_has_different_metadata - then: file {filename} has changed from before impl: rust: function: subplotlib::steplibrary::files::has_different_metadata + python: + function: files_has_different_metadata - then: file {filename} has a very recent modification time impl: rust: function: subplotlib::steplibrary::files::mtime_is_recent + python: + function: files_mtime_is_recent - then: file {filename} has a very old modification time impl: rust: function: subplotlib::steplibrary::files::mtime_is_ancient + python: + function: files_mtime_is_ancient - given: a directory {path} impl: rust: function: subplotlib::steplibrary::files::make_directory + python: + function: files_make_directory - when: I create directory {path} impl: rust: function: subplotlib::steplibrary::files::make_directory + python: + function: files_make_directory - when: I remove directory {path} impl: rust: function: subplotlib::steplibrary::files::remove_directory + python: + function: files_remove_directory - then: directory {path} exists impl: rust: function: subplotlib::steplibrary::files::path_exists + python: + function: files_directory_exists - then: directory {path} does not exist impl: rust: function: subplotlib::steplibrary::files::path_does_not_exist + python: + function: files_directory_does_not_exist - then: directory {path} is empty impl: rust: function: subplotlib::steplibrary::files::path_is_empty + python: + function: files_directory_is_empty - then: directory {path} is not empty impl: rust: function: subplotlib::steplibrary::files::path_is_not_empty + python: + function: files_directory_is_not_empty diff --git a/share/python/lib/files.md b/share/python/lib/files.md index 823c760..5638791 100644 --- a/share/python/lib/files.md +++ b/share/python/lib/files.md @@ -99,7 +99,7 @@ title: Acceptance criteria for the files Subplot library author: The Subplot project template: python bindings: -- files.yaml +- lib/files.yaml functions: - files.py ... diff --git a/share/python/lib/files.py b/share/python/lib/files.py index fa219b4..8c2c3a7 100644 --- a/share/python/lib/files.py +++ b/share/python/lib/files.py @@ -1,3 +1,5 @@ +from time import strptime + import logging import os import re @@ -5,21 +7,21 @@ import shutil import time -def files_create_from_embedded(ctx, filename=None): - files_make_directory(ctx, path=os.path.dirname(filename) or ".") +def files_create_from_embedded(ctx, embedded_file=None): + files_make_directory(ctx, path=os.path.dirname(embedded_file) or ".") files_create_from_embedded_with_other_name( - ctx, filename_on_disk=filename, embedded_filename=filename + ctx, filename_on_disk=embedded_file, embedded_file=embedded_file ) def files_create_from_embedded_with_other_name( - ctx, filename_on_disk=None, embedded_filename=None + ctx, filename_on_disk=None, embedded_file=None ): get_file = globals()["get_file"] files_make_directory(ctx, path=os.path.dirname(filename_on_disk) or ".") with open(filename_on_disk, "wb") as f: - f.write(get_file(embedded_filename)) + f.write(get_file(embedded_file)) def files_create_from_text(ctx, filename=None, text=None): @@ -106,27 +108,8 @@ def files_match(ctx, filename1=None, filename2=None): assert_eq(data1, data2) -def files_touch_with_timestamp( - ctx, - filename=None, - year=None, - month=None, - day=None, - hour=None, - minute=None, - second=None, -): - t = ( - int(year), - int(month), - int(day), - int(hour), - int(minute), - int(second), - -1, - -1, - -1, - ) +def files_touch_with_timestamp(ctx, filename=None, mtime = None): + t = strptime(mtime, "%Y-%m-%d %H:%M:%S") ts = time.mktime(t) _files_touch(filename, ts) diff --git a/share/python/lib/files.yaml b/share/python/lib/files.yaml deleted file mode 100644 index 64a2d14..0000000 --- a/share/python/lib/files.yaml +++ /dev/null @@ -1,133 +0,0 @@ -- given: file {filename} - impl: - python: - function: files_create_from_embedded - types: - filename: file - -- given: file {filename_on_disk} from {embedded_filename} - impl: - python: - function: files_create_from_embedded_with_other_name - types: - embedded_filename: file - -- given: file {filename} has modification time {year}-{month}-{day} {hour}:{minute}:{second} - impl: - python: - function: files_touch_with_timestamp - -- when: I write "(?P<text>.*)" to file (?P<filename>\S+) - regex: true - impl: - python: - function: files_create_from_text - -- when: I remember metadata for file {filename} - impl: - python: - function: files_remember_metadata - -- when: I touch file {filename} - impl: - python: - function: files_touch - -- then: file {filename} exists - impl: - python: - function: files_file_exists - -- then: file {filename} does not exist - impl: - python: - function: files_file_does_not_exist - -- then: only files (?P<filenames>.+) exist - impl: - python: - function: files_only_these_exist - regex: true - -- then: file (?P<filename>\S+) contains "(?P<data>.*)" - regex: true - impl: - python: - function: files_file_contains - -- then: file (?P<filename>\S+) matches regex /(?P<regex>.*)/ - regex: true - impl: - python: - function: files_file_matches_regex - -- then: file (?P<filename>\S+) matches regex "(?P<regex>.*)" - regex: true - impl: - python: - function: files_file_matches_regex - -- then: files {filename1} and {filename2} match - impl: - python: - function: files_match - -- then: file {filename} has same metadata as before - impl: - python: - function: files_has_remembered_metadata - -- then: file {filename} has different metadata from before - impl: - python: - function: files_has_different_metadata - -- then: file {filename} has changed from before - impl: - python: - function: files_has_different_metadata - -- then: file {filename} has a very recent modification time - impl: - python: - function: files_mtime_is_recent - -- then: file {filename} has a very old modification time - impl: - python: - function: files_mtime_is_ancient - -- given: a directory {path} - impl: - python: - function: files_make_directory - -- when: I create directory {path} - impl: - python: - function: files_make_directory - -- when: I remove directory {path} - impl: - python: - function: files_remove_directory - -- then: directory {path} exists - impl: - python: - function: files_directory_exists - -- then: directory {path} does not exist - impl: - python: - function: files_directory_does_not_exist - -- then: directory {path} is empty - impl: - python: - function: files_directory_is_empty - -- then: directory {path} is not empty - impl: - python: - function: files_directory_is_not_empty diff --git a/share/python/lib/runcmd.md b/share/python/lib/runcmd.md index f28ec2a..f165ad3 100644 --- a/share/python/lib/runcmd.md +++ b/share/python/lib/runcmd.md @@ -206,7 +206,7 @@ template: python bindings: - lib/runcmd.yaml - runcmd_test.yaml -- files.yaml +- lib/files.yaml functions: - runcmd.py - runcmd_test.py diff --git a/share/python/lib/runcmd_test.py b/share/python/lib/runcmd_test.py index 6aa435a..4aa5f49 100644 --- a/share/python/lib/runcmd_test.py +++ b/share/python/lib/runcmd_test.py @@ -8,7 +8,7 @@ def create_script_from_embedded(ctx, filename=None, embedded=None): # Create the file. files_create_from_embedded_with_other_name( - ctx, filename_on_disk=filename, embedded_filename=embedded + ctx, filename_on_disk=filename, embedded_file=embedded ) # Make the new file executable. |