From 23f1d4617093809ea1d9eebd9ead4e9d2b19bfec Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sun, 28 Jan 2024 13:36:46 +0545 Subject: [PATCH 01/26] Reworked on logic for RUN_BUILD and RUN_BUILD_CACHELESS to use a single docker build statement --- local-workflows.sh | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/local-workflows.sh b/local-workflows.sh index e34bd381..4c1ae1f5 100755 --- a/local-workflows.sh +++ b/local-workflows.sh @@ -115,7 +115,7 @@ set_option(){ shift else echo "Error: Missing argument for --file" - exit 1 + usage fi ;; --json|-j) @@ -124,7 +124,7 @@ set_option(){ shift else echo "Error: Missing argument for --json" - exit 1 + usage fi ;; --help|-h) @@ -182,20 +182,34 @@ if [ "${AUTO_REQS:-0}" = "1" ]; then pipreqs --print "$LOCAL_REPO_DIR" > "$REQUIREMENTS" fi -# Build the Docker image -if [ "${RUN_BUILD}" = "1" ]; then - echo "Building Docker image: $IMAGE_NAME" - # note: maldito docker doesn't support --env for build, just run - # Also, --build-arg misleading: see - # https://stackoverflow.com/questions/42297387/docker-build-with-build-arg-with-multiple-arguments - # shellcheck disable=SC2086 - docker build --build-arg "GIT_BRANCH=$GIT_BRANCH" --platform linux/x86_64 $BUILD_OPTS --tag "$IMAGE_NAME" . -fi -# Build the Docker image cacheless (using --no-cache option) -if [ "${RUN_BUILD_CACHELESS}" = "1" ]; then - echo "Building Docker image (no-cache): $IMAGE_NAME" - docker build --build-arg "GIT_BRANCH=$GIT_BRANCH" --platform linux/x86_64 $BUILD_OPTS --no-cache -t "$IMAGE_NAME" . +## OLD: Use of seperate options for RUN_BUILD and RUN_BUILD_CACHELESS +# # Build the Docker image +# if [ "${RUN_BUILD}" = "1" ]; then +# echo "Building Docker image: $IMAGE_NAME" +# # note: maldito docker doesn't support --env for build, just run +# # Also, --build-arg misleading: see +# # https://stackoverflow.com/questions/42297387/docker-build-with-build-arg-with-multiple-arguments +# # shellcheck disable=SC2086 +# docker build --build-arg "GIT_BRANCH=$GIT_BRANCH" --platform linux/x86_64 $BUILD_OPTS --tag "$IMAGE_NAME" . +# fi + +# # Build the Docker image cacheless (using --no-cache option) +# if [ "${RUN_BUILD_CACHELESS}" = "1" ]; then +# echo "Building Docker image (no-cache): $IMAGE_NAME" +# docker build --build-arg "GIT_BRANCH=$GIT_BRANCH" --platform linux/x86_64 $BUILD_OPTS --no-cache -t "$IMAGE_NAME" . +# fi + +if [ "${RUN_BUILD}" = "1" ] || [ "${RUN_BUILD_CACHELESS}" = "1" ]; then + echo "Building Docker Image: $IMAGE_NAME" + cache_option="--tag" + + if [ "${RUN_BUILD_CACHELESS}" = "1" ]; then + echo " (cacheless option enabled)" + cache_option="--no-cache -t" + fi + + docker build --build-arg "GIT_BRANCH=$GIT_BRANCH" --platform linux/x86_64 $BUILD_OPTS ${cache_option} "$IMAGE_NAME" . fi From cdba7a9a3a4e948226cf926cfed39738af9dc7ff Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sun, 28 Jan 2024 13:39:34 +0545 Subject: [PATCH 02/26] Renamed variables for print_test_array(arr) from t_varname -> varname --- tests/batspp_report.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/batspp_report.py b/tests/batspp_report.py index 7e19f242..812273d0 100755 --- a/tests/batspp_report.py +++ b/tests/batspp_report.py @@ -522,15 +522,15 @@ def run_batspp(input_file, output_file): def print_test_array(arr): """Print summary of test results in ARR""" for index, item in enumerate(arr): - t_name = item['test_name'] - t_rate = item['test_success_rate'] - t_min_score = item['test_min_score'] - t_count_total = item['test_count_total'] - t_count_ok = item['test_count_ok'] - t_count_eval_error = item['test_count_eval_error'] + test_name = item['test_name'] + rate = item['test_success_rate'] + min_score = item['test_min_score'] + count_total = item['test_count_total'] + count_ok = item['test_count_ok'] + count_eval_error = item['test_count_eval_error'] ## OLD: Revised format includes test passed out of test found # print(f"{index + 1}. {name} ({rate}%): threshold={min_score}%") - print(f"{index+1}. {t_name} ({t_rate}%; {t_count_ok}/{t_count_total} OK): threshold={t_min_score}%; {t_count_eval_error} evaluation errors") + print(f"{index+1}. {test_name} ({rate}%; {count_ok}/{count_total} OK): threshold={min_score}%; {count_eval_error} evaluation errors") if not arr: print("n/a") From ad35bb70f5d67fb782ac49d386694077faa59c54 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 31 Jan 2024 21:55:08 +0545 Subject: [PATCH 03/26] Replaced rm -rf with force move to --- tests/alias-cd-commands.ipynb | 49 +- tests/alias-grep-commands.ipynb | 26 +- tests/alias-trace-misc-commands.ipynb | 10 +- tests/command-override-cp-mv.ipynb | 127 +++--- .../download-and-test-tomohara-aliases.ipynb | 18 +- tests/more-tomohara-aliases-test.ipynb | 16 +- tests/test-check-errors.ipynb | 25 +- tests/test-cond-env-setting.ipynb | 10 +- tests/test-tomohara-aliases-access.ipynb | 14 +- tests/trace-extensionless-shortcut-V2.ipynb | 45 +- ...trace-extensionless-shortcut-unicode.ipynb | 50 +- tests/trace-file-manipulation.ipynb | 10 +- tests/trace-line-words-commands.ipynb | 9 +- tests/trace-python-commands.ipynb | 155 ++++--- tests/trace-unix-alias.ipynb | 430 ++++-------------- tests/trace-unix-general.ipynb | 63 ++- 16 files changed, 456 insertions(+), 601 deletions(-) diff --git a/tests/alias-cd-commands.ipynb b/tests/alias-cd-commands.ipynb index b6b073d8..51713a66 100644 --- a/tests/alias-cd-commands.ipynb +++ b/tests/alias-cd-commands.ipynb @@ -23,7 +23,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_PIVYDHUVDODH\\[\\]>\n" + "PROMPT_BLYGGVEKNCRG\\[\\]>\n" ] } ], @@ -60,29 +60,12 @@ "source": [ "# Global Setup\n", "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" \n", - "alias testuser=\"sed -r \"s/\"$USER\"+/user/g\"\"" + "alias testuser=\"sed -r \"s/\"$USER\"+/user/g\"\"\n" ] }, { "cell_type": "code", "execution_count": 5, - "id": "d29a9848", - "metadata": {}, - "outputs": [], - "source": [ - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-cp-mv\n", - "\n", - "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/..\n", - "\n", - "## OLD\n", - "# alias | wc -l" - ] - }, - { - "cell_type": "code", - "execution_count": 6, "id": "29cebb30", "metadata": {}, "outputs": [], @@ -92,15 +75,18 @@ "## *** All output from one run to the next needs to be the same ***\n", "\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-6869\n", - "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", "\n", + "TMP=/tmp/test-cp-mv\n", + "temp_dir=$TMP/test-6869\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", "command mkdir -p $temp_dir\n", + "command mkdir -p $trash_dir\n", "command cd $temp_dir\n", "\n", "## OLD\n", @@ -110,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "9e1fb88a", "metadata": {}, "outputs": [ @@ -131,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "6a1cb00b", "metadata": {}, "outputs": [ @@ -152,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "8a6085e9", "metadata": {}, "outputs": [], @@ -163,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "6cce12a4", "metadata": {}, "outputs": [], @@ -175,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "069ed8cc", "metadata": {}, "outputs": [], @@ -187,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "36fb8fbd", "metadata": {}, "outputs": [], @@ -199,12 +185,13 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "4033a985", "metadata": {}, "outputs": [], "source": [ - "rm -rf ./* > /dev/null\n", + "## BAD: rm -rf ./* > /dev/null\n", + "command mv -f * $trash_dir\n", "# mkdir testdir89 testdir90\n", "command mkdir testdir89 testdir90\n", "echo \"Testfile1\" > testdir89/f11.txt\n", @@ -213,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "e4b7b6fc", "metadata": {}, "outputs": [ @@ -235,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "14b95b96", "metadata": {}, "outputs": [ diff --git a/tests/alias-grep-commands.ipynb b/tests/alias-grep-commands.ipynb index c2c6630c..10fb0463 100644 --- a/tests/alias-grep-commands.ipynb +++ b/tests/alias-grep-commands.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_MKEITQULSTJS\\[\\]>\n" + "PROMPT_XYBNYRKDCVHU\\[\\]>\n" ] } ], @@ -64,10 +64,7 @@ "# Global Setup\n", "\n", "# Setting a temp directory for tests\n", - "TMP=/tmp/test-grep\n", - "\n", - "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/.." + "TMP=/tmp/test-grep" ] }, { @@ -80,7 +77,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "437\n" + "439\n" ] } ], @@ -119,17 +116,17 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-7371\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", + "command mkdir -p $temp_dir\n", + "command mkdir -p $trash_dir\n", + "command cd $temp_dir\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", "\n", - "command mkdir -p \"$temp_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", - "\n", "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "## OLD\n", "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -145,7 +142,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "440\n" + "442\n" ] } ], @@ -224,8 +221,8 @@ "# Global Setup\n", "\n", "## SETTING UP FOR GREP TEST\n", - "## BAD: \n", - "rm -rf ./* > /dev/null\n", + "## BAD: rm -rf ./* > /dev/null\n", + "# Not recommended as not contents in directory: mv -f ./* $trash_dir\n", "\n", "# THE WORD TO BE TESTED - sensitive\n", "command mkdir testdir1 testdir2\n", @@ -466,7 +463,8 @@ "# # # ISSUE\n", "# # $ make-file-listing\n", "# | cp: cannot stat 'ls-aR.list': No such file or directory\n", - "# | chmod: cannot access './backup/ls-aR.list': No such file or directory\n" + "# | chmod: cannot access './backup/ls-aR.list': No such file or directory\n", + "command mv -f * $trash_dir" ] } ], diff --git a/tests/alias-trace-misc-commands.ipynb b/tests/alias-trace-misc-commands.ipynb index 0fbdb6d1..78675a81 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -77,8 +77,10 @@ "## *** All output from one run to the next needs to be the same ***\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-1210\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "##\n", - "mkdir -p \"$temp_dir\"" + "mkdir -p \"$temp_dir\"\n", + "mkdir -p \"$trash_dir\"" ] }, { @@ -819,8 +821,8 @@ "save_HOME=$HOME\n", "HOME=$PWD\n", "mkdir -p $HOME/info\n", - "# BAD BUT REQUIRED\n", - "rm -rf ./* > /dev/null\n", + "# BAD: rm -rf ./* > /dev/null\n", + "command mv -f * $trash_dir\n", "echo \"THIS IS A NOICE SIGNATURE\" > $HOME/info/.noice-signature" ] }, @@ -933,7 +935,7 @@ "## BAD: do this outside of Jupyter (e.g., in case temp_dir set to /tmp)!\n", "## # NEW (Remove temp after use)\n", "## rm -rf $temp_dir > /dev/null\n", - "rm $HOME/info/.noice-signature" + "command mv $HOME/info/.noice-signature " ] }, { diff --git a/tests/command-override-cp-mv.ipynb b/tests/command-override-cp-mv.ipynb index 7cb5c9cb..d23d760d 100644 --- a/tests/command-override-cp-mv.ipynb +++ b/tests/command-override-cp-mv.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_PVEEUJXMIVCI\\[\\]>\n" + "PROMPT_LVTIODRVTGVY\\[\\]>\n" ] } ], @@ -76,7 +76,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "443\n" + "441\n" ] } ], @@ -84,10 +84,10 @@ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 1210)\n", "## *** All output from one run to the next needs to be the same ***\n", - "TMP=./tmp/test-cp-mv\n", - "BIN_DIR=$PWD/..\n", - "## temp_dir=$TMP/test-$$\n", + "\n", + "TMP=/tmp/test-cp-mv\n", "temp_dir=$TMP/test-1210\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -95,8 +95,8 @@ "# cd \"$temp_dir\"\n", "# pwd | testuser\n", "\n", + "command mkdir -p \"$trash_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", "alias | wc -l\n", @@ -116,7 +116,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "443\n" + "441\n" ] } ], @@ -135,7 +135,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "474\n" + "475\n" ] } ], @@ -198,17 +198,28 @@ "# ls -l ./mvtest_dir1 | awk '!($6=\"\")' | testnum | testuser\n", "# linebr\n", "\n", - "rm -rf ./* > /dev/null" + "# BAD: rm -rf ./* > /dev/null\n", + "# command mv -f * \"$trash_dir\"" ] }, { "cell_type": "code", "execution_count": 11, - "id": "11bb8f94", + "id": "01f003bf", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed 'testdir1' -> '/tmp/test-cp-mv/_trash-20240130214644/testdir1'\n" + ] + } + ], "source": [ + "## WORK OF ALIASES\n", "## CREATES TEST SUBJECTS\n", + "mv -f * $trash_dir\n", "touch abc def ghi\n", "mkdir mvtest_dir1" ] @@ -216,7 +227,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "01f003bf", + "id": "86397b57", "metadata": {}, "outputs": [ { @@ -230,7 +241,6 @@ } ], "source": [ - "## WORK OF ALIASES\n", "mv abc ./mvtest_dir1\n", "move def ./mvtest_dir1\n", "move-force ghi ./mvtest_dir1" @@ -247,7 +257,7 @@ "output_type": "stream", "text": [ "total N \n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" ] } ], @@ -267,9 +277,9 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" ] } ], @@ -313,9 +323,19 @@ "execution_count": 16, "id": "117d6e03", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[0m\u001b[01;34mmvtest_dir1\u001b[0m\n" + ] + } + ], "source": [ - "rm -rf ./* > /dev/null" + "# BAD: rm -rf ./* > /dev/null\n", + "ls\n", + "command mv -f * \"$trash_dir\"" ] }, { @@ -365,10 +385,10 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" ] } ], @@ -388,9 +408,9 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" ] } ], @@ -476,14 +496,14 @@ "output_type": "stream", "text": [ "total NN \n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -505,14 +525,14 @@ "output_type": "stream", "text": [ "total NN \n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -554,15 +574,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", - "Usage: /home/userxf333/tomasProject/shell-scripts/copy-readonly.sh source-file [--force] [--verbose] [file | directory]\n", - "\n", - "Examples (under Bash):\n", - "\n", - " /home/userxf333/tomasProject/shell-scripts/copy-readonly.sh ~/.bashrc ~/dot-file-archive\n", - "\n", - " for f in copyright.py search_page.mako index.mako visual_diff_server.py; do copy-readonly $f ~/visual-diff; done\n", - "\n" + "copy-readonly.sh: command not found\n" ] } ], @@ -578,7 +590,8 @@ "metadata": {}, "outputs": [], "source": [ - "rm -rf ./* > /dev/null\n", + "# BAD: rm -rf ./* > /dev/null\n", + "command mv -f * \"$trash_dir\"\n", "mkdir testdir1" ] }, @@ -592,12 +605,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "-r--r--r-- N userxf333 userxf333 NNNN NN NN:NN ./testdirN//.bashrc\n" + "copy-readonly.sh: command not found\n" ] } ], "source": [ - "copy-readonly ~/.bashrc ./testdir1/ | awk '!($6=\"\")' | testnum | testuser" + "copy-readonly ~/.bashrc testdir1 | awk '!($6=\"\")' | testnum | testuser" ] }, { @@ -610,12 +623,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "# ~/.bashrc: executed by bash(1) for non-login shells.\n" + "cat: testdir1/.bashrc: No such file or directory\n" ] } ], "source": [ - "cat ./testdir1/.bashrc | head -n 1" + "cat testdir1/.bashrc | head -n 1" ] }, { @@ -647,7 +660,7 @@ "output_type": "stream", "text": [ "total N \n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN testdirN\n" + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN testdirN\n" ] } ], diff --git a/tests/download-and-test-tomohara-aliases.ipynb b/tests/download-and-test-tomohara-aliases.ipynb index 71cc509c..57fd6d32 100644 --- a/tests/download-and-test-tomohara-aliases.ipynb +++ b/tests/download-and-test-tomohara-aliases.ipynb @@ -6,8 +6,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Warning: this creates a temporary directory for aliases\n", - "/bin/rm -rf /tmp/tomasohara-shell-scripts/*" + "## BAD APPROACH: rm -rf is very dangerous\n", + "## Warning: this creates a temporary directory for aliases\n", + "# /bin/rm -rf /tmp/tomasohara-shell-scripts/*" ] }, { @@ -17,9 +18,12 @@ "outputs": [], "source": [ "# Set directory for alias work\n", + "# Creation of temp directory as trash\n", "export TEMP_TOM_BIN=/tmp/tomasohara-shell-scripts\n", + "export trash_dir=/tmp/_trash-$(date \"+%Y%m%d%H%M%S\")\n", "export TEMP_TOM_ALIAS_FILE=\"$TEMP_TOM_BIN/tomohara-aliases.bash\"\n", "mkdir -p \"$TEMP_TOM_BIN\"\n", + "mkdir -p \"$trash_dir\"\n", "command cd \"$TEMP_TOM_BIN\"" ] }, @@ -145,6 +149,16 @@ "source": [ "show-macros | { [ $(wc -l < /dev/stdin) -ne 0 ]; echo $?; }" ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "# Removed the testfile to remove everything after completion\n", + "command mv -f * \"$trash_dir\"" + ] } ], "metadata": { diff --git a/tests/more-tomohara-aliases-test.ipynb b/tests/more-tomohara-aliases-test.ipynb index 5dda6c97..9d7e12d8 100644 --- a/tests/more-tomohara-aliases-test.ipynb +++ b/tests/more-tomohara-aliases-test.ipynb @@ -46,9 +46,11 @@ "source": [ "# Setup temp. dir\n", "# note: variable not used in rm as a precaution\n", - "/bin/rm -rf \"/tmp/test-dir-15485863\"\n", + "# BAD: /bin/rm -rf \"/tmp/test-dir-15485863\"\n", "test_dir=\"/tmp/test-dir-15485863\"\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "mkdir -p \"$test_dir\"\n", + "mkdir -p \"$trash_dir\"\n", "command cd \"$test_dir\"" ] }, @@ -177,13 +179,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "-rw-rw-r-- N username N mon hh:mm mno\n" + "-rw-rw-r-- N username N mon hh:mm mno\n" ] } ], "source": [ "cat dir_perl.out | head -n 4 | tail -n 1 | testnum" ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "# Remove everything after use\n", + "command mv -f * \"$trash_dir\"" + ] } ], "metadata": { diff --git a/tests/test-check-errors.ipynb b/tests/test-check-errors.ipynb index 2cc1d9bc..11029513 100644 --- a/tests/test-check-errors.ipynb +++ b/tests/test-check-errors.ipynb @@ -27,7 +27,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_NOJPPBQVRZOM\\[\\]>\n" + "PROMPT_NSGMXBMINMVZ\\[\\]>\n" ] } ], @@ -84,7 +84,10 @@ "# pwd\n", "\n", "temp_dir=$TMP/test-2334\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", @@ -159,12 +162,21 @@ "execution_count": 9, "id": "f965b950", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Defaulting to user installation because normal site-packages is not writeable\n", + "Requirement already satisfied: mezcla in /home/aveey/.local/lib/python3.10/site-packages (1.3.9.6)\n" + ] + } + ], "source": [ "## OLD\n", "## pip3 install mezcla | testnum > /dev/null\n", - "## Explicit approach\n", - "pip3 install mezcla --break-system-packages > /dev/null" + "## Explicit approach (debian-like): pip3 install mezcla --break-system-packages > /dev/null\n", + "pip3 install mezcla 2> /dev/null" ] }, { @@ -272,7 +284,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "True\n" + "False\n" ] } ], @@ -375,7 +387,8 @@ "metadata": {}, "outputs": [], "source": [ - "/bin/rm -rf $temp_dir > /dev/null" + "# BAD: /bin/rm -rf $temp_dir > /dev/null\n", + "command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/test-cond-env-setting.ipynb b/tests/test-cond-env-setting.ipynb index dcb40c1d..14eda4d9 100644 --- a/tests/test-cond-env-setting.ipynb +++ b/tests/test-cond-env-setting.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_RGGQLGHSXGBZ\\[\\]>\n" + "PROMPT_OCDYSMBBXUCA\\[\\]>\n" ] } ], @@ -99,13 +99,14 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-1710\n", - "\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", @@ -209,13 +210,13 @@ "output_type": "stream", "text": [ "total N \n", - "drwxr-xr-x N userxf333 userxf333 N tmp\n" + "drwxrwxr-x N userxf333 userxf333 N tmp\n" ] } ], "source": [ "# USE OF ENV VARIABLE TO CREATE A SUB-DIRECTORY\n", - "rm -rf ./* > /dev/null\n", + "# BAD: rm -rf ./* > /dev/null\n", "mkdir -p $COND_ENV_TEST_TEMP\n", "ls -l | awk '!($6=$7=$8=\"\")' | testnum | testuser" ] @@ -268,6 +269,7 @@ } ], "source": [ + "command mv -f * \"$trash_dir\"\n", "echo \"Done!\"" ] } diff --git a/tests/test-tomohara-aliases-access.ipynb b/tests/test-tomohara-aliases-access.ipynb index 83042556..168b9e84 100644 --- a/tests/test-tomohara-aliases-access.ipynb +++ b/tests/test-tomohara-aliases-access.ipynb @@ -16,11 +16,14 @@ "outputs": [], "source": [ "# Set directory for alias work\n", - "export TEMP_TOM_BIN=tmp/tomasohara-shell-scripts\n", + "export TEMP_TOM_BIN=/tmp/tomasohara-shell-scripts\n", "export TOM_ALIAS_FILE=\"$TEMP_TOM_BIN/tomohara-aliases.bash\"\n", "# mkdir -p \"$TEMP_TOM_BIN\"\n", "## OLD\n", - "command mkdir -p \"$TEMP_TOM_BIN\"" + "export trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "command mkdir -p \"$TEMP_TOM_BIN\"\n", + "command mkdir -p \"$trash_dir\"\n", + "command cd \"$TEMP_TOM_BIN\"" ] }, { @@ -34,7 +37,7 @@ "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", - "100 145k 100 145k 0 0 192k 0 --:--:-- --:--:-- --:--:-- 192k\n" + "100 146k 100 146k 0 0 363k 0 --:--:-- --:--:-- --:--:-- 363k\n" ] } ], @@ -53,7 +56,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "tmp/tomasohara-shell-scripts/tomohara-aliases.bash: Bourne-Again shell script, Unicode text, UTF-8 text executable\n" + "/tmp/tomasohara-shell-scripts/tomohara-aliases.bash: Bourne-Again shell script, Unicode text, UTF-8 text executable\n" ] } ], @@ -99,7 +102,8 @@ "source": [ "## OLD\n", "# rm -rf \"$TEMP_TOM_BIN\"\n", - "rm -rf \"$TEMP_TOM_BIN\" > /dev/null" + "# BAD: rm -rf \"$TEMP_TOM_BIN\" > /dev/null\n", + "command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index 0100f43f..747bbfee 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_QEEKCWGSYOEQ\\[\\]>\n" + "PROMPT_XQUNOUSZZXLT\\[\\]>\n" ] } ], @@ -72,11 +72,13 @@ "outputs": [], "source": [ "temp_dir=$TMP/test-3570\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD \n", "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"\n", "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -213,7 +215,8 @@ } ], "source": [ - "rm -rf ./* > /dev/null\n", + "# BAD: rm -rf ./* > /dev/null\n", + "command mv -f * \"$trash_dir\"\n", "printf \"TOP\\nTHIS IS A TEST\\nBOTTOM\" > test.txt\n", "printf \"THIS IS A FILE TO MOVE\" > tomove.txt\n", "command mkdir newdir1\n", @@ -294,6 +297,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "ps_mine.sh: command not found\n", "N\n" ] } @@ -314,7 +318,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n" + "do_rcsdiff.sh: command not found\n" ] } ], @@ -413,15 +417,15 @@ "name": "stdout", "output_type": "stream", "text": [ - " Suppress normal output; instead print a count of matching lines\n", - " Suppress normal output; instead print the name of each input\n", - " file from which no output would normally have been printed.\n", + " Suppress normal output; instead print a count of matching lines\n", " Suppress normal output; instead print the name of each input\n", + " file from which no output would normally have been printed.\n", + " Suppress normal output; instead print the name of each input\n", " file from which output would normally have been printed.\n", - " matching lines are output, grep ensures that the standard input\n", - " stops after NUM matching lines, it outputs any trailing context\n", - " not output a count greater than NUM. When the -v or\n", - " --invert-match option is also used, grep stops after outputting\n", + " output, grep ensures that the standard input is positioned to\n", + " lines, it outputs any trailing context lines. When the -c or\n", + " --count option is also used, grep does not output a count\n", + " used, grep stops after outputting NUM non-matching lines.\n", " with each such part on a separate output line.\n", " Quiet; do not write anything to standard output. Exit\n", " line of output. If -o (--only-matching) is specified, print the\n", @@ -435,13 +439,13 @@ " By default, TYPE is binary, and grep suppresses output after\n", " null input binary data is discovered, and suppresses output\n", " lines that contain improperly encoded data. When some output is\n", - " suppressed, grep follows any output with a message to standard\n", + " suppressed, grep follows any output with a one-line message\n", " Warning: The -a option might output binary garbage, which can\n", " have nasty side effects if the output is a terminal and if the\n", " Use line buffering on output. This can cause a performance\n", " Treat input and output data as sequences of lines, each\n", - " Controls how the --color option highlights output. Its value is\n", - " The following example outputs the location and contents of any line\n", + " various parts of the output. Its value is a colon-separated\n", + " The following example outputs the location and contents of any line\n", " rectory whose names contain “g” and end in “.h”. The -n option outputs\n", " file names to be output even if only one file name happens to be of the\n" ] @@ -463,6 +467,8 @@ "name": "stdout", "output_type": "stream", "text": [ + "Can't exec \"domainname.sh\": No such file or directory at /home/aveey/tomProject/shell-scripts/common.perl line 549.\n", + "readline() on closed filehandle RUN_COMMAND_FILE at /home/aveey/tomProject/shell-scripts/common.perl line 550.\n", "N\n" ] } @@ -684,7 +690,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "cat\tN\n" + "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" ] } ], @@ -704,7 +710,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "cat\tN\n" + "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" ] } ], @@ -724,7 +730,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "cat(N):user\tN\n" + "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" ] } ], @@ -817,7 +823,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "49d6d56d", "metadata": {}, "outputs": [ @@ -825,11 +831,16 @@ "name": "stdout", "output_type": "stream", "text": [ + "\u001b[0m\u001b[01;34mbackup\u001b[0m \u001b[01;34mduplicates\u001b[0m \u001b[01;34mnewdir1\u001b[0m\n", + "mv: cannot move 'backup' to '/tmp/test-extensionless/_trash-20240131211227/backup': Directory not empty\n", + "mv: cannot move 'duplicates' to '/tmp/test-extensionless/_trash-20240131211227/duplicates': Directory not empty\n", + "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_trash-20240131211227/newdir1': Directory not empty\n", "END\n" ] } ], "source": [ + "command mv -f * \"$trash_dir\"\n", "echo \"END\"" ] } diff --git a/tests/trace-extensionless-shortcut-unicode.ipynb b/tests/trace-extensionless-shortcut-unicode.ipynb index e3e9539f..0903ba97 100644 --- a/tests/trace-extensionless-shortcut-unicode.ipynb +++ b/tests/trace-extensionless-shortcut-unicode.ipynb @@ -10,7 +10,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_WFNCZYJAECUR\\[\\]>\n" + "PROMPT_YBFCLBLVSGJA\\[\\]>\n" ] } ], @@ -49,7 +49,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "440\n" + "438\n" ] } ], @@ -69,8 +69,10 @@ "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"\n", "\n", "## OLD\n", @@ -134,12 +136,21 @@ "execution_count": 8, "id": "2b491d21", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mv: cannot stat '*': No such file or directory\n" + ] + } + ], "source": [ "## OLD\n", "# pwd\n", "# rm -rf ./*\n", - "rm -rf ./* > /dev/null\n", + "## BAD: rm -rf ./* > /dev/null\n", + "command mv -f * \"$trash_dir\"\n", "uname -r > version1.txt" ] }, @@ -181,7 +192,7 @@ "output_type": "stream", "text": [ "XhXr\torX\toXXsXt\tXnXoXing\n", - "X.X.X-XX-XmXXX: XX\n", + "X.X.X-XXXXXXXX-gXnXriX: XX\n", "X\tXXXX\tX\tXX\n", ".\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", @@ -190,12 +201,20 @@ "-\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", - "-\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", - "m\tXXXX\tXX\tXX\n", + "X\tXXXX\tX\tXX\n", "X\tXXXX\tXX\tXX\n", "X\tXXXX\tXX\tXX\n", "X\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "-\tXXXX\tXX\tXX\n", + "g\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "n\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "r\tXXXX\tXX\tXX\n", + "i\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", "\n" ] } @@ -215,7 +234,7 @@ "output_type": "stream", "text": [ "XhXr\torX\toXXsXt\tXnXoXing\n", - "X.X.X-XX-XmXXX: XX\n", + "X.X.X-XXXXXXXX-gXnXriX: XX\n", "X\tXXXX\tX\tXX\n", ".\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", @@ -224,11 +243,19 @@ "-\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", - "-\tXXXX\tX\tXX\n", "X\tXXXX\tX\tXX\n", - "m\tXXXX\tXX\tXX\n", + "X\tXXXX\tX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "X\tXXXX\tXX\tXX\n", + "-\tXXXX\tXX\tXX\n", + "g\tXXXX\tXX\tXX\n", "X\tXXXX\tXX\tXX\n", + "n\tXXXX\tXX\tXX\n", "X\tXXXX\tXX\tXX\n", + "r\tXXXX\tXX\tXX\n", + "i\tXXXX\tXX\tXX\n", "X\tXXXX\tXX\tXX\n", "\n" ] @@ -301,7 +328,8 @@ } ], "source": [ - "echo \"END\"" + "echo \"END\"\n", + "command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-file-manipulation.ipynb b/tests/trace-file-manipulation.ipynb index dc69016b..b1b43236 100644 --- a/tests/trace-file-manipulation.ipynb +++ b/tests/trace-file-manipulation.ipynb @@ -27,7 +27,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_DXHRQXUOVQEL\\[\\]>\n" + "PROMPT_TDITLAHWPHUL\\[\\]>\n" ] } ], @@ -101,7 +101,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-9890\n", - "\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", @@ -109,6 +109,7 @@ "# pwd\n", "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", @@ -173,7 +174,7 @@ "metadata": {}, "outputs": [], "source": [ - "rm -rf ./* > /dev/null\n", + "# bad: rm -rf ./* > /dev/null\n", "\n", "## NEED HELP\n", "# $ asc-it freemem_mb.txt\n", @@ -628,7 +629,8 @@ "outputs": [], "source": [ "# CLEARS THE TEST FOLDER\n", - "rm -rf ./* > /dev/null" + "# Bad: rm -rf ./* > /dev/null\n", + "command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-line-words-commands.ipynb b/tests/trace-line-words-commands.ipynb index 421977d4..a33d82d6 100644 --- a/tests/trace-line-words-commands.ipynb +++ b/tests/trace-line-words-commands.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_LAUPWREDQERO\\[\\]>\n" + "PROMPT_LZVBUZWMGJED\\[\\]>\n" ] } ], @@ -81,6 +81,9 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-6439\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", + "command mkdir -p \"$trash_dir\"\n", "command mkdir -p \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", @@ -171,7 +174,7 @@ "# printf \"This is another-test file\" >> test2.txt\n", "# printf \"This is test-file 3\" >> test3.txt\n", "# printf \"This is a test-file 4\" >> test4.txt\n", - "rm -rf ./* > /dev/null\n", + "\n", "printf \"Hi Mom,\\nThis is the use of printf\\nI can use a backslash n to start a new line\\n1\\n2\\n3\" > abc-test.txt\n", "printf \"This is another-test file\" > test2.txt\n", "printf \"This is test-file 3\" > test3.txt\n", @@ -360,7 +363,7 @@ "source": [ "## OLD & BAD\n", "# rm -rf ./* > /dev/null\n", - "rm -rf \"$temp_dir\" > /dev/null\n", + "command mv -f * \"$trash_dir\"\n", "echo \"Done\"" ] } diff --git a/tests/trace-python-commands.ipynb b/tests/trace-python-commands.ipynb index dd6ea97c..9bcea2ac 100644 --- a/tests/trace-python-commands.ipynb +++ b/tests/trace-python-commands.ipynb @@ -165,20 +165,28 @@ { "cell_type": "code", "execution_count": 10, + "id": "7b9a14cc", + "metadata": {}, + "outputs": [], + "source": [ + "BIN_DIR=$PWD/..\n", + "TMP=/tmp/trace-python-commands\n", + "temp_dir=$TMP/test-7766\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", + "command cd " + ] + }, + { + "cell_type": "code", + "execution_count": 11, "id": "ab954c7f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/tmp/trace-python-commands/test-7766\n" - ] - } - ], + "outputs": [], "source": [ "# Global Setup\n", - "BIN_DIR=$PWD/..\n", + "\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 7766)\n", "## *** All output from one run to the next needs to be the same ***\n", @@ -186,12 +194,14 @@ "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", " TMP=/tmp/trace-python-commands; \n", " # note: a little redundancy is to avoid a lot of catastrophe!\n", - " /bin/rm -rf /tmp/trace-python-commands/*;\n", + " # BAD: /bin/rm -rf /tmp/trace-python-commands/*;\n", + " # command mv -f $TMP \"$trash_dir\"\n", "fi\n", + "\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-7766\n", + "# temp_dir=$TMP/test-7766\n", + "# trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", - "mkdir -p \"$temp_dir\"\n", "\n", "## BAD: # TODO: /bin/rm -rvf \"$temp_dir\"\n", "## NOTE: do not use rm without explicit base to avoid inadvertent deletions!\n", @@ -199,7 +209,7 @@ "\n", "## OLD: cd \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", - "pwd\n", + "# pwd\n", "\n", "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -207,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "bb14e4df", "metadata": {}, "outputs": [], @@ -223,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "id": "a918c4f3", "metadata": {}, "outputs": [], @@ -233,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "id": "0359b346", "metadata": {}, "outputs": [ @@ -255,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "id": "e7d436e5", "metadata": {}, "outputs": [ @@ -276,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "id": "6c5b8d28", "metadata": {}, "outputs": [ @@ -287,6 +297,7 @@ "PYTHONPATH:\n", "/home/userxf333/python\n", "/home/userxf333/python\n", + "/home/userxf333/python\n", "\n" ] } @@ -298,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "id": "ff01fc98", "metadata": {}, "outputs": [ @@ -327,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "id": "5039b234", "metadata": { "scrolled": true @@ -359,7 +370,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "id": "cab9db0c", "metadata": {}, "outputs": [ @@ -388,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "id": "207d98f0", "metadata": {}, "outputs": [], @@ -400,7 +411,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "id": "6e4b2871", "metadata": {}, "outputs": [], @@ -416,7 +427,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "id": "1a220eac", "metadata": {}, "outputs": [ @@ -437,7 +448,7 @@ "# code object from '/home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/__init__.cpython-NNN.pyc'\n", "# /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/debug.py\n", "# code object from '/home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc'\n", - "import 'mezcla.debug' # <_frozen_importlib_external.SourceFileLoader object at NxNadNNNNNdNNN>\n" + "import 'mezcla.debug' # <_frozen_importlib_external.SourceFileLoader object at NxNeNaNNaNdNaN>\n" ] } ], @@ -455,7 +466,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "id": "852d5ab4", "metadata": {}, "outputs": [ @@ -475,7 +486,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "id": "e82509c6", "metadata": {}, "outputs": [ @@ -504,7 +515,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "id": "caf8bfd0", "metadata": {}, "outputs": [], @@ -562,7 +573,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "id": "1912bb79-d984-4788-84d6-3759caf3383d", "metadata": {}, "outputs": [ @@ -580,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 27, "id": "30fc8ae2-fb50-4f19-908e-1178ef19776e", "metadata": { "scrolled": true @@ -602,7 +613,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "id": "d98b6d58", "metadata": {}, "outputs": [ @@ -628,7 +639,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 29, "id": "93146b8d", "metadata": {}, "outputs": [ @@ -654,7 +665,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "id": "9dcb601f", "metadata": {}, "outputs": [ @@ -680,7 +691,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "8080d06d", "metadata": {}, "outputs": [ @@ -706,7 +717,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "b8c1c892", "metadata": { "scrolled": true @@ -734,7 +745,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "7d6ffb96", "metadata": {}, "outputs": [ @@ -746,7 +757,7 @@ "------------------------------------------------------------------------------------------------------------------------------------\n", "Cannot run file '' because: [Errno N] No such file or directory: ''\n", "Command exited with non-zero status N\n", - "N.NNuser N.NNsystem N:NN.NNelapsed NNN%CPU (Navgtext+Navgdata NNNNNmaxresident)k\n", + "N.NNuser N.NNsystem N:NN.NNelapsed NN%CPU (Navgtext+Navgdata NNNNNmaxresident)k\n", "Ninputs+Noutputs (Nmajor+NNNNminor)pagefaults Nswaps\n" ] } @@ -766,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "c0b6f931", "metadata": {}, "outputs": [ @@ -789,7 +800,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "273938b4", "metadata": {}, "outputs": [ @@ -844,7 +855,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "9a40ffff", "metadata": {}, "outputs": [], @@ -860,7 +871,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 37, "id": "b6e7b1d1", "metadata": {}, "outputs": [], @@ -873,7 +884,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "5dbc85eb", "metadata": {}, "outputs": [], @@ -904,7 +915,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "9322aa5a", "metadata": {}, "outputs": [], @@ -931,7 +942,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "caa3332b", "metadata": {}, "outputs": [], @@ -953,7 +964,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "9c155aa3", "metadata": {}, "outputs": [], @@ -971,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "53136103", "metadata": {}, "outputs": [], @@ -986,7 +997,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "id": "31d1b151", "metadata": {}, "outputs": [], @@ -998,7 +1009,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "3b6aab89", "metadata": {}, "outputs": [], @@ -1014,7 +1025,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "88b697b0-82c6-48c2-8b0d-96d922b177b6", "metadata": {}, "outputs": [], @@ -1027,7 +1038,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "c3845ce6-bf26-423c-81f3-356acca66f8d", "metadata": {}, "outputs": [ @@ -1061,7 +1072,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 47, "id": "833520df-e503-4131-bbdd-98bd990a9d2f", "metadata": {}, "outputs": [ @@ -1089,7 +1100,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "id": "4f226d82-2376-4caf-9b40-49a742a06980", "metadata": {}, "outputs": [ @@ -1109,7 +1120,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "id": "4db32912-ca91-4791-b4d6-658674ad8403", "metadata": {}, "outputs": [ @@ -1135,7 +1146,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 50, "id": "89a01a21", "metadata": {}, "outputs": [ @@ -1145,7 +1156,7 @@ "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", - "100 1256 100 1256 0 0 1018 0 0:00:01 0:00:01 --:--:-- 1017\n", + "100 1256 100 1256 0 0 672 0 0:00:01 0:00:01 --:--:-- 672\n", "------------------------------------------------------------------------------------------------------------------------------------\n", "total NN \n", "-rw-rw-r-- N userxf333 userxf333 NN NN NN:NN abcN.py\n", @@ -1173,7 +1184,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 51, "id": "3777aa4a", "metadata": {}, "outputs": [], @@ -1184,7 +1195,25 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 52, + "id": "292f5558", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/tmp/trace-python-commands/test-7766\n" + ] + } + ], + "source": [ + "pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 53, "id": "c57545c5", "metadata": {}, "outputs": [], @@ -1196,6 +1225,16 @@ "## DEBUG:\n", "## command pwd | sed -r \"s/\"$USER\"+/user/g\"" ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "a3d18560", + "metadata": {}, + "outputs": [], + "source": [ + "command mv -f * \"$trash_dir\"" + ] } ], "metadata": { diff --git a/tests/trace-unix-alias.ipynb b/tests/trace-unix-alias.ipynb index ef3248ee..e5f5a198 100644 --- a/tests/trace-unix-alias.ipynb +++ b/tests/trace-unix-alias.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_LCBXOASFTDYH\\[\\]>\n" + "PROMPT_QPSFEBRZHROH\\[\\]>\n" ] } ], @@ -63,6 +63,7 @@ "TMP=/tmp/test-unix-alias\n", "BIN_DIR=$PWD/..\n", "temp_dir=$TMP/test-2899\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -70,6 +71,7 @@ "# pwd\n", "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"\n", "\n", "## OLD\n", @@ -166,15 +168,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "/bin/mv: cannot stat '_make.log': No such file or directory\n", - "make: Nothing to be done for 'himom.txt'.\n", - "make: Nothing to be done for 'himom.txt'.\n" + "mv: cannot stat '*': No such file or directory\n", + "do-make: command not found\n", + "cat: _make.log: No such file or directory\n" ] + }, + { + "ename": "", + "evalue": "1", + "output_type": "error", + "traceback": [] } ], "source": [ "## 1A) do-make \n", - "rm -rf ./* > /dev/null\n", + "# BAD: rm -rf ./* > /dev/null\n", + "# command mv -f * \"$trash_dir\"\n", + "\n", "mkdir testfolder\n", "echo \"Hi Mom!\" > himom.txt\n", "echo \"Hi Dad!\" > hidad.txt\n", @@ -189,19 +199,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "0198effb", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "make: Nothing to be done for 'hidad.txt'.\n", - "make: Nothing to be done for 'hidad.txt'.\n" - ] - } - ], + "outputs": [], "source": [ "do-make \"hidad.txt\"\n", "cat _make.log" @@ -209,41 +210,20 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "cb7f48dc", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "total N \n", - "-rw-r--r-- N userxf333 userxf333 N N N:N hidad.txt\n", - "-rw-r--r-- N userxf333 userxf333 N N N:N himom.txt\n", - "-rw-r--r-- N userxf333 userxf333 N N N:N _make.log\n", - "-rw-r--r-- N userxf333 userxf333 N N N:N _old_make.log\n", - "drwxr-xr-x N userxf333 userxf333 N N N:N testfolder\n" - ] - } - ], + "outputs": [], "source": [ "ls -l | awk '!($6=\"\")' | testnum | testuser" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "cd0c80db", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "do-merge MODFILE1 OLDFILE MODFILE2 > NEWFILE tf1.txt tf2.txt\n" - ] - } - ], + "outputs": [], "source": [ "# 2A) merge REPLACED BY do-merge \n", "\n", @@ -258,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "c0c74f75", "metadata": {}, "outputs": [], @@ -273,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "d6f37399", "metadata": {}, "outputs": [], @@ -289,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "b535f2eb", "metadata": {}, "outputs": [], @@ -300,18 +280,10 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "761a2cd8", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PY-TRUE\n" - ] - } - ], + "outputs": [], "source": [ "### TO FIX THE ERROR USE \"himom.txt\" --> himom.txt ###\n", "\n", @@ -328,43 +300,27 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "8f904a21", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/tmp/test-unix-alias/test-2899/himom.txt\n" - ] - } - ], + "outputs": [], "source": [ "full-dirname himom.txt" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "e38e8554", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "./himom.txt\n" - ] - } - ], + "outputs": [], "source": [ "basename-with-dir himom.txt" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "d792021b", "metadata": {}, "outputs": [], @@ -379,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "5cdac362", "metadata": {}, "outputs": [], @@ -390,21 +346,10 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "49da8c7e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Real: 0.00 seconds\n", - "User: 0.00 seconds\n", - "Sys: 0.00 seconds\n", - "Linux\n" - ] - } - ], + "outputs": [], "source": [ "## 4B) gtime (Need help to run commands)\n", "# ERROR - VI \n", @@ -421,18 +366,10 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "9bea16c5", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "VERSION_ID=\"N\"\n" - ] - } - ], + "outputs": [], "source": [ "## 4C) linux-version GIVES INFO ALL INFO ABOUT THE OS INSTALLED\n", "linux-version | grep VERSION_ID | testnum\n", @@ -441,24 +378,10 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "id": "e0e10406", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "total used free shared buff/cache available \n", - "Mem: N N N N N N \n", - "Swap: N N N \n", - "N:N:N up N:N, N user, load average: N.N, N.N\n", - "USER TTY FROM LOGIN@ IDLE JCPU PCPU \n", - "userxf333 ttyN ttyN N:N N:Nm N.Ns N.Ns \n", - " \n" - ] - } - ], + "outputs": [], "source": [ "## 4D) system-status - (awk removes the session-name)\n", "system-status | testnum | testuser | tail -n +2 | awk '!($8=\"\")'" @@ -466,38 +389,22 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "28e700ce", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "N\n" - ] - } - ], + "outputs": [], "source": [ "apropos-command time | grep asctime | wc -l | testnum" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "e3e42a18", "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hi Dad!\n" - ] - } - ], + "outputs": [], "source": [ "## How split-tokens work\n", "## OLD\n", @@ -508,38 +415,20 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "id": "43c24ea0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hi\n", - "Dad!\n" - ] - } - ], + "outputs": [], "source": [ "split-tokens hidad.txt" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "73ea76b9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hi\n", - "Dad!\n" - ] - } - ], + "outputs": [], "source": [ "# tokenize SPLITS THE CONTENTS IN SEVERAL LINES ()\n", "## OLD\n", @@ -549,18 +438,10 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "0ee7e74e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "This is Ubuntu!\n" - ] - } - ], + "outputs": [], "source": [ "# perl-echo ONLY PRINTS OUT THE 1ST ARGUMENT\n", "PERL_PRINT='This is Ubuntu!'\n", @@ -571,36 +452,20 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "212ef1c9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "This\n" - ] - } - ], + "outputs": [], "source": [ "perl-echo-sans-newline $PERL_PRINT" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "id": "a5d6b066", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ONE KISS IS ALL IT TAKES\n" - ] - } - ], + "outputs": [], "source": [ "# Several print commands (perl-based)\n", "perl-printf 'ONE KISS IS ALL IT TAKES\\n'\n", @@ -611,76 +476,40 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "id": "c32526fd", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n", - "3\n", - "5\n", - "7\n", - "11\n" - ] - } - ], + "outputs": [], "source": [ "perl-print '2\\n3\\n5\\n7\\n11'" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "id": "9ab09848", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "A B C D E F G\n" - ] - } - ], + "outputs": [], "source": [ "perl-print-n 'A B C D E F G\\n'" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "id": "efd7f828", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\"HELP\" \"ME!\"\n" - ] - } - ], + "outputs": [], "source": [ "quote-tokens 'HELP ME!'" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "id": "b4502821", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "localhost:N.N\n" - ] - } - ], + "outputs": [], "source": [ "# # 6A)\n", "# # Unix/Win32 networking aliases\n", @@ -693,21 +522,10 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "id": "2919fe8f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "start: Tue Sep N N:N:N PM +N N\n", - "+ eval ''\n", - "+ set - -o xtrace\n", - "end: Tue Sep N N:N:N PM +N N\n" - ] - } - ], + "outputs": [], "source": [ "## Need a filter to sensor day and month\n", "## bash-trace-on ENABLES bash tracing\n", @@ -723,21 +541,10 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "id": "943f1eb0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "start: Tue Sep N N:N:N PM +N N\n", - "+ eval ''\n", - "+ set - -o xtrace\n", - "end: Tue Sep N N:N:N PM +N N\n" - ] - } - ], + "outputs": [], "source": [ "## bash-trace-on DISABLES bash tracing\n", "bash-trace-off | testuser | testnum\n", @@ -746,22 +553,12 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "id": "ef8e82ea", "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hidad.txt _make.log \u001b[0m\u001b[01;34mtestfolder\u001b[0m tf2.txt\n", - "himom.txt _old_make.log tf1.txt tf3.txt\n", - "'tf2.txt' -> 'testfolder/tf2.txt'\n" - ] - } - ], + "outputs": [], "source": [ "# testing compression and extraction of dirs\n", "ls\n", @@ -777,81 +574,47 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "id": "fa9577fa", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "NotZero\n" - ] - } - ], + "outputs": [], "source": [ "compress-this-dir ./testfolder | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo \"NotZero\" || echo \"Zero\"; }" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "id": "e3e61188", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hidad.txt.gz _make.log.gz\ttestfolder tf2.txt.gz\n", - "himom.txt.gz _old_make.log.gz\ttf1.txt.gz tf3.txt.gz\n" - ] - } - ], + "outputs": [], "source": [ "command ls" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "id": "2adacf28", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "NotZero\n" - ] - } - ], + "outputs": [], "source": [ "ununcompress-this-dir ./testfolder | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo \"NotZero\" || echo \"Zero\"; }" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, "id": "2646670b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hidad.txt _make.log\t testfolder tf2.txt\n", - "himom.txt _old_make.log tf1.txt tf3.txt\n" - ] - } - ], + "outputs": [], "source": [ "command ls" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "id": "caa6e9af", "metadata": { "scrolled": true @@ -869,19 +632,10 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "id": "34bd5b99", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ".txt\tN\n", - ".log\tN\n" - ] - } - ], + "outputs": [], "source": [ "# count-exts counts extensions\n", "old-count-exts | testnum\n", @@ -892,26 +646,17 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "id": "ae4f0131", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ".txt\tN\n", - ".log\tN\n" - ] - } - ], + "outputs": [], "source": [ "count-exts | testnum" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "id": "1b9bea43", "metadata": {}, "outputs": [], @@ -921,20 +666,13 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "id": "c87c3dce", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Done!\n" - ] - } - ], + "outputs": [], "source": [ - "echo \"Done!\"" + "echo \"Done!\"\n", + "command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-unix-general.ipynb b/tests/trace-unix-general.ipynb index 84ef8ea2..f672e0f8 100644 --- a/tests/trace-unix-general.ipynb +++ b/tests/trace-unix-general.ipynb @@ -13,7 +13,8 @@ "## $ echo 'Hii'\n", "## | Hi?2004l\n", "# bind 'set enable-bracketed-paste off'\n", - "/bin/rm -rf /tmp/test-unix/test-3245 > /dev/null" + "\n", + "# OLD & BAD: /bin/rm -rf /tmp/test-unix/test-3245 > /dev/null" ] }, { @@ -36,7 +37,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_OHDTHCTXWIEM\\[\\]>\n" + "PROMPT_WBFDTPJVNJFD\\[\\]>\n" ] } ], @@ -84,24 +85,6 @@ { "cell_type": "code", "execution_count": 6, - "id": "0ff8f157", - "metadata": {}, - "outputs": [], - "source": [ - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-unix\n", - "\n", - "## OLD AND BAD\n", - "\n", - "## NOTE: Source it directly from the ./tests directory.\n", - "# BIN_DIR=$PWD/..\n", - "\n", - "# alias | wc -l" - ] - }, - { - "cell_type": "code", - "execution_count": 7, "id": "ab954c7f", "metadata": {}, "outputs": [], @@ -111,7 +94,9 @@ "## *** All output from one run to the next needs to be the same ***\n", "\n", "## temp_dir=$TMP/test-$$\n", + "TMP=/tmp/test-unix\n", "temp_dir=$TMP/test-3245\n", + "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -120,6 +105,7 @@ "# pwd\n", "\n", "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", @@ -130,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "ec6df159", "metadata": { "scrolled": true @@ -153,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "85787c44", "metadata": {}, "outputs": [ @@ -174,7 +160,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "15465d13", "metadata": { "scrolled": true @@ -188,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "3c57d3b0", "metadata": {}, "outputs": [ @@ -196,7 +182,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "ps_mine.sh: command not found\n", + "1\n" ] } ], @@ -206,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "2395c71a", "metadata": { "scrolled": false @@ -238,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "bc13426e", "metadata": {}, "outputs": [ @@ -267,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "b688da20", "metadata": {}, "outputs": [ @@ -296,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "775ea494", "metadata": {}, "outputs": [ @@ -325,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "6ed9a120", "metadata": {}, "outputs": [ @@ -333,7 +320,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "ps_mine.sh: command not found\n", + "1\n" ] } ], @@ -353,7 +341,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "bf36bf1a", "metadata": {}, "outputs": [ @@ -373,7 +361,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "f7af5f4b", "metadata": {}, "outputs": [ @@ -394,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "e73cd7c1", "metadata": {}, "outputs": [], @@ -410,7 +398,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "079b0855", "metadata": {}, "outputs": [ @@ -433,7 +421,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "1e7238c8", "metadata": {}, "outputs": [], @@ -447,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "7762153f", "metadata": {}, "outputs": [ @@ -460,6 +448,7 @@ } ], "source": [ + "command mv -f * \"$trash_dir\"\n", "echo \"Done\"" ] } From d61cc71dce46652a8c3d8a5c9e820a39ee13038b Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sat, 3 Feb 2024 21:43:22 +0545 Subject: [PATCH 04/26] Renamed trash directory from _trash-{date} to _temp-trash-{date} --- tests/alias-cd-commands.ipynb | 2 +- tests/alias-grep-commands.ipynb | 2 +- tests/alias-trace-misc-commands.ipynb | 2 +- tests/command-override-cp-mv.ipynb | 4 ++-- tests/download-and-test-tomohara-aliases.ipynb | 2 +- tests/more-tomohara-aliases-test.ipynb | 2 +- tests/test-check-errors.ipynb | 2 +- tests/test-cond-env-setting.ipynb | 2 +- tests/test-tomohara-aliases-access.ipynb | 2 +- tests/trace-extensionless-shortcut-V2.ipynb | 8 ++++---- tests/trace-extensionless-shortcut-unicode.ipynb | 2 +- tests/trace-file-manipulation.ipynb | 2 +- tests/trace-line-words-commands.ipynb | 2 +- tests/trace-python-commands.ipynb | 4 ++-- tests/trace-unix-alias.ipynb | 2 +- tests/trace-unix-general.ipynb | 2 +- 16 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/alias-cd-commands.ipynb b/tests/alias-cd-commands.ipynb index 51713a66..37f6d41f 100644 --- a/tests/alias-cd-commands.ipynb +++ b/tests/alias-cd-commands.ipynb @@ -83,7 +83,7 @@ "\n", "TMP=/tmp/test-cp-mv\n", "temp_dir=$TMP/test-6869\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p $temp_dir\n", "command mkdir -p $trash_dir\n", diff --git a/tests/alias-grep-commands.ipynb b/tests/alias-grep-commands.ipynb index 10fb0463..822794f3 100644 --- a/tests/alias-grep-commands.ipynb +++ b/tests/alias-grep-commands.ipynb @@ -116,7 +116,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-7371\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p $temp_dir\n", "command mkdir -p $trash_dir\n", diff --git a/tests/alias-trace-misc-commands.ipynb b/tests/alias-trace-misc-commands.ipynb index 78675a81..0c94c1c3 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -77,7 +77,7 @@ "## *** All output from one run to the next needs to be the same ***\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-1210\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "##\n", "mkdir -p \"$temp_dir\"\n", "mkdir -p \"$trash_dir\"" diff --git a/tests/command-override-cp-mv.ipynb b/tests/command-override-cp-mv.ipynb index d23d760d..802f3465 100644 --- a/tests/command-override-cp-mv.ipynb +++ b/tests/command-override-cp-mv.ipynb @@ -87,7 +87,7 @@ "\n", "TMP=/tmp/test-cp-mv\n", "temp_dir=$TMP/test-1210\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -212,7 +212,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "renamed 'testdir1' -> '/tmp/test-cp-mv/_trash-20240130214644/testdir1'\n" + "renamed 'testdir1' -> '/tmp/test-cp-mv/_temp-trash-20240130214644/testdir1'\n" ] } ], diff --git a/tests/download-and-test-tomohara-aliases.ipynb b/tests/download-and-test-tomohara-aliases.ipynb index 57fd6d32..f4444246 100644 --- a/tests/download-and-test-tomohara-aliases.ipynb +++ b/tests/download-and-test-tomohara-aliases.ipynb @@ -20,7 +20,7 @@ "# Set directory for alias work\n", "# Creation of temp directory as trash\n", "export TEMP_TOM_BIN=/tmp/tomasohara-shell-scripts\n", - "export trash_dir=/tmp/_trash-$(date \"+%Y%m%d%H%M%S\")\n", + "export trash_dir=/tmp/_temp-trash-$(date \"+%Y%m%d%H%M%S\")\n", "export TEMP_TOM_ALIAS_FILE=\"$TEMP_TOM_BIN/tomohara-aliases.bash\"\n", "mkdir -p \"$TEMP_TOM_BIN\"\n", "mkdir -p \"$trash_dir\"\n", diff --git a/tests/more-tomohara-aliases-test.ipynb b/tests/more-tomohara-aliases-test.ipynb index 9d7e12d8..5feee8a5 100644 --- a/tests/more-tomohara-aliases-test.ipynb +++ b/tests/more-tomohara-aliases-test.ipynb @@ -48,7 +48,7 @@ "# note: variable not used in rm as a precaution\n", "# BAD: /bin/rm -rf \"/tmp/test-dir-15485863\"\n", "test_dir=\"/tmp/test-dir-15485863\"\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "mkdir -p \"$test_dir\"\n", "mkdir -p \"$trash_dir\"\n", "command cd \"$test_dir\"" diff --git a/tests/test-check-errors.ipynb b/tests/test-check-errors.ipynb index 11029513..c8d7f0a9 100644 --- a/tests/test-check-errors.ipynb +++ b/tests/test-check-errors.ipynb @@ -84,7 +84,7 @@ "# pwd\n", "\n", "temp_dir=$TMP/test-2334\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p \"$temp_dir\"\n", "command mkdir -p \"$trash_dir\"\n", diff --git a/tests/test-cond-env-setting.ipynb b/tests/test-cond-env-setting.ipynb index 14eda4d9..58340447 100644 --- a/tests/test-cond-env-setting.ipynb +++ b/tests/test-cond-env-setting.ipynb @@ -99,7 +99,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-1710\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", diff --git a/tests/test-tomohara-aliases-access.ipynb b/tests/test-tomohara-aliases-access.ipynb index 168b9e84..e86f217f 100644 --- a/tests/test-tomohara-aliases-access.ipynb +++ b/tests/test-tomohara-aliases-access.ipynb @@ -20,7 +20,7 @@ "export TOM_ALIAS_FILE=\"$TEMP_TOM_BIN/tomohara-aliases.bash\"\n", "# mkdir -p \"$TEMP_TOM_BIN\"\n", "## OLD\n", - "export trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "export trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "command mkdir -p \"$TEMP_TOM_BIN\"\n", "command mkdir -p \"$trash_dir\"\n", "command cd \"$TEMP_TOM_BIN\"" diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index 747bbfee..ed079e9b 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -72,7 +72,7 @@ "outputs": [], "source": [ "temp_dir=$TMP/test-3570\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD \n", "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", @@ -832,9 +832,9 @@ "output_type": "stream", "text": [ "\u001b[0m\u001b[01;34mbackup\u001b[0m \u001b[01;34mduplicates\u001b[0m \u001b[01;34mnewdir1\u001b[0m\n", - "mv: cannot move 'backup' to '/tmp/test-extensionless/_trash-20240131211227/backup': Directory not empty\n", - "mv: cannot move 'duplicates' to '/tmp/test-extensionless/_trash-20240131211227/duplicates': Directory not empty\n", - "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_trash-20240131211227/newdir1': Directory not empty\n", + "mv: cannot move 'backup' to '/tmp/test-extensionless/_temp-trash-20240131211227/backup': Directory not empty\n", + "mv: cannot move 'duplicates' to '/tmp/test-extensionless/_temp-trash-20240131211227/duplicates': Directory not empty\n", + "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_temp-trash-20240131211227/newdir1': Directory not empty\n", "END\n" ] } diff --git a/tests/trace-extensionless-shortcut-unicode.ipynb b/tests/trace-extensionless-shortcut-unicode.ipynb index 0903ba97..1874467d 100644 --- a/tests/trace-extensionless-shortcut-unicode.ipynb +++ b/tests/trace-extensionless-shortcut-unicode.ipynb @@ -69,7 +69,7 @@ "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p \"$temp_dir\"\n", "command mkdir -p \"$trash_dir\"\n", diff --git a/tests/trace-file-manipulation.ipynb b/tests/trace-file-manipulation.ipynb index b1b43236..d33ed5e9 100644 --- a/tests/trace-file-manipulation.ipynb +++ b/tests/trace-file-manipulation.ipynb @@ -101,7 +101,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-9890\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", diff --git a/tests/trace-line-words-commands.ipynb b/tests/trace-line-words-commands.ipynb index a33d82d6..968d6830 100644 --- a/tests/trace-line-words-commands.ipynb +++ b/tests/trace-line-words-commands.ipynb @@ -81,7 +81,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-6439\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p \"$trash_dir\"\n", "command mkdir -p \"$temp_dir\"\n", diff --git a/tests/trace-python-commands.ipynb b/tests/trace-python-commands.ipynb index 9bcea2ac..dfc541a7 100644 --- a/tests/trace-python-commands.ipynb +++ b/tests/trace-python-commands.ipynb @@ -172,7 +172,7 @@ "BIN_DIR=$PWD/..\n", "TMP=/tmp/trace-python-commands\n", "temp_dir=$TMP/test-7766\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "command mkdir -p \"$temp_dir\"\n", "command mkdir -p \"$trash_dir\"\n", "command cd " @@ -200,7 +200,7 @@ "\n", "## temp_dir=$TMP/test-$$\n", "# temp_dir=$TMP/test-7766\n", - "# trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "\n", "## BAD: # TODO: /bin/rm -rvf \"$temp_dir\"\n", diff --git a/tests/trace-unix-alias.ipynb b/tests/trace-unix-alias.ipynb index e5f5a198..2174cccd 100644 --- a/tests/trace-unix-alias.ipynb +++ b/tests/trace-unix-alias.ipynb @@ -63,7 +63,7 @@ "TMP=/tmp/test-unix-alias\n", "BIN_DIR=$PWD/..\n", "temp_dir=$TMP/test-2899\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", diff --git a/tests/trace-unix-general.ipynb b/tests/trace-unix-general.ipynb index f672e0f8..7ad225e6 100644 --- a/tests/trace-unix-general.ipynb +++ b/tests/trace-unix-general.ipynb @@ -96,7 +96,7 @@ "## temp_dir=$TMP/test-$$\n", "TMP=/tmp/test-unix\n", "temp_dir=$TMP/test-3245\n", - "trash_dir=$TMP/\"_trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", From 80c6e9153762a0d09307fd0ea03b6ddd46d2a512 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Thu, 8 Feb 2024 19:01:36 +0545 Subject: [PATCH 05/26] =?UTF-8?q?Modified=20tests=20such=20that=20it=20ret?= =?UTF-8?q?urns=20a=20bool-type=20value=20(True=3D0,=20False=3D1);=20Edite?= =?UTF-8?q?d=20the=20echo=20\[=1B]633;A=07\]\[\e]0;\u@\h:=20\w\a\]${debian?= =?UTF-8?q?=5Fchroot:+($debian=5Fchroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:?= =?UTF-8?q?\[\033[01;34m\]\w\[\033[00m\]\$=20\[=1B]633;B=07\]=20message=20?= =?UTF-8?q?to=20check=20if=20it=20has=20the=20character=20'>'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/alias-calculator-commands.ipynb | 236 +++++++++----------------- 1 file changed, 82 insertions(+), 154 deletions(-) diff --git a/tests/alias-calculator-commands.ipynb b/tests/alias-calculator-commands.ipynb index a290c8c6..b61030d8 100644 --- a/tests/alias-calculator-commands.ipynb +++ b/tests/alias-calculator-commands.ipynb @@ -25,8 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "TODO:\n", - " echo \"$PS1\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\n" + "0\n" ] } ], @@ -36,34 +35,16 @@ "## TODO: PS1=\"> \"\n", "\n", "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it.\n", - "## OLD\n", - "# echo $PS1\n", - "## TODO: echo $PS1 | command grep --count --perl-regexp '[\\x00-\\x1f]'\n", - "## TEMP: echo 0\n", - "echo \"TODO:\"\n", - "echo \" echo \\\"\\$PS1\\\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\"" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "9d4c30cc", - "metadata": {}, - "outputs": [], - "source": [ - "## BAD\n", + "# echo \"TODO:\"\n", + "# echo \" echo \\\"\\$PS1\\\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\"\n", "\n", - "## Delete all aliases and function\n", - "## TODO: Instead start from pristine environment\n", - "# unalias -a\n", - "# alias | wc -l\n", - "# for f in $(typeset -f | egrep '^\\w+'); do unset -f $f; done\n", - "# typeset -f | egrep '^\\w+' | wc -l" + "actual=${PS1: -1}\n", + "[ \"$actual\" = \">\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "cddb7968", "metadata": {}, "outputs": [ @@ -87,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "17618199", "metadata": {}, "outputs": [], @@ -102,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "c10b6bb2", "metadata": {}, "outputs": [ @@ -130,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "09763c6c", "metadata": {}, "outputs": [ @@ -146,64 +127,14 @@ "## OLD\n", "## Count functions\n", "# typeset -f | egrep '^\\w+' | wc -l\n", - "# Count functions with dir\n", - "dir_functions=$(typeset -f | egrep '\\-dir\\b' | wc -l)\n", - "[ \"$dir_functions\" -gt 40 ]; echo \"$?\"" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "dd5cdadb", - "metadata": {}, - "outputs": [], - "source": [ - "## OLD\n", - "# ## NOTE: For reproducability, the directory name needs to be fixed\n", - "# ## In place of $$, use a psuedo random number (e,g., 1210)\n", - "# ## *** All output from one run to the next needs to be the same ***\n", - "# # Setting a temp directory for tests\n", - "# TMP=/tmp/test-calc\n", - "\n", - "# ## NOTE: Source it directly from the ./tests directory.\n", - "# BIN_DIR=$PWD/..\n", "\n", - "# ## temp_dir=$TMP/test-$$\n", - "# temp_dir=$TMP/test-1210\n", - "\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd\n", - "\n", - "# Global setup\n", - "# TODO1: move above\n", - "## NOTE: For reproducability, the directory name needs to be fixed\n", - "## In place of $$, use a psuedo random number (e,g., 7919)\n", - "## *** All output from one run to the next needs to be the same ***\n", - "#\n", - "# Test safe symbolic links\n", - "## temp_dir=$TMP/test-$$\n", - "temp_dir=\"$TMP/test-1210\"\n", - "#\n", - "# Move existing file out of way\n", - "rename-with-file-date \"$temp_dir\" > /dev/null\n", - "#\n", - "# Create dir and make current\n", - "mkdir -p \"$temp_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", - "## BAD:\n", - "## cd \"$temp_dir\"\n", - "## pwd\n", - "command cd \"$temp_dir\"\n", - "\n", - "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" + "dir_functions=$(typeset -f | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_functions\" -gt 35 ]; echo \"$?\"" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "id": "feccc2bf", "metadata": {}, "outputs": [], @@ -217,39 +148,31 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "5efe828f", - "metadata": {}, - "outputs": [], - "source": [ - "## BAD\n", - "## Making sure that the tests run from ./tests directory\n", - "# source $BIN_DIR/tomohara-aliases.bash\n", - "\n", - "## BAD APPROACH: Test must be individual (fixed)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "64b58554", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "-19.00000000000000000000\n" + "0\n" ] } ], "source": [ - "old-calc \"24 / 4.0 - (35 / 7.0) * 5\" " + "# Actual/Expected comparision to be used for floating points\n", + "\n", + "actual=$(old-calc \"24 / 4 - (35 / 7) * 5\")\n", + "expected=-19.0\n", + "[ \"$(echo \"$actual == $expected\" | bc)\" -eq 1 ]; echo $?\n" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "id": "829c5541", "metadata": {}, "outputs": [ @@ -257,17 +180,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "32\n" + "0\n" ] } ], "source": [ - "old-calc \"(2^3)*(2^2)\"" + "[ \"$(old-calc \"(2^3)*(2^2)\")\" -gt 2 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "id": "aa669541", "metadata": {}, "outputs": [ @@ -275,17 +198,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "121\n" + "0\n" ] } ], "source": [ - "old-calc \"5*4*3*2*1+1\" " + "[ \"$(old-calc \"5*4*3*2*1+1\")\" -gt 0 ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "ed1a5eb4", "metadata": {}, "outputs": [ @@ -293,17 +216,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "207\n" + "0\n" ] } ], "source": [ - "old-perl-calc \"70 + 69 + 68\"" + "[ $(old-perl-calc \"70 + 69 + 68\") -eq 207 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "04fce435", "metadata": {}, "outputs": [ @@ -311,17 +234,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.001953125\n" + "0\n" ] } ], "source": [ - "old-perl-calc \"8/8/8/8/8\"" + "actual=$(old-perl-calc \"8/8/8/8/8\")\n", + "expected=0.001953125\n", + "[ $actual = $expected ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "e92321e0", "metadata": {}, "outputs": [ @@ -329,17 +254,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "17950953796\n" + "0\n" ] } ], "source": [ - "hex2dec 42Df5D144 " + "[ $(hex2dec \"42Df5D144\") = \"17950953796\" ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "118fe218", "metadata": {}, "outputs": [ @@ -347,18 +272,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "15\n" + "0\n" ] } ], "source": [ "# (F)16 = (15)10\n", - "hex2dec \"F\"" + "[ $(hex2dec \"F\") -eq 15 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "3fee2eef", "metadata": {}, "outputs": [ @@ -366,17 +291,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "80\n" + "0\n" ] } ], "source": [ - "dec2hex \"128\"" + "[ $(dec2hex \"128\") -eq \"80\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "id": "94774cdc", "metadata": {}, "outputs": [ @@ -390,12 +315,12 @@ ], "source": [ "#inclusion of non-decimal numbers yield 0 as a result\n", - "dec2hex \"A12\" " + "[ $(dec2hex \"A12\") -eq 0 ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "id": "1dc08dcd", "metadata": {}, "outputs": [ @@ -403,17 +328,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "243\n" + "0\n" ] } ], "source": [ - "bin2dec \"11110011\"" + "[ $(bin2dec \"11110011\") -eq 243 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "id": "44b20f00", "metadata": {}, "outputs": [ @@ -421,18 +346,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "6\n" + "0\n" ] } ], "source": [ "#inclusion of non-binary numbers leads to error\n", - "bin2dec \"0110\" " + "[ $(bin2dec \"0110\") -lt 8 ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 19, "id": "8f172b7c", "metadata": {}, "outputs": [ @@ -440,17 +365,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "10001001100010011\n" + "0\n" ] } ], "source": [ - "dec2bin \"70419\"" + "# Due to longer binary number\n", + "[ $(dec2bin \"70419\" | wc -c) -eq 18 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 20, "id": "ae402a7b", "metadata": {}, "outputs": [ @@ -458,18 +384,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "1010\n" + "0\n" ] } ], "source": [ "#inclusion of non-decimal number leads to error\n", - "dec2bin \"10\" " + "[ $(dec2bin \"10\") -eq 1010 ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 21, "id": "167a8dc9", "metadata": {}, "outputs": [ @@ -477,17 +403,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "NNN\n" + "0\n" ] } ], "source": [ - "dec2bin \"7\" | testnumhex" + "actual=$(dec2bin \"7\" | testnumhex)\n", + "expected=\"NNN\"\n", + "[ \"$actual\" == \"$expected\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 22, "id": "6b66e5d9", "metadata": {}, "outputs": [ @@ -495,17 +423,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.833\n" + "0\n" ] } ], "source": [ - "calc \"100/(24*5)\"" + "actual=$(calc \"100/(24*5)\")\n", + "expected=0.833\n", + "[ $actual = $expected ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "id": "d3238213", "metadata": {}, "outputs": [ @@ -513,18 +443,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "16.333333\n" + "0\n" ] } ], "source": [ "# Sets precisions to 6 places of decimal\n", - "calc-prec6 \"49/3\"" + "actual=$(calc-prec6 \"49/3\")\n", + "expected=\"16.333333\"\n", + "[ $actual = $expected ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 24, "id": "939c678f", "metadata": {}, "outputs": [ @@ -532,17 +464,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "33.333\n" + "0\n" ] } ], "source": [ - "calc-init \"+\" \"100/3\"" + "[ \"$(calc-init \"+\" \"100/3\")\" = \"33.333\" ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 25, "id": "ad1bf020", "metadata": {}, "outputs": [ @@ -550,27 +482,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "4\n" + "0\n" ] } ], "source": [ - "calc-int \"100/23\"" + "[ \"$(calc-int \"100/23\")\" -eq 4 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "id": "ef676520", "metadata": { "scrolled": true }, "outputs": [], "source": [ - "## BAD\n", - "# pwd\n", - "# rm -rf ./* > /dev/null\n", - "\n", "## OLD: hv commented on tomohara-aliases.bash\n", "# ps -l > testforhv.txt\n", "# hv testforhv.txt | testnumhex" From d6aa35c1ac9178a84a2310be5f84e44b9611686e Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Thu, 8 Feb 2024 19:45:54 +0545 Subject: [PATCH 06/26] (EXPERIMENTAL) Reverted back to using t_ prefix for variables of print_test_array --- tests/batspp_report.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/batspp_report.py b/tests/batspp_report.py index e404d263..e69c24fe 100755 --- a/tests/batspp_report.py +++ b/tests/batspp_report.py @@ -565,15 +565,15 @@ def run_batspp(input_file, output_file): def print_test_array(arr): """Print summary of test results in ARR""" for index, item in enumerate(arr): - test_name = item['test_name'] - rate = item['test_success_rate'] - min_score = item['test_min_score'] - count_total = item['test_count_total'] - count_ok = item['test_count_ok'] - count_eval_error = item['test_count_eval_error'] + t_name = item['test_name'] + t_rate = item['test_success_rate'] + t_min_score = item['test_min_score'] + t_count_total = item['test_count_total'] + t_count_ok = item['test_count_ok'] + t_count_eval_error = item['test_count_eval_error'] ## OLD: Revised format includes test passed out of test found # print(f"{index + 1}. {name} ({rate}%): threshold={min_score}%") - print(f"{index+1}. {test_name} ({rate}%; {count_ok}/{count_total} OK): threshold={min_score}%; {count_eval_error} evaluation errors") + print(f"{index+1}. {t_name} ({t_rate}%; {t_count_ok}/{t_count_total} OK): threshold={min_score}%; {t_count_eval_error} evaluation errors") if not arr: print("n/a") From 1d92e658342075cf9ebed05cf65a5262ea907b23 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sat, 10 Feb 2024 21:26:34 +0545 Subject: [PATCH 07/26] Added "move to trash dir if PWD in TMP" at the end of test --- tests/trace-python-commands.ipynb | 262 ++++++++++++++---------------- 1 file changed, 122 insertions(+), 140 deletions(-) diff --git a/tests/trace-python-commands.ipynb b/tests/trace-python-commands.ipynb index dfc541a7..1b916808 100644 --- a/tests/trace-python-commands.ipynb +++ b/tests/trace-python-commands.ipynb @@ -34,8 +34,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "aveey\n", - "aveey adm sudo lpadmin docker\n" + "zavee\n", + "zavee\n" ] } ], @@ -72,17 +72,7 @@ "execution_count": 5, "id": "76e3d870-b4e7-457e-af7b-bcd0beb5f74c", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "*** Error: should not be run as operator unless FORCE_RUN ***\n", - "exit\n", - "Restarting Bash\n" - ] - } - ], + "outputs": [], "source": [ "# Abort if user in admin-like group unless FORCE_RUN env var set\n", "# note: The bash kernel restarts, so this \n", @@ -150,7 +140,15 @@ "execution_count": 9, "id": "0ff8f157", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/home/zavee/temp/tmp\n" + ] + } + ], "source": [ "## OLD\n", "## ## NOTE: Source it directly from the ./tests directory.\n", @@ -159,7 +157,8 @@ "## BIN_DIR=$PWD/..\n", "## ## You will need to run jupyter from that directory.\n", "## ## source $TEMP_BIN/_dir-aliases.bash\n", - "## alias | wc -l" + "## alias | wc -l\n", + "echo \"$TMP\"" ] }, { @@ -169,55 +168,21 @@ "metadata": {}, "outputs": [], "source": [ - "BIN_DIR=$PWD/..\n", - "TMP=/tmp/trace-python-commands\n", + "# Global Setup\n", + "\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", + " TMP=/tmp/trace-python-commands\n", + "fi\n", "temp_dir=$TMP/test-7766\n", "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "command mkdir -p \"$temp_dir\"\n", "command mkdir -p \"$trash_dir\"\n", - "command cd " + "command cd \"$temp_dir\"" ] }, { "cell_type": "code", "execution_count": 11, - "id": "ab954c7f", - "metadata": {}, - "outputs": [], - "source": [ - "# Global Setup\n", - "\n", - "## NOTE: For reproducability, the directory name needs to be fixed\n", - "## In place of $$, use a psuedo random number (e,g., 7766)\n", - "## *** All output from one run to the next needs to be the same ***\n", - "\n", - "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", - " TMP=/tmp/trace-python-commands; \n", - " # note: a little redundancy is to avoid a lot of catastrophe!\n", - " # BAD: /bin/rm -rf /tmp/trace-python-commands/*;\n", - " # command mv -f $TMP \"$trash_dir\"\n", - "fi\n", - "\n", - "## temp_dir=$TMP/test-$$\n", - "# temp_dir=$TMP/test-7766\n", - "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "\n", - "\n", - "## BAD: # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "## NOTE: do not use rm without explicit base to avoid inadvertent deletions!\n", - "## ALSO: in addition, tests can be reworked so that deletion not needed (e.g., using distinct subdir)\n", - "\n", - "## OLD: cd \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", - "# pwd\n", - "\n", - "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" - ] - }, - { - "cell_type": "code", - "execution_count": 12, "id": "bb14e4df", "metadata": {}, "outputs": [], @@ -233,17 +198,7 @@ }, { "cell_type": "code", - "execution_count": 13, - "id": "a918c4f3", - "metadata": {}, - "outputs": [], - "source": [ - "## BAD: source $BIN_DIR/tomohara-aliases.bash" - ] - }, - { - "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "id": "0359b346", "metadata": {}, "outputs": [ @@ -265,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "id": "e7d436e5", "metadata": {}, "outputs": [ @@ -286,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "id": "6c5b8d28", "metadata": {}, "outputs": [ @@ -295,10 +250,7 @@ "output_type": "stream", "text": [ "PYTHONPATH:\n", - "/home/userxf333/python\n", - "/home/userxf333/python\n", - "/home/userxf333/python\n", - "\n" + "/home/userxf333/tomProject/shell-scripts/\n" ] } ], @@ -309,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "id": "ff01fc98", "metadata": {}, "outputs": [ @@ -325,7 +277,7 @@ "/usr/lib/pythonN.NN/os.py:NN:N: WNNNN: Wildcard import nt (wildcard-import)\n", "/usr/lib/pythonN.NN/os.py:NN:N: ENNNN: Unable to import 'nt' (import-error)\n", "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining built-in 'str' (redefined-builtin)\n", - "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n", + "/usr/lib/pythonN.NN/os.py:NNN:NN: ENNNN: Using variable 'stat' before assignment (used-before-assignment)\n", "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n" ] } @@ -338,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "id": "5039b234", "metadata": { "scrolled": true @@ -349,6 +301,7 @@ "output_type": "stream", "text": [ "************* Module os\n", + "/usr/lib/pythonN.NN/os.py:NNN:N: CNNNN: Unnecessary parens after '=' keyword (superfluous-parens)\n", "/usr/lib/pythonN.NN/os.py:NN:N: WNNNN: Redefining built-in 'open' (redefined-builtin)\n", "/usr/lib/pythonN.NN/os.py:NN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n", "/usr/lib/pythonN.NN/os.py:NN:N: WNNNN: Wildcard import posix (wildcard-import)\n", @@ -356,8 +309,7 @@ "/usr/lib/pythonN.NN/os.py:NN:N: WNNNN: Wildcard import nt (wildcard-import)\n", "/usr/lib/pythonN.NN/os.py:NN:N: ENNNN: Unable to import 'nt' (import-error)\n", "/usr/lib/pythonN.NN/os.py:NN:N: CNNNN: Import \"from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull\" should be placed at the top of the module (wrong-import-position)\n", - "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining built-in 'str' (redefined-builtin)\n", - "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n" + "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining built-in 'str' (redefined-builtin)\n" ] } ], @@ -370,7 +322,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "id": "cab9db0c", "metadata": {}, "outputs": [ @@ -386,7 +338,7 @@ "/usr/lib/pythonN.NN/os.py:NN:N: WNNNN: Wildcard import nt (wildcard-import)\n", "/usr/lib/pythonN.NN/os.py:NN:N: ENNNN: Unable to import 'nt' (import-error)\n", "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining built-in 'str' (redefined-builtin)\n", - "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n", + "/usr/lib/pythonN.NN/os.py:NNN:NN: ENNNN: Using variable 'stat' before assignment (used-before-assignment)\n", "/usr/lib/pythonN.NN/os.py:NNN:NN: WNNNN: Redefining name 'name' from outer scope (line NN) (redefined-outer-name)\n" ] } @@ -399,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 18, "id": "207d98f0", "metadata": {}, "outputs": [], @@ -411,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 19, "id": "6e4b2871", "metadata": {}, "outputs": [], @@ -427,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "id": "1a220eac", "metadata": {}, "outputs": [ @@ -435,20 +387,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", "------------------------------------------------------------------------------------------------------------------------------------\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/debug.py\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/glue_helpers.py\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/system.py\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/tpo_common.py\n", - "matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/my_regex.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/debug.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/glue_helpers.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/system.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/tpo_common.py\n", + "matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/my_regex.py\n", "------------------------------------------------------------------------------------------------------------------------------------\n", - "# /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/__init__.cpython-NNN.pyc matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", - "# code object from '/home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/__init__.cpython-NNN.pyc'\n", - "# /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc matches /home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/debug.py\n", - "# code object from '/home/aveey/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc'\n", - "import 'mezcla.debug' # <_frozen_importlib_external.SourceFileLoader object at NxNeNaNNaNdNaN>\n" + "# /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/__init__.cpython-NNN.pyc matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__init__.py\n", + "# code object from '/home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/__init__.cpython-NNN.pyc'\n", + "# /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc matches /home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/debug.py\n", + "# code object from '/home/zavee/.local/lib/pythonN.NN/site-packages/mezcla/__pycache__/debug.cpython-NNN.pyc'\n", + "import 'mezcla.debug' # <_frozen_importlib_external.SourceFileLoader object at NxNefNNNbNbebN>\n" ] } ], @@ -466,7 +418,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "id": "852d5ab4", "metadata": {}, "outputs": [ @@ -486,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "id": "e82509c6", "metadata": {}, "outputs": [ @@ -495,10 +447,14 @@ "output_type": "stream", "text": [ "N.N.N.N\n", + "0.03user 0.01system 0:00.05elapsed 98%CPU (0avgtext+0avgdata 17236maxresident)k\n", + "0inputs+8outputs (0major+2890minor)pagefaults 0swaps\n", "------------------------------------------------------------------------------------------------------------------------------------\n", "N.N.N.N\n", "------------------------------------------------------------------------------------------------------------------------------------\n", "['PYTHONN_PLUS', 'TL', '__VERSION__', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'debug', 'gh', 'glue_helpers', 'my_re', 'my_regex', 'sys', 'system', 'tpo_common', 'version']\n", + "0.04user 0.00system 0:00.05elapsed 98%CPU (0avgtext+0avgdata 16972maxresident)k\n", + "0inputs+8outputs (0major+2881minor)pagefaults 0swaps\n", "------------------------------------------------------------------------------------------------------------------------------------\n" ] } @@ -515,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "id": "caf8bfd0", "metadata": {}, "outputs": [], @@ -573,7 +529,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 24, "id": "1912bb79-d984-4788-84d6-3759caf3383d", "metadata": {}, "outputs": [ @@ -591,7 +547,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 25, "id": "30fc8ae2-fb50-4f19-908e-1178ef19776e", "metadata": { "scrolled": true @@ -613,7 +569,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 26, "id": "d98b6d58", "metadata": {}, "outputs": [ @@ -639,7 +595,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 27, "id": "93146b8d", "metadata": {}, "outputs": [ @@ -665,7 +621,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 28, "id": "9dcb601f", "metadata": {}, "outputs": [ @@ -691,7 +647,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "id": "8080d06d", "metadata": {}, "outputs": [ @@ -717,7 +673,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "id": "b8c1c892", "metadata": { "scrolled": true @@ -745,7 +701,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 31, "id": "7d6ffb96", "metadata": {}, "outputs": [ @@ -753,12 +709,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "N.NN.N\n", - "------------------------------------------------------------------------------------------------------------------------------------\n", - "Cannot run file '' because: [Errno N] No such file or directory: ''\n", - "Command exited with non-zero status N\n", - "N.NNuser N.NNsystem N:NN.NNelapsed NN%CPU (Navgtext+Navgdata NNNNNmaxresident)k\n", - "Ninputs+Noutputs (Nmajor+NNNNminor)pagefaults Nswaps\n" + "N.NN.N\n" ] } ], @@ -768,16 +719,15 @@ "## OLD: ipython --version | testuser | testnum\n", "## NOTE: garbage due to xterm title escapes\n", "command ipython --version | testuser | testnum\n", - "linebr\n", "# STATEMENT TRACING WORKS WELL / ISSUES WITH TESTUSER\n", "## BAD: python-trace l $BIN_DIR/tests/auto_batspp.py | testuser | testnum\n", "## NOTE: use head to speed up\n", - "python-trace python-trace $BIN_DIR//simple_batspp.py --help 2>&1 | head | testnum\n" + "# BAD: python-trace python-trace $BIN_DIR//simple_batspp.py --help 2>&1 | head | testnum\n" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 32, "id": "c0b6f931", "metadata": {}, "outputs": [ @@ -800,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 33, "id": "273938b4", "metadata": {}, "outputs": [ @@ -855,7 +805,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 34, "id": "9a40ffff", "metadata": {}, "outputs": [], @@ -871,7 +821,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 35, "id": "b6e7b1d1", "metadata": {}, "outputs": [], @@ -884,7 +834,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 36, "id": "5dbc85eb", "metadata": {}, "outputs": [], @@ -915,7 +865,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 37, "id": "9322aa5a", "metadata": {}, "outputs": [], @@ -942,7 +892,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 38, "id": "caa3332b", "metadata": {}, "outputs": [], @@ -964,7 +914,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 39, "id": "9c155aa3", "metadata": {}, "outputs": [], @@ -982,7 +932,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 40, "id": "53136103", "metadata": {}, "outputs": [], @@ -997,7 +947,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 41, "id": "31d1b151", "metadata": {}, "outputs": [], @@ -1009,7 +959,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 42, "id": "3b6aab89", "metadata": {}, "outputs": [], @@ -1025,7 +975,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 43, "id": "88b697b0-82c6-48c2-8b0d-96d922b177b6", "metadata": {}, "outputs": [], @@ -1038,7 +988,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 44, "id": "c3845ce6-bf26-423c-81f3-356acca66f8d", "metadata": {}, "outputs": [ @@ -1072,7 +1022,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 45, "id": "833520df-e503-4131-bbdd-98bd990a9d2f", "metadata": {}, "outputs": [ @@ -1080,6 +1030,8 @@ "name": "stdout", "output_type": "stream", "text": [ + "0.06user 0.02system 0:00.08elapsed 101%CPU (0avgtext+0avgdata 17476maxresident)k\n", + "0inputs+24outputs (0major+3403minor)pagefaults 0swaps\n", "1\n", "2\n", "6\n", @@ -1100,7 +1052,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 46, "id": "4f226d82-2376-4caf-9b40-49a742a06980", "metadata": {}, "outputs": [ @@ -1120,7 +1072,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 47, "id": "4db32912-ca91-4791-b4d6-658674ad8403", "metadata": {}, "outputs": [ @@ -1146,7 +1098,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 48, "id": "89a01a21", "metadata": {}, "outputs": [ @@ -1156,7 +1108,7 @@ "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", - "100 1256 100 1256 0 0 672 0 0:00:01 0:00:01 --:--:-- 672\n", + "100 1256 100 1256 0 0 870 0 0:00:01 0:00:01 --:--:-- 869\n", "------------------------------------------------------------------------------------------------------------------------------------\n", "total NN \n", "-rw-rw-r-- N userxf333 userxf333 NN NN NN:NN abcN.py\n", @@ -1168,8 +1120,7 @@ "-rw-rw-r-- N userxf333 userxf333 NN NN NN:NN testless.txt\n", "-rw-rw-r-- N userxf333 userxf333 NNNN NN NN:NN www.example.com\n", "-rw-rw-r-- N userxf333 userxf333 NN NN NN:NN xyz.py\n", - "------------------------------------------------------------------------------------------------------------------------------------\n", - "file:////home/userxf333/tomProject/shell-scripts/tests/auto_batspp.py\n" + "------------------------------------------------------------------------------------------------------------------------------------\n" ] } ], @@ -1179,12 +1130,12 @@ "linebr\n", "ls -l | testnum | testuser | awk '!($6=\"\")'\n", "linebr\n", - "url-path $BIN_DIR/tests/auto_batspp.py | testuser" + "# url-path $BIN_DIR/tests/auto_batspp.py | testuser" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 49, "id": "3777aa4a", "metadata": {}, "outputs": [], @@ -1195,7 +1146,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 50, "id": "292f5558", "metadata": {}, "outputs": [ @@ -1213,7 +1164,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 51, "id": "c57545c5", "metadata": {}, "outputs": [], @@ -1228,12 +1179,43 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 52, + "id": "008e51b7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "[[ \"$PWD\" = *\"/tmp/\"* ]]; echo $?" + ] + }, + { + "cell_type": "code", + "execution_count": 53, "id": "a3d18560", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successfully moved to trash\n" + ] + } + ], "source": [ - "command mv -f * \"$trash_dir\"" + "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + " command mv -f * \"$trash_dir\"\n", + " echo \"Successfully moved to trash\"\n", + "else\n", + " echo \"Warning: Current directory not in TMP\"\n", + "fi" ] } ], From 8205668ecc26260ccda38da91cdd9f40dcd08525 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sat, 10 Feb 2024 21:45:46 +0545 Subject: [PATCH 08/26] Refined Global setup; Added conditional-trash at end; Commented copy-readonly commands (copy-readonly.sh not exist) --- tests/command-override-cp-mv.ipynb | 205 +++++++++++++++-------------- 1 file changed, 106 insertions(+), 99 deletions(-) diff --git a/tests/command-override-cp-mv.ipynb b/tests/command-override-cp-mv.ipynb index 802f3465..50f6d9d3 100644 --- a/tests/command-override-cp-mv.ipynb +++ b/tests/command-override-cp-mv.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_LVTIODRVTGVY\\[\\]>\n" + "0\n" ] } ], @@ -33,8 +33,13 @@ "## TEST: Make sure simple prompt used (e.g., no escapes that might contaminate output)\n", "## PS1=\"$ \"\n", "## TODO: PS1=\"> \"\n", - "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it. \n", - "echo $PS1" + "\n", + "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it.\n", + "# echo \"TODO:\"\n", + "# echo \" echo \\\"\\$PS1\\\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\"\n", + "\n", + "actual=${PS1: -1}\n", + "[ \"$actual\" = \">\" ]; echo $?" ] }, { @@ -42,68 +47,55 @@ "execution_count": 3, "id": "be8ef5b9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], "source": [ - "## BAD (SUPER )\n", - "# # Delete all aliases and function\n", - "# # TODO: Instead start from pristine environment\n", - "# unalias -a\n", + "## OLD: For debug\n", "# alias | wc -l\n", - "# for f in $(typeset -f | egrep '^\\w+'); do unset -f $f; done\n", - "# typeset -f | egrep '^\\w+' | wc -l" + "\n", + "# The debugging level should be at most 3\n", + "# Note: this affects output as bash_kernel conflates stderr w/ stdout\n", + "## TODO: echo \"DEBUG_LEVEL=$DEBUG_LEVEL\" 1>&2\n", + "[ \"$DEBUG_LEVEL\" -lt 4 ]; echo \"$?\"" ] }, { "cell_type": "code", "execution_count": 4, - "id": "8a0854c8", + "id": "1f0c6191", "metadata": {}, "outputs": [], "source": [ "# Global Setup\n", - "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", - "alias testnum=\"sed -r \"s/[0-9]/N/g\"\"\n", - "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" + "\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", + " TMP=/tmp/trace-python-commands\n", + "fi\n", + "temp_dir=$TMP/test-7766\n", + "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$trash_dir\"\n", + "command cd \"$temp_dir\"" ] }, { "cell_type": "code", "execution_count": 5, - "id": "8093ffd1", + "id": "8a0854c8", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "441\n" - ] - } - ], + "outputs": [], "source": [ - "## NOTE: For reproducability, the directory name needs to be fixed\n", - "## In place of $$, use a psuedo random number (e,g., 1210)\n", - "## *** All output from one run to the next needs to be the same ***\n", - "\n", - "TMP=/tmp/test-cp-mv\n", - "temp_dir=$TMP/test-1210\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd | testuser\n", - "\n", - "command mkdir -p \"$trash_dir\"\n", - "command mkdir -p \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", - "\n", - "alias | wc -l\n", - "\n", - "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "## OLD\n", - "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" + "# Global Setup\n", + "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", + "alias testnum=\"sed -r \"s/[0-9]/N/g\"\"\n", + "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, { @@ -116,13 +108,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "441\n" + "0\n" ] } ], "source": [ - "# Count aliases proper\n", - "alias | wc -l" + "## OLD\n", + "## Count aliases proper\n", + "# alias | wc -l\n", + "\n", + "# Count aliases w/ -dir in name\n", + "# Example:\n", + "# $ alias | egrep '\\-dir\\b' | wc -l\n", + "# 29\n", + "\n", + "dir_aliases=$(alias | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_aliases\" -gt 20 ]; echo \"$?\"" ] }, { @@ -135,13 +136,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "475\n" + "0\n" ] } ], "source": [ - "# Count functions\n", - "typeset -f | egrep '^\\w+' | wc -l" + "## OLD\n", + "## Count functions\n", + "# typeset -f | egrep '^\\w+' | wc -l\n", + "\n", + "dir_functions=$(typeset -f | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_functions\" -gt 35 ]; echo \"$?\"" ] }, { @@ -207,19 +212,10 @@ "execution_count": 11, "id": "01f003bf", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "renamed 'testdir1' -> '/tmp/test-cp-mv/_temp-trash-20240130214644/testdir1'\n" - ] - } - ], + "outputs": [], "source": [ "## WORK OF ALIASES\n", "## CREATES TEST SUBJECTS\n", - "mv -f * $trash_dir\n", "touch abc def ghi\n", "mkdir mvtest_dir1" ] @@ -569,18 +565,13 @@ "execution_count": 26, "id": "29b8b028", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "copy-readonly.sh: command not found\n" - ] - } - ], + "outputs": [], "source": [ - "# RUNNING FOR DETAILS\n", - "copy-readonly | testuser" + "## RUNNING FOR DETAILS\n", + "\n", + "## Error: copy-readonly.sh: command not found\n", + "\n", + "# copy-readonly | testuser" ] }, { @@ -591,8 +582,8 @@ "outputs": [], "source": [ "# BAD: rm -rf ./* > /dev/null\n", - "command mv -f * \"$trash_dir\"\n", - "mkdir testdir1" + "# command mv -f * \"$trash_dir\"\n", + "# mkdir testdir1" ] }, { @@ -600,17 +591,9 @@ "execution_count": 28, "id": "453d4af0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "copy-readonly.sh: command not found\n" - ] - } - ], + "outputs": [], "source": [ - "copy-readonly ~/.bashrc testdir1 | awk '!($6=\"\")' | testnum | testuser" + "# copy-readonly ~/.bashrc testdir1 | awk '!($6=\"\")' | testnum | testuser" ] }, { @@ -618,17 +601,9 @@ "execution_count": 29, "id": "167288de", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "cat: testdir1/.bashrc: No such file or directory\n" - ] - } - ], + "outputs": [], "source": [ - "cat testdir1/.bashrc | head -n 1" + "# cat testdir1/.bashrc | head -n 1" ] }, { @@ -653,14 +628,23 @@ "cell_type": "code", "execution_count": 31, "id": "d6cf3aca", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "total N \n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN testdirN\n" + "total NN \n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -668,6 +652,29 @@ "# AFTER fix-dir-permissions\n", "ls -l | awk '!($6=\"\")' | testnum | testuser" ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "5d4aef31", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successfully moved to trash\n" + ] + } + ], + "source": [ + "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + " command mv -f * \"$trash_dir\"\n", + " echo \"Successfully moved to trash\"\n", + "else\n", + " echo \"Warning: Current directory not in TMP\"\n", + "fi" + ] } ], "metadata": { From 304db8d5dff9f248b007a5b036ffa17dc9861bb7 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sat, 10 Feb 2024 22:01:06 +0545 Subject: [PATCH 09/26] Added newer test standards (trashdir, refined global setup); Commented do-make command (not found) --- tests/trace-unix-alias.ipynb | 504 ++++++++++++++++++++++++++--------- 1 file changed, 379 insertions(+), 125 deletions(-) diff --git a/tests/trace-unix-alias.ipynb b/tests/trace-unix-alias.ipynb index 2174cccd..70050329 100644 --- a/tests/trace-unix-alias.ipynb +++ b/tests/trace-unix-alias.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_QPSFEBRZHROH\\[\\]>\n" + "0\n" ] } ], @@ -34,8 +34,12 @@ "## PS1=\"$ \"\n", "## TODO: PS1=\"> \"\n", "\n", - "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it. \n", - "echo $PS1" + "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it.\n", + "# echo \"TODO:\"\n", + "# echo \" echo \\\"\\$PS1\\\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\"\n", + "\n", + "actual=${PS1: -1}\n", + "[ \"$actual\" = \">\" ]; echo $?" ] }, { @@ -43,14 +47,23 @@ "execution_count": 3, "id": "d623c9a9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], "source": [ - "## BAD (SUPER BAD)\n", - "\n", - "# unalias -a\n", + "## OLD: For debug\n", "# alias | wc -l\n", - "# for f in $(typeset -f | egrep '^\\w+'); do unset -f $f; done\n", - "# typeset -f | egrep '^\\w+' | wc -l" + "\n", + "# The debugging level should be at most 3\n", + "# Note: this affects output as bash_kernel conflates stderr w/ stdout\n", + "## TODO: echo \"DEBUG_LEVEL=$DEBUG_LEVEL\" 1>&2\n", + "[ \"$DEBUG_LEVEL\" -lt 4 ]; echo \"$?\"" ] }, { @@ -60,23 +73,16 @@ "metadata": {}, "outputs": [], "source": [ - "TMP=/tmp/test-unix-alias\n", - "BIN_DIR=$PWD/..\n", - "temp_dir=$TMP/test-2899\n", + "# Global Setup\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", + " TMP=/tmp/trace-unix-commands\n", + "fi\n", + "temp_dir=$TMP/test-7766\n", "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd\n", - "\n", "command mkdir -p \"$temp_dir\"\n", "command mkdir -p \"$trash_dir\"\n", - "command cd \"$temp_dir\"\n", - "\n", - "## OLD\n", - "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" + "command cd \"$temp_dir\"" ] }, { @@ -89,10 +95,8 @@ "# Global Setup\n", "\n", "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", - "## For number of digits not being critical\n", "alias testnum=\"sed -r \"s/[0-9][0-9]*/N/g\"\"\n", - "## OLD\n", - "# alias testnum=\"sed -r \"s/[0-9]/N/g\"\" " + "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, { @@ -105,13 +109,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "N\n" + "0\n" ] } ], "source": [ - "# Count aliases proper\n", - "alias | wc -l | testnum" + "## OLD\n", + "## Count aliases proper\n", + "# alias | wc -l\n", + "\n", + "# Count aliases w/ -dir in name\n", + "# Example:\n", + "# $ alias | egrep '\\-dir\\b' | wc -l\n", + "# 29\n", + "\n", + "dir_aliases=$(alias | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_aliases\" -gt 20 ]; echo \"$?\"" ] }, { @@ -124,13 +137,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "N\n" + "0\n" ] } ], "source": [ - "# Count functions\n", - "typeset -f | egrep '^\\w+' | wc -l | testnum" + "## OLD\n", + "## Count functions\n", + "# typeset -f | egrep '^\\w+' | wc -l\n", + "\n", + "dir_functions=$(typeset -f | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_functions\" -gt 35 ]; echo \"$?\"" ] }, { @@ -163,23 +180,7 @@ "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "mv: cannot stat '*': No such file or directory\n", - "do-make: command not found\n", - "cat: _make.log: No such file or directory\n" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], + "outputs": [], "source": [ "## 1A) do-make \n", "# BAD: rm -rf ./* > /dev/null\n", @@ -189,41 +190,58 @@ "echo \"Hi Mom!\" > himom.txt\n", "echo \"Hi Dad!\" > hidad.txt\n", "\n", - "do-make \"himom.txt\"\n", - "cat _make.log\n", - "# do-make \"hidad.txt\"\n", - "# cat _make.log\n", - "\n", - "# ls -l | awk '!($6=\"\")' | testuser | testnum" + "## $ do-make \"himom.txt\"\n", + "## $ cat _make.log\n", + "## | do-make: command not found\n", + "## | cat: _make.log: No such file or directory\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "0198effb", "metadata": {}, "outputs": [], "source": [ - "do-make \"hidad.txt\"\n", - "cat _make.log" + "# do-make \"hidad.txt\"\n", + "# cat _make.log" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "cb7f48dc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total N \n", + "-rw-rw-r-- N userxf333 userxf333 N N N:N hidad.txt\n", + "-rw-rw-r-- N userxf333 userxf333 N N N:N himom.txt\n", + "drwxrwxr-x N userxf333 userxf333 N N N:N testfolder\n" + ] + } + ], "source": [ "ls -l | awk '!($6=\"\")' | testnum | testuser" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "cd0c80db", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "do-merge MODFILE1 OLDFILE MODFILE2 > NEWFILE tf1.txt tf2.txt\n" + ] + } + ], "source": [ "# 2A) merge REPLACED BY do-merge \n", "\n", @@ -238,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "c0c74f75", "metadata": {}, "outputs": [], @@ -253,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "d6f37399", "metadata": {}, "outputs": [], @@ -269,7 +287,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "b535f2eb", "metadata": {}, "outputs": [], @@ -280,10 +298,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "761a2cd8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PY-TRUE\n" + ] + } + ], "source": [ "### TO FIX THE ERROR USE \"himom.txt\" --> himom.txt ###\n", "\n", @@ -300,27 +326,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "8f904a21", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/tmp/trace-unix-commands/test-7766/himom.txt\n" + ] + } + ], "source": [ "full-dirname himom.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "e38e8554", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./himom.txt\n" + ] + } + ], "source": [ "basename-with-dir himom.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "d792021b", "metadata": {}, "outputs": [], @@ -335,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "5cdac362", "metadata": {}, "outputs": [], @@ -346,10 +388,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "49da8c7e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Linux\n", + "Real: 0.00 seconds\n", + "User: 0.00 seconds\n", + "Sys: 0.00 seconds\n" + ] + } + ], "source": [ "## 4B) gtime (Need help to run commands)\n", "# ERROR - VI \n", @@ -366,10 +419,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "9bea16c5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "VERSION_ID=\"N.N\"\n" + ] + } + ], "source": [ "## 4C) linux-version GIVES INFO ALL INFO ABOUT THE OS INSTALLED\n", "linux-version | grep VERSION_ID | testnum\n", @@ -378,10 +439,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "e0e10406", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "system_status.sh: command not found\n" + ] + } + ], "source": [ "## 4D) system-status - (awk removes the session-name)\n", "system-status | testnum | testuser | tail -n +2 | awk '!($8=\"\")'" @@ -389,22 +458,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "28e700ce", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "N\n" + ] + } + ], "source": [ "apropos-command time | grep asctime | wc -l | testnum" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "e3e42a18", "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi Dad!\n" + ] + } + ], "source": [ "## How split-tokens work\n", "## OLD\n", @@ -415,20 +500,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "43c24ea0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi\n", + "Dad!\n" + ] + } + ], "source": [ "split-tokens hidad.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "73ea76b9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi\n", + "Dad!\n" + ] + } + ], "source": [ "# tokenize SPLITS THE CONTENTS IN SEVERAL LINES ()\n", "## OLD\n", @@ -438,10 +541,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "0ee7e74e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is Ubuntu!\n" + ] + } + ], "source": [ "# perl-echo ONLY PRINTS OUT THE 1ST ARGUMENT\n", "PERL_PRINT='This is Ubuntu!'\n", @@ -452,20 +563,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "212ef1c9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This\n" + ] + } + ], "source": [ "perl-echo-sans-newline $PERL_PRINT" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "id": "a5d6b066", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ONE KISS IS ALL IT TAKES\n" + ] + } + ], "source": [ "# Several print commands (perl-based)\n", "perl-printf 'ONE KISS IS ALL IT TAKES\\n'\n", @@ -476,40 +603,76 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "c32526fd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "5\n", + "7\n", + "11\n" + ] + } + ], "source": [ "perl-print '2\\n3\\n5\\n7\\n11'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "9ab09848", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A B C D E F G\n" + ] + } + ], "source": [ "perl-print-n 'A B C D E F G\\n'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "id": "efd7f828", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"HELP\" \"ME!\"\n" + ] + } + ], "source": [ "quote-tokens 'HELP ME!'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "b4502821", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "localhost:N.N\n" + ] + } + ], "source": [ "# # 6A)\n", "# # Unix/Win32 networking aliases\n", @@ -522,10 +685,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "2919fe8f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "start: Sat Feb N N:N:N PM +N N\n", + "+ eval ''\n", + "+ set - -o xtrace\n", + "end: Sat Feb N N:N:N PM +N N\n" + ] + } + ], "source": [ "## Need a filter to sensor day and month\n", "## bash-trace-on ENABLES bash tracing\n", @@ -541,10 +715,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "943f1eb0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "start: Sat Feb N N:N:N PM +N N\n", + "+ eval ''\n", + "+ set - -o xtrace\n", + "end: Sat Feb N N:N:N PM +N N\n" + ] + } + ], "source": [ "## bash-trace-on DISABLES bash tracing\n", "bash-trace-off | testuser | testnum\n", @@ -553,12 +738,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "ef8e82ea", "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hidad.txt himom.txt \u001b[0m\u001b[01;34mtestfolder\u001b[0m tf1.txt tf2.txt tf3.txt\n", + "'tf2.txt' -> 'testfolder/tf2.txt'\n" + ] + } + ], "source": [ "# testing compression and extraction of dirs\n", "ls\n", @@ -574,47 +768,79 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "fa9577fa", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NotZero\n" + ] + } + ], "source": [ "compress-this-dir ./testfolder | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo \"NotZero\" || echo \"Zero\"; }" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "id": "e3e61188", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hidad.txt.gz himom.txt.gz testfolder\ttf1.txt.gz tf2.txt.gz\ttf3.txt.gz\n" + ] + } + ], "source": [ "command ls" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "id": "2adacf28", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NotZero\n" + ] + } + ], "source": [ "ununcompress-this-dir ./testfolder | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo \"NotZero\" || echo \"Zero\"; }" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "id": "2646670b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hidad.txt himom.txt testfolder tf1.txt tf2.txt tf3.txt\n" + ] + } + ], "source": [ "command ls" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "caa6e9af", "metadata": { "scrolled": true @@ -632,10 +858,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "id": "34bd5b99", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".txt\tN\n" + ] + } + ], "source": [ "# count-exts counts extensions\n", "old-count-exts | testnum\n", @@ -646,17 +880,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "id": "ae4f0131", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".txt\tN\n" + ] + } + ], "source": [ "count-exts | testnum" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "id": "1b9bea43", "metadata": {}, "outputs": [], @@ -666,13 +908,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "id": "c87c3dce", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successfully moved to trash\n" + ] + } + ], "source": [ - "echo \"Done!\"\n", - "command mv -f * \"$trash_dir\"" + "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + " command mv -f * \"$trash_dir\"\n", + " echo \"Successfully moved to trash\"\n", + "else\n", + " echo \"Warning: Current directory not in TMP\"\n", + "fi" ] } ], From 0e5a9f283ec927043483c22b0ccae54f6a17a781 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sun, 11 Feb 2024 12:45:11 +0545 Subject: [PATCH 10/26] Added examples for conditional-echo --- tests/hello-world-basic.ipynb | 23 +++++++++++++---------- tests/hello-world-revised.ipynb | 32 +++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/tests/hello-world-basic.ipynb b/tests/hello-world-basic.ipynb index f5e509ba..2ccb132d 100644 --- a/tests/hello-world-basic.ipynb +++ b/tests/hello-world-basic.ipynb @@ -29,45 +29,48 @@ } ], "source": [ + "## This is how a simple command works\n", "echo 'BIND ON!'" ] }, { "cell_type": "code", "execution_count": 3, - "id": "10e4aac0", - "metadata": {}, + "id": "93dfcf88", + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Hi Mom!\n" + "1\n" ] } ], "source": [ - "echo 'Hi Mom!'" + "## Here's an example of pipeline\n", + "echo 'Hello world' | wc -l" ] }, { "cell_type": "code", "execution_count": 4, - "id": "93dfcf88", - "metadata": { - "scrolled": true - }, + "id": "adb5fa38", + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], "source": [ - "echo 'Hello world' | wc -l" + "## Tests using single line conditions and echo\n", + "[ \"$(echo 'Hi Mom!' | wc -c)\" -eq 8 ]; echo $? " ] } ], diff --git a/tests/hello-world-revised.ipynb b/tests/hello-world-revised.ipynb index 6765a174..96d5640e 100644 --- a/tests/hello-world-revised.ipynb +++ b/tests/hello-world-revised.ipynb @@ -173,11 +173,11 @@ "output_type": "stream", "text": [ " PID TTY TIME CMD\n", - " NNNNNN pts/N NN:NN:NN bash\n", - " NNNNNN pts/N NN:NN:NN ps\n", - " NNNNNN pts/N NN:NN:NN head\n", - " NNNNNN pts/N NN:NN:NN sed\n", - " NNNNNN pts/N NN:NN:NN sed\n" + " NNNNN pts/N NN:NN:NN bash\n", + " NNNNN pts/N NN:NN:NN ps\n", + " NNNNN pts/N NN:NN:NN head\n", + " NNNNN pts/N NN:NN:NN sed\n", + " NNNNN pts/N NN:NN:NN sed\n" ] } ], @@ -195,13 +195,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "NotZero\n" + "0\n" ] } ], "source": [ "## Zero or Non-Zero checking for wc -l reduces non-critical tests\n", - "ps | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo \"NotZero\" || echo \"Zero\"; }" + "ps | { [ $(wc -l < /dev/stdin) -ne 0 ] && echo $?; }" ] }, { @@ -223,6 +223,24 @@ "## Example: Check if there are python files (py) in testfolders\n", "ls | grep -q \"py\" && echo \".py files present\" || echo \"No .py files present\"" ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "ef05beae", + "metadata": {}, + "outputs": [ + { + "ename": "", + "evalue": "1", + "output_type": "error", + "traceback": [] + } + ], + "source": [ + "# Incase of a false condition, echo $? returns nothing\n", + "ls | grep -q \"pyx\" && echo $?" + ] } ], "metadata": { From 6e4237b9c5b497d0b52bc2d2d14ad9a2a497373e Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sun, 11 Feb 2024 12:48:35 +0545 Subject: [PATCH 11/26] Added conditional-echo and reworked on Global Setup --- tests/alias-grep-commands.ipynb | 163 +++++++++++++------------------- 1 file changed, 66 insertions(+), 97 deletions(-) diff --git a/tests/alias-grep-commands.ipynb b/tests/alias-grep-commands.ipynb index 822794f3..86d5ff01 100644 --- a/tests/alias-grep-commands.ipynb +++ b/tests/alias-grep-commands.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_XYBNYRKDCVHU\\[\\]>\n" + "0\n" ] } ], @@ -34,62 +34,37 @@ "## PS1=\"$ \"\n", "## TODO: PS1=\"> \"\n", "\n", - "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it. \n", - "echo $PS1" + "## NOTE: The Jupyter bash kernel requires that PS1 not be modified as they customize it.\n", + "# echo \"TODO:\"\n", + "# echo \" echo \\\"\\$PS1\\\" | command grep --count --perl-regexp '[\\x00-\\x1f]'\"\n", + "\n", + "actual=${PS1: -1}\n", + "[ \"$actual\" = \">\" ]; echo $?" ] }, { "cell_type": "code", "execution_count": 3, - "id": "71d47f5f", - "metadata": {}, - "outputs": [], - "source": [ - "## BAD (SUPER BAD)\n", - "# # Delete all aliases and function\n", - "# # TODO: Instead start from pristine environment\n", - "# unalias -a\n", - "# alias | wc -l\n", - "# for f in $(typeset -f | egrep '^\\w+'); do unset -f $f; done\n", - "# typeset -f | egrep '^\\w+' | wc -l" - ] - }, - { - "cell_type": "code", - "execution_count": 4, "id": "118f4d68", "metadata": {}, - "outputs": [], - "source": [ - "# Global Setup\n", - "\n", - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-grep" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "acd1700d", - "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "439\n" + "0\n" ] } ], "source": [ - "## You will need to run jupyter from that directory.\n", - "alias | wc -l" + "# Setting a temp directory for tests\n", + "[ \"$DEBUG_LEVEL\" -lt 4 ]; echo \"$?\"" ] }, { "cell_type": "code", - "execution_count": 6, - "id": "ab6448b5", + "execution_count": 4, + "id": "58f47ac9", "metadata": {}, "outputs": [], "source": [ @@ -103,57 +78,56 @@ }, { "cell_type": "code", - "execution_count": 7, - "id": "2f7150b0", + "execution_count": 5, + "id": "482c3dcb", "metadata": {}, "outputs": [], "source": [ - "# Global Setup\n", + "# Global setup\n", "\n", - "## NOTE: For reproducability, the directory name needs to be fixed\n", - "## In place of $$, use a psuedo random number (e,g., 7071)\n", - "## *** All output from one run to the next needs to be the same ***\n", + "## Setting a temp directory for tests\n", + "## NOTE: If debugging uses $TMP\n", + "## Use of rm command is heavily discouraged, use move to $trash_dir instead\n", + "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-grep-commands; fi\n", "\n", - "## temp_dir=$TMP/test-$$\n", "temp_dir=$TMP/test-7371\n", "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", "command mkdir -p $temp_dir\n", "command mkdir -p $trash_dir\n", - "command cd $temp_dir\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd\n", - "\n", - "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "## OLD\n", - "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" + "command cd $temp_dir" ] }, { "cell_type": "code", - "execution_count": 8, - "id": "868c96db", + "execution_count": 6, + "id": "ab6448b5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "442\n" + "0\n" ] } ], "source": [ - "# Count aliases proper\n", - "alias | wc -l" + "## Count aliases w/ -dir in name\n", + "\n", + "## Example:\n", + "## $ alias | egrep '\\-dir\\b' | wc -l\n", + "## 29\n", + "\n", + "dir_aliases=$(alias | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_aliases\" -gt 20 ]; echo \"$?\"" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "id": "4eb0b066", "metadata": {}, "outputs": [ @@ -161,18 +135,24 @@ "name": "stdout", "output_type": "stream", "text": [ - "474\n" + "0\n" ] } ], "source": [ - "# Count functions\n", - "typeset -f | egrep '^\\w+' | wc -l" + "## Count functions w/ -dir in name\n", + "\n", + "## Example:\n", + "## $ typeset -f | egrep '^\\w+' | wc -l\n", + "## | 474\n", + "\n", + "dir_functions=$(typeset -f | egrep '\\-dir\\b' | wc -l)\n", + "[ \"$dir_functions\" -gt 35 ]; echo \"$?\"" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "993a90d3", "metadata": {}, "outputs": [], @@ -183,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "37c6221e", "metadata": {}, "outputs": [ @@ -191,29 +171,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "grep (GNU grep) N.N\n", - "Copyright (C) NNNN Free Software Foundation, Inc.\n" + "grep (GNU grep) 3.7\n" ] } ], "source": [ - "# TEST-1\n", - "# check for a modern version of grep. For example,\n", - "#\n", - "# $ grep -V\n", - "# grep (GNU grep) 2.4.2\n", - "#\n", - "# Copyright 1988, 1992-1999, 2000 Free Software Foundation, Inc.\n", - "# ...\n", - "\n", - "## OLD\n", - "# grep -V | testnum\n", - "grep -V | head -n 2 | testnum" + "grep_ver=$(grep -V | head -n 1 | tail )\n", + "echo $grep_ver" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "id": "135998e6", "metadata": {}, "outputs": [], @@ -236,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "id": "f906642e", "metadata": {}, "outputs": [ @@ -271,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "id": "b209fa0d", "metadata": {}, "outputs": [ @@ -292,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "id": "66375e3e", "metadata": {}, "outputs": [ @@ -313,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "id": "4a61dbfa", "metadata": {}, "outputs": [ @@ -332,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "id": "690311c9", "metadata": {}, "outputs": [], @@ -343,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "id": "c1709353", "metadata": { "scrolled": true @@ -364,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "id": "4221570d", "metadata": {}, "outputs": [ @@ -383,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 18, "id": "76128375", "metadata": {}, "outputs": [], @@ -393,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 19, "id": "e51dcd01", "metadata": {}, "outputs": [ @@ -401,10 +370,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-alR.list.log\n", - "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-aR.list.log\n" + "-rw-rw-r-- N userxfNNN userxfNNN N N NN:NN ./ls-alR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN N NN:NN ./ls-alR.list.log\n", + "-rw-rw-r-- N userxfNNN userxfNNN N N NN:NN ./ls-aR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN N NN:NN ./ls-aR.list.log\n" ] } ], @@ -414,7 +383,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "id": "584ac3a6", "metadata": {}, "outputs": [ @@ -434,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "id": "4da38cda", "metadata": {}, "outputs": [], @@ -444,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "id": "f7c048b8", "metadata": {}, "outputs": [], @@ -455,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "id": "1572700d", "metadata": {}, "outputs": [], From 554d4aa007fab47a145f4bfa9f634697cdc0375b Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 14 Feb 2024 14:21:54 +0545 Subject: [PATCH 12/26] Added conditional-echo for cell 8 --- tests/testing-support-script-tests.ipynb | 44 ++++++++---------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/tests/testing-support-script-tests.ipynb b/tests/testing-support-script-tests.ipynb index 803db389..ee817ae9 100644 --- a/tests/testing-support-script-tests.ipynb +++ b/tests/testing-support-script-tests.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 11, + "execution_count": 1, "id": "7cb29952-f87f-4874-bb8e-9416fcdf3827", "metadata": {}, "outputs": [], @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 2, "id": "c071734b-2447-4d61-883a-cfe6b0a3001e", "metadata": {}, "outputs": [], @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "286f9780-c223-4eab-b57a-f593efe59d3b", "metadata": {}, "outputs": [], @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "ddfd9f55-9a4d-49be-8de7-cced0d1bf3fc", "metadata": {}, "outputs": [], @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 5, "id": "477cf63b-2675-4e54-ba4c-4a6e91be5f14", "metadata": {}, "outputs": [ @@ -54,7 +54,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1 tests, 0 \u001b[01;31m\u001b[Kfailure\u001b[m\u001b[K(s)\n" + "2 tests, 1 \u001b[01;31m\u001b[Kfailure\u001b[m\u001b[K(s)\n" ] } ], @@ -65,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 6, "id": "9911adb1-b9f6-44a4-a820-0afdaea2cc52", "metadata": {}, "outputs": [ @@ -73,7 +73,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "1\n" ] } ], @@ -84,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 7, "id": "e96fd637-4ca4-4f8f-a939-8e91d0135596", "metadata": {}, "outputs": [], @@ -95,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 8, "id": "a32d21fc-11e0-4204-9b59-f891f397ba27", "metadata": {}, "outputs": [], @@ -107,7 +107,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "id": "a8d93dcb-c2ad-4fcd-9fad-9ec2633dadc0", "metadata": {}, "outputs": [ @@ -115,32 +115,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "# That itself is dangerous, so the filenames start and end with _ to minimize conflict.\n", - "# For example, \"file.txt\" => \"_file.txt_\").\n", - "\n", - "# Create test file with letters\n", - "$ echo \"a b c D E F\" >| _abcDEF_.txt_\n", - "$ cat _abcDEF_.txt_\n", - "a b c D E F\n", - "\n", - "# Make sure 3 lowercase chars\n", - "# note: count-it is alias tabulating regex pattern occurrences\n", - "$ num_lower=$(count-it \"[a-z]\" _abcDEF_.txt_ | wc -l)\n", - "$ [ $num_lower -eq 3 ]; echo $?\n", - "0\n", - "\n", - "\n" + "0\n" ] } ], "source": [ "# Show sample\n", - "tail --lines=15 $log" + "[ \"$(tail --lines=15 $log | wc -l)\" -eq 15 ]; echo $? " ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 10, "id": "6c110d76-9927-4bb9-8c6c-ed7ba76db9a1", "metadata": {}, "outputs": [ @@ -159,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 11, "id": "e2289fa3-4545-45a6-aa02-f8a1ac7864f6", "metadata": {}, "outputs": [ From 504f35b0a034ef8e80fdfb9305cd5cd97820afa1 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 14 Feb 2024 20:56:44 +0545 Subject: [PATCH 13/26] Added conditional echo for asctime, commaize, numeric suffixes; Removed mv to trash_dir on cell34 --- tests/alias-trace-misc-commands.ipynb | 353 +++++++++++--------------- 1 file changed, 143 insertions(+), 210 deletions(-) diff --git a/tests/alias-trace-misc-commands.ipynb b/tests/alias-trace-misc-commands.ipynb index 0c94c1c3..80c7aa11 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -50,18 +50,13 @@ "metadata": {}, "outputs": [], "source": [ - "# Global setup\n", - "# Setting a temp directory for tests\n", - "# TODO2: Use $TMP if debugging\n", - "TMP=/tmp/test-trace-misc\n", - "\n", - "## OLD\n", - "## ## NOTE: Source it directly from the ./tests directory.\n", - "## BIN_DIR=$PWD/..\n", + "# Global Setup\n", "\n", - "## OLD\n", - "## ## You will need to run jupyter from that directory.\n", - "## alias | wc -l" + "## Aliases for censoring username and/or numbers\n", + "alias testnum=\"sed -r \"s/[0-9]/N/g\"\"\n", + "alias testnumhex=\"sed -r \"s/[0-9][A-F][a-F]/N/g\"\"\n", + "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", + "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, { @@ -69,18 +64,31 @@ "execution_count": 5, "id": "ce58f3f6-2f78-4bff-a96a-23e4f1983d94", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-trace-misc/test-1001' -> '/tmp/test-trace-misc/test-1001.14Feb24.17'\n" + ] + } + ], "source": [ "# Global setup\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 1210)\n", "## *** All output from one run to the next needs to be the same ***\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-1210\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-misc; fi\n", + "\n", + "temp_dir=$TMP/test-1001\n", + "rename-with-file-date \"$temp_dir\"\n", + "\n", + "mkdir -p $temp_dir\n", "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "##\n", - "mkdir -p \"$temp_dir\"\n", - "mkdir -p \"$trash_dir\"" + "command mkdir -p $trash_dir\n", + "command cd $temp_dir" ] }, { @@ -97,45 +105,6 @@ { "cell_type": "code", "execution_count": 7, - "id": "21b33380-da9a-4fbd-ba94-a7b6c2754cb5", - "metadata": {}, - "outputs": [], - "source": [ - "# Global setup\n", - "#\n", - "## OLD: \n", - "## # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "## ## cd \"$temp_dir\"\n", - "## command cd \"$temp_dir\"\n", - "## ## OLD: pwd\n", - "## command pwd\n", - "#\n", - "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "d0153e76-a5aa-4792-b0bc-81a1c0aed50e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/tmp/test-trace-misc/test-1210\n" - ] - } - ], - "source": [ - "command cd \"$temp_dir\"\n", - "command pwd" - ] - }, - { - "cell_type": "code", - "execution_count": 9, "id": "66e35e72-5233-4294-8762-3c65d4ba4e13", "metadata": {}, "outputs": [], @@ -149,20 +118,7 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "fa868993", - "metadata": {}, - "outputs": [], - "source": [ - "# Global Setup\n", - "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", - "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" \n", - "alias testnumhex=\"sed -r \"s/[0-9,a-f,A-F]/h/g\"\" " - ] - }, - { - "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "a0f513ae", "metadata": {}, "outputs": [], @@ -172,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "id": "e149fbc9", "metadata": {}, "outputs": [], @@ -189,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "id": "ed1a5eb4", "metadata": {}, "outputs": [ @@ -197,7 +153,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "DDD MMM N N:N:N N\n" + "0\n" ] } ], @@ -205,12 +161,14 @@ "##3 ASCTIME\n", "## BAD: function asctime() { perl -e 'print (scalar localtime($1));'; echo ''; }\n", "## BAD: asctime | perl -pe 's/\\d/N/g; s/\\w+ \\w+/DDD MMM/;'\n", - "asctime | perl -pe 's/\\d+/N/g; s/\\w+ \\w+/DDD MMM/;'" + "\n", + "# asctime | perl -pe 's/\\d+/N/g; s/\\w+ \\w+/DDD MMM/;'\n", + "[ \"$(asctime | perl -pe 's/\\d+/N/g; s/\\w+ \\w+/DDD MMM/;')\" = \"DDD MMM N N:N:N N\" ]; echo $?\n" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "f7c6a03a", "metadata": {}, "outputs": [ @@ -219,11 +177,11 @@ "output_type": "stream", "text": [ " PID TTY TIME CMD\n", - " NNNNNN pts/N NN:NN:NN bash\n", - " NNNNNN pts/N NN:NN:NN ps\n", - " NNNNNN pts/N NN:NN:NN bash\n", - " NNNNNN pts/N NN:NN:NN sed\n", - " NNNNNN pts/N NN:NN:NN perl\n" + " NNNNN pts/N NN:NN:NN bash\n", + " NNNNN pts/N NN:NN:NN ps\n", + " NNNNN pts/N NN:NN:NN bash\n", + " NNNNN pts/N NN:NN:NN sed\n", + " NNNNN pts/N NN:NN:NN perl\n" ] } ], @@ -237,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "0a69f15f", "metadata": {}, "outputs": [ @@ -245,18 +203,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "99,012,342,305,324,254\n" + "0\n" ] } ], "source": [ "##5 COMMAIZE NUMBERS\n", - "echo '99012342305324254' | comma-ize-number" + "[ \"$(echo '99012342305324254' | comma-ize-number)\" = \"99,012,342,305,324,254\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "fd7d2c34", "metadata": {}, "outputs": [ @@ -264,18 +222,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "7.45G\n" + "0\n" ] } ], "source": [ "##6 APPLYING NUMERIC SUFFIXES\n", - "echo \"8000000000\" | apply-numeric-suffixes" + "[ \"$(echo \"8000000000\" | apply-numeric-suffixes)\" = \"7.45G\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "d6e23378", "metadata": {}, "outputs": [ @@ -283,20 +241,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "7.45T\n", - "7.63G\n" + "0\n" ] } ], "source": [ "##6.1 APPLYING USAGE NUMERIC SUFFIXES\n", - "echo \"8000000000\" | apply-usage-numeric-suffixes\n", - "echo \"8000000\" | apply-usage-numeric-suffixes " + "[ \"$(echo \"8000000000\" | apply-usage-numeric-suffixes)\" = \"7.45T\" ]; echo $?\n", + "\n", + "# echo \"8000000\" | apply-usage-numeric-suffixes returns 7.63G" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "28d9cce7", "metadata": {}, "outputs": [ @@ -304,14 +262,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Backing up 'usage.bytes.list' to './backup/usage.bytes.list'\n", - "NN.NM\t.\n", - "N.NNM\t./backup\n", - "N.NNM\t./info\n", - "renamed 'usage.list' -> 'usage.list.NNAugNN.NN'\n", - "NNNK\t.\n", - "NNK\t./backup\n", - "NK\t./info\n" + "NM\t.\n", + "NK\t.\n" ] } ], @@ -341,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "id": "95bda88c", "metadata": {}, "outputs": [ @@ -349,9 +301,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "204K\t.\n", - "16K\t./backup\n", - "8K\t./info\n" + "12K\t.\n" ] } ], @@ -371,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "id": "db031306", "metadata": {}, "outputs": [ @@ -379,9 +329,6 @@ "name": "stdout", "output_type": "stream", "text": [ - "mkdir: cannot create directory ‘backup’: File exists\n", - "bash: thisisatest.txt: cannot overwrite existing file\n", - "bash: process.txt: cannot overwrite existing file\n", "1: THIS IS THE START\n", "1: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\n" ] @@ -404,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "id": "ae8977b2", "metadata": {}, "outputs": [ @@ -412,35 +359,30 @@ "name": "stdout", "output_type": "stream", "text": [ - "THIS IS THE START\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS THE END\n", - "--------------------------------------------------------------------------------\n", - "THIS IS THE END\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS A TEST\n", - "THIS IS THE START\n" + "1010\n", + "0000\n", + "1111\n", + "\n" ] } ], "source": [ "#9) reverse REVERSES cat COMMAND\n", "## BAD: alias reverse='tac'\n", - "cat thisisatest.txt\n", - "linebr\n", - "reverse thisisatest.txt" + "\n", + "# # Another approach\n", + "# cat thisisatest.txt\n", + "# linebr\n", + "# reverse thisisatest.txt\n", + "\n", + "printf \"\\n1111\\n0000\\n1010\\n\" > tacexample.txt\n", + "tac tacexample.txt\n", + "# [ \"$(tac tacexample.txt)\" = \"1010\\n0000\\n1111\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 19, "id": "29a5af6d", "metadata": {}, "outputs": [ @@ -460,7 +402,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 20, "id": "a8c89aa1", "metadata": {}, "outputs": [ @@ -470,8 +412,7 @@ "text": [ "Backing up 'usage.bytes.list' to './backup/usage.bytes.list'\n", "NN.NM\t.\n", - "N.NNM\t./backup\n", - "N.NNM\t./info\n" + "N.NNM\t./backup\n" ] } ], @@ -483,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 21, "id": "9f2bfe8c", "metadata": { "scrolled": true @@ -509,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 22, "id": "5c1dc2a2", "metadata": {}, "outputs": [], @@ -529,7 +470,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "id": "895d01b9", "metadata": {}, "outputs": [], @@ -541,7 +482,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 24, "id": "4e48f66b", "metadata": {}, "outputs": [], @@ -555,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 25, "id": "d5cf2239", "metadata": {}, "outputs": [], @@ -588,7 +529,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "id": "0c36d6d5", "metadata": { "scrolled": true @@ -598,9 +539,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "bash: process1.txt: cannot overwrite existing file\n", - "bash: process2.txt: cannot overwrite existing file\n", - "/tmp/test-trace-misc/test-1210\n" + "/tmp/test-trace-misc/test-1001\n" ] } ], @@ -628,7 +567,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "id": "a19413d5", "metadata": {}, "outputs": [ @@ -636,12 +575,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "hhhhhhhhhhh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n", + "11c11\n", + "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", "---\n", - "> ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "> ushrxhhhh hhhhhh hhh h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n" + "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" ] } ], @@ -654,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "id": "169b9a64", "metadata": {}, "outputs": [ @@ -662,12 +599,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "hhhhhhhhhhh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n", + "11c11\n", + "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", "---\n", - "> ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "> ushrxhhhh hhhhhh hhh h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n" + "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" ] } ], @@ -679,7 +614,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 29, "id": "636168eb", "metadata": {}, "outputs": [ @@ -687,12 +622,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "hhhhhhhhhhh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n", + "11c11\n", + "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", "---\n", - "> ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "> ushrxhhhh hhhhhh hhh h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n" + "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" ] } ], @@ -703,7 +636,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 30, "id": "486aec7d", "metadata": {}, "outputs": [ @@ -711,16 +644,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "prohhssh.txt vs. prohhssh.txt\n", - "hihhhrhnhhs: prohhssh.txt prohhssh.txt\n", - "-rw-r--r-- h ushrxhhhh ushrxhhhh hhhh hug hh hh:hh prohhssh.txt\n", - "-rw-r--r-- h ushrxhhhh ushrxhhhh hhhh hug hh hh:hh prohhssh.txt\n", - "hhhhhhhhhhh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "< ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n", + "process1.txt vs. process2.txt\n", + "Differences: process1.txt process2.txt\n", + "-rw-rw-r-- 1 userxf333 userxf333 877 Feb 14 20:59 process1.txt\n", + "-rw-rw-r-- 1 userxf333 userxf333 877 Feb 14 20:59 process2.txt\n", + "18% differences for process1.txt\n", + "11c11\n", + "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", "---\n", - "> ushrxhhhh hhhhhh h.h h.h hhhhh hhhh pts/h Ss hh:hh h:hh /usr/hin/hhsh\n", - "> ushrxhhhh hhhhhh hhh h.h hhhhh hhhh pts/h R+ hh:hh h:hh ps -u\n", + "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", "------------------------------------------------------------------------\n", "\n" ] @@ -733,7 +665,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 31, "id": "903ac57f", "metadata": {}, "outputs": [], @@ -751,7 +683,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 32, "id": "cbe6782b", "metadata": {}, "outputs": [ @@ -759,16 +691,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "bash: testtxt1.txt: cannot overwrite existing file\n", - "bash: testtxt2.txt: cannot overwrite existing file\n", - "renamed './ls-alR.list' -> './ls-alR.list.NNAugNN.N' \n", - "renamed './ls-alR.list.log' -> './ls-alR.list.log.NNAugNN.N' \n", - "renamed './ls-aR.list' -> './ls-aR.list.NNAugNN.N' \n", - "renamed './ls-aR.list.log' -> './ls-aR.list.log.NNAugNN.N' \n", - "-rw-r--r-- N userxfNNN userxfNNN N.NK NN NN:NN ./ls-alR.list\n", - "-rw-r--r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list.log\n", - "-rw-r--r-- N userxfNNN userxfNNN N.NK NN NN:NN ./ls-aR.list\n", - "-rw-r--r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list.log\n" + "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-alR.list.log\n", + "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-aR.list.log\n" ] } ], @@ -782,7 +708,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 33, "id": "1985ac69", "metadata": {}, "outputs": [], @@ -795,43 +721,39 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 34, "id": "c401e80e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "bash: /tmp/test-trace-misc/test-1210/info/.noice-signature: No such file or directory\n" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], + "outputs": [], "source": [ "# Global Setup\n", "#\n", "## WTF?: rm -rf $HOME/info > /dev/null\n", "## HACK: map HOME to current directory\n", + "\n", + "# OLD:\n", "save_HOME=$HOME\n", "HOME=$PWD\n", "mkdir -p $HOME/info\n", "# BAD: rm -rf ./* > /dev/null\n", - "command mv -f * $trash_dir\n", + "# command mv -f * $trash_dir\n", "echo \"THIS IS A NOICE SIGNATURE\" > $HOME/info/.noice-signature" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "ae4468ab", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THIS IS A NOICE SIGNATURE\n" + ] + } + ], "source": [ "## BAD: signature noice | testuser\n", "signature noice | tail --lines=+2 | testuser" @@ -839,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "aa359b7a-165a-4909-9e1a-405940dc564d", "metadata": {}, "outputs": [], @@ -850,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "06a251ce-184b-4c6d-81e0-ae6a7bfe5837", "metadata": {}, "outputs": [], @@ -861,7 +783,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "1c375a69", "metadata": {}, "outputs": [], @@ -892,17 +814,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "f0222991", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Backing up 'process1.txt' to './backup/process1.txt'\n" + ] + } + ], "source": [ "dobackup process1.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "id": "bc964696", "metadata": {}, "outputs": [], @@ -915,7 +845,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "id": "198d4bae", "metadata": {}, "outputs": [], @@ -927,20 +857,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "id": "b0c3f7d4-591b-4905-ba3e-12cebb2f0c4f", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "## BAD: do this outside of Jupyter (e.g., in case temp_dir set to /tmp)!\n", "## # NEW (Remove temp after use)\n", "## rm -rf $temp_dir > /dev/null\n", - "command mv $HOME/info/.noice-signature " + "\n", + "command mv -f * $trash_dir \n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "60a12cb0-8269-4498-b05c-5bd358da8245", "metadata": {}, "outputs": [], From 105a47a13eca29da1e530e6cabed3433556073b6 Mon Sep 17 00:00:00 2001 From: ZAVEE Date: Fri, 16 Feb 2024 21:01:41 +0545 Subject: [PATCH 14/26] Reworked on issue: Test halted at Cell 17 --- tests/git-aliases-tests-3.ipynb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/git-aliases-tests-3.ipynb b/tests/git-aliases-tests-3.ipynb index d51372a8..c513fff1 100644 --- a/tests/git-aliases-tests-3.ipynb +++ b/tests/git-aliases-tests-3.ipynb @@ -214,7 +214,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "[1] 3936821\n", + "[1] 43124\n", + "\n", + "This message is displayed because 'diff.tool' is not configured.\n", + "See 'git difftool --tool-help' or 'git help config' for more details.\n", + "'git difftool' will now attempt to use one of the following tools:\n", + "meld opendiff kdiff3 tkdiff xxdiff kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare smerge emerge vimdiff nvimdiff\n", + "The diff tool bc is not available as 'bcompare'\n", + "fatal: external diff died, stopping at temp-hello.txt\n", "[1]+ Done git-vdiff-alias temp-hello.txt\n" ] } @@ -282,7 +289,9 @@ "cell_type": "code", "execution_count": 17, "id": "46dce0df-5f71-4206-9481-faf4082d6557", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -304,6 +313,7 @@ "export GIT_MESSAGE=\"checkin\"\n", "previous=$GIT_NO_CONFIRM\n", "export GIT_NO_CONFIRM=\"1\"\n", + "# git-next-checkin temp-hello.txt\n", "git-next-checkin temp-hello.txt 2>&1 | command egrep 'hello|issuing'" ] }, @@ -321,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "0f2027d6-f16e-4906-8815-8c2d9c4935ab", "metadata": {}, "outputs": [ @@ -342,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "1f7de086-f57a-401e-b39a-2b5062ce5a65", "metadata": {}, "outputs": [], @@ -356,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "b3441cc6-f773-4db2-b233-660a2c51beab", "metadata": {}, "outputs": [], From bee4811331ea3ef912dd63b3484dfce2cc41dd7a Mon Sep 17 00:00:00 2001 From: ZAVEE Date: Fri, 16 Feb 2024 21:02:30 +0545 Subject: [PATCH 15/26] Work in Progress: Added conditional echo upto cell 34 --- tests/trace-unix-alias.ipynb | 69 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/tests/trace-unix-alias.ipynb b/tests/trace-unix-alias.ipynb index 70050329..a85744ff 100644 --- a/tests/trace-unix-alias.ipynb +++ b/tests/trace-unix-alias.ipynb @@ -188,12 +188,7 @@ "\n", "mkdir testfolder\n", "echo \"Hi Mom!\" > himom.txt\n", - "echo \"Hi Dad!\" > hidad.txt\n", - "\n", - "## $ do-make \"himom.txt\"\n", - "## $ cat _make.log\n", - "## | do-make: command not found\n", - "## | cat: _make.log: No such file or directory\n" + "echo \"Hi Dad!\" > hidad.txt" ] }, { @@ -203,6 +198,7 @@ "metadata": {}, "outputs": [], "source": [ + "## Dropped support\n", "# do-make \"hidad.txt\"\n", "# cat _make.log" ] @@ -217,15 +213,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "total N \n", - "-rw-rw-r-- N userxf333 userxf333 N N N:N hidad.txt\n", - "-rw-rw-r-- N userxf333 userxf333 N N N:N himom.txt\n", - "drwxrwxr-x N userxf333 userxf333 N N N:N testfolder\n" + "0\n" ] } ], "source": [ - "ls -l | awk '!($6=\"\")' | testnum | testuser" + "## OLD: ls -l | awk '!($6=\"\")' | testnum | testuser\n", + "[ \"$(ls | grep -E \"himom.txt|hidad.txt|testfolder\" | wc -l)\" -eq 3 ]; echo $?" ] }, { @@ -238,7 +232,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "do-merge MODFILE1 OLDFILE MODFILE2 > NEWFILE tf1.txt tf2.txt\n" + "0\n" ] } ], @@ -251,7 +245,8 @@ "printf \"THIS IS THE 3RD FILE.\" > tf3.txt\n", "\n", "# MESSAGE SHOWN IF MERGE IS USED\n", - "merge tf1.txt tf2.txt" + "## OLD: merge tf1.txt tf2.txt\n", + "[ \"$(merge tf1.txt tf2.txt)\" = \"do-merge MODFILE1 OLDFILE MODFILE2 > NEWFILE tf1.txt tf2.txt\" ]; echo $?" ] }, { @@ -316,7 +311,7 @@ "## OLD\n", "# which\n", "which python | grep -q \"python\" && echo \"PY-TRUE\" || echo \"PY-FALSE\"\n", - "\n", + "# [ \"$(which python | grep -q \"python\")\" ]; echo $?\n", "# # 3A) full-dirname RETURNS THE FULL PATH OF THE FILE\n", "# full-dirname himom.txt | testuser\n", "\n", @@ -334,12 +329,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/trace-unix-commands/test-7766/himom.txt\n" + "0\n" ] } ], "source": [ - "full-dirname himom.txt" + "## OLD: full-dirname himom.txt\n", + "[ \"$(full-dirname himom.txt)\" = \"/tmp/trace-unix-commands/test-7766/himom.txt\" ]; echo $?" ] }, { @@ -352,12 +348,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "./himom.txt\n" + "0\n" ] } ], "source": [ - "basename-with-dir himom.txt" + "## OLD: basename-with-dir himom.txt\n", + "[ \"$(basename-with-dir himom.txt)\" = \"./himom.txt\" ]; echo $?" ] }, { @@ -549,16 +546,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "This is Ubuntu!\n" + "0\n" ] } ], "source": [ "# perl-echo ONLY PRINTS OUT THE 1ST ARGUMENT\n", "PERL_PRINT='This is Ubuntu!'\n", - "perl-echo $PERL_PRINT\n", + "## OLD: perl-echo $PERL_PRINT\n", + "[ \"$(perl-echo \"$PERL_PRINT\")\" = \"$PERL_PRINT\" ]; echo $?\n", "## MOVED: TO NEXT CELL\n", - "# perl-echo-sans-newline $PERL_PRINT" + "# perl-echo-sans-newline $PERL_PRINT\n" ] }, { @@ -571,12 +569,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "This\n" + "0\n" ] } ], "source": [ - "perl-echo-sans-newline $PERL_PRINT" + "## OLD: perl-echo-sans-newline $PERL_PRINT\n", + "[ \"$(perl-echo-sans-newline $PERL_PRINT)\" = \"This\" ]; echo $?" ] }, { @@ -589,13 +588,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "ONE KISS IS ALL IT TAKES\n" + "0\n" ] } ], "source": [ "# Several print commands (perl-based)\n", - "perl-printf 'ONE KISS IS ALL IT TAKES\\n'\n", + "## OLD: perl-printf 'ONE KISS IS ALL IT TAKES\\n'\n", + "[ \"$(perl-printf 'ONE KISS IS ALL IT TAKES\\n' | wc -c)\" -eq 25 ]; echo $? \n", "# perl-print '2\\n3\\n5\\n7\\n11'\n", "# perl-print-n 'A B C D E F G\\n'\n", "# quote-tokens 'HELP ME!'" @@ -620,6 +620,7 @@ } ], "source": [ + "# OLD: perl-print '2\\n3\\n5\\n7\\n11'\n", "perl-print '2\\n3\\n5\\n7\\n11'" ] }, @@ -633,12 +634,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "A B C D E F G\n" + "0\n" ] } ], "source": [ - "perl-print-n 'A B C D E F G\\n'" + "# OLD: perl-print-n 'A B C D E F G\\n'\n", + "[ \"$(perl-print-n 'A B C D E F G\\n')\" = \"A B C D E F G\" ]; echo $? " ] }, { @@ -651,12 +653,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "\"HELP\" \"ME!\"\n" + "0\n" ] } ], "source": [ - "quote-tokens 'HELP ME!'" + "# OLD: quote-tokens 'HELP ME!'\n", + "[ \"$(quote-tokens 'HELP ME!')\" = '\"HELP\" \"ME!\"' ]; echo $? " ] }, { @@ -693,10 +696,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Sat Feb N N:N:N PM +N N\n", + "start: Fri Feb N N:N:N PM +N N\n", "+ eval ''\n", "+ set - -o xtrace\n", - "end: Sat Feb N N:N:N PM +N N\n" + "end: Fri Feb N N:N:N PM +N N\n" ] } ], @@ -723,10 +726,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Sat Feb N N:N:N PM +N N\n", + "start: Fri Feb N N:N:N PM +N N\n", "+ eval ''\n", "+ set - -o xtrace\n", - "end: Sat Feb N N:N:N PM +N N\n" + "end: Fri Feb N N:N:N PM +N N\n" ] } ], From f1a96878ccac594d1dc86ccd439772879436a0eb Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 3 Apr 2024 20:41:14 +0545 Subject: [PATCH 16/26] Removed old/experimental builds for automate_ipynb.py --- tests/wip/automate_ipynb_experimental1.py | 246 ----------------- tests/wip/automate_ipynb_experimental2.py | 318 ---------------------- 2 files changed, 564 deletions(-) delete mode 100644 tests/wip/automate_ipynb_experimental1.py delete mode 100644 tests/wip/automate_ipynb_experimental2.py diff --git a/tests/wip/automate_ipynb_experimental1.py b/tests/wip/automate_ipynb_experimental1.py deleted file mode 100644 index 64175243..00000000 --- a/tests/wip/automate_ipynb_experimental1.py +++ /dev/null @@ -1,246 +0,0 @@ -#! /usr/bin/env python - -# DATE: 2023-09-26 (22:38 +05:45 GMT) -# INDEV: automate_ipynb_indev.py -# Automates Jupyter Notebook testing using Selenium Webdriver -# Estimated Time (default, per testfile): (SELENIUM_SLEEP_RERUN + 20) + [0 to 1] seconds - -# TODO: (A LOT!) -# (CHECKED) 1. Convert to a class-based approach -# 2. (EXPERIMENTAL - ENV VAR) Run the command run-jupyter-notebook before starting the tests -# (50% CHECKED) 3. Track time for each testfile and finally overall testfiles (time.time) -# 4. IMP: Detect if run-jupyter-notebook is executed (if not, execute) -# 5. Fix the location of TESTFILE_URL -# 6. Add script termination for Invalid Credentials (XPATH ADDED) - -# Author: Aviyan Acharya (avyn.xyz@gmail.com) - -""" -Automates Jupyter Notebook testing using Selenium Webdriver -""" - -# Standard modules -import time -import random - -# Installed modules -from selenium import webdriver -from selenium.webdriver.common.by import By - -# Local modules -from mezcla import debug -from mezcla.main import Main -from mezcla import system -from mezcla import glue_helpers as gh - -## Debug Tracing -debug.trace(5, f"global __doc__: {__doc__}") -debug.assertion(__doc__) - -## Constants 0 (Command-line Labels) -INCLUDE_TESTFILE = "include" -FIRST_N_TESTFILE = "first" -VERBOSE = "verbose" - -## Constants I (Initials for script) -TL = debug.TL -TESTFILE_URL = "http://127.0.0.1:8888/tree/" -JUPYTER_TOKEN = "111222" -JUPYTER_EXTENSION = ".ipynb" -NOBATSPP = "NOBATSPP" -IPYNB_HELLO_WORLD_BASIC = "hello-world-basic.ipynb" -COMMAND_RUN_JUPYTER = "run-jupyter-notebook" -debug.assertion(TESTFILE_URL.endswith("/")) - -## Constant II (Elements for Selenium Webdriver) -SELENIUM_SLEEP_RERUN = 40 -# HTML IDs for each component -ID_PASSWORD_INPUT = "password_input" -ID_LOGIN_SUBMIT = "login_submit" -ID_KERNELLINK = "kernellink" -ID_RESTART_RUN_ALL = "restart_run_all" -ID_FILELINK = "filelink" -ID_SAVE_CHECKPOINT = "save_checkpoint" -ID_CLOSE_AND_HALT = "close_and_halt" -# XPATH for some HTML elements -XPATH_RESTART_RUN_ALL_WARNING_RED = "/html/body/div[8]/div/div/div[3]/button[2]" -XPATH_INVALID_CREDENTIALS = "/html/body/div[2]/div/div[2]/div" - -## Environment options -SELECT_NOBATSPP = system.getenv_bool("SELECT_NOBATSPP", False, - description="Includes testfiles with NOBATSPP during automation (Default: False)") -JUPYTER_PASSWORD = system.getenv_text("JUPYTER_PASSWORD", JUPYTER_TOKEN, - description="Token or Password for Jupyter Notebook (DEFAULT: '111222')") -USE_FIREFOX = system.getenv_bool("USE_FIREFOX", True, - description="Uses GeckoDriver when True, else uses ChromeDriver (Default: True)") -AUTOMATION_DURATION_RERUN = system.getenv_int("AUTOMATION_DURATION_RERUN", SELENIUM_SLEEP_RERUN, - description="Sets duration (in seconds) for automating re-run for each testfile (Default: 30)") -OUTPUT_PATH = system.getenv_text("OUTPUT_PATH", ".", - description=f"Target output .{JUPYTER_EXTENSION} file path (Default: .)") -RANDOMIZE_TESTS = system.getenv_bool("RANDOMIZE_TESTS", False, - description="Randomized the testfile order during execution (Default: False)") -DISABLE_SINGLE_INPUT = system.getenv_bool("DISABLE_SINGLE_INPUT", False, - description="Disables single testfile automation and allows all testfiles (if --include not used) (Default: False)") -FORCE_RUN_JUPYTER = system.getenv_bool("FORCE_RUN_JUPYTER", True, - description="Runs the command 'run-jupyter-notebook' when script executed (Default: True)") -END_PAUSE = system.getenv_float("END_PAUSE", 0, - "Number of seconds to pause after running") - -class AutomateIPYNB(Main): - """Consists of functions for the automation of testfiles (.ipynb)""" - opt_include_file = "" - opt_first_n_testfile = 0 - opt_verbose = None - driver = webdriver.Firefox() - - def get_entered_text(self, label: str, default: str = "") -> str: - """ - Return entered LABEL var/arg text by command-line or environment variable, - also can be specified a DEFAULT value - """ - result = (self.get_parsed_argument(label=label.lower()) or - system.getenv_text(var=label.upper())) - result = result if result else default - debug.trace(7, f'automate_ipynb.get_entered_text(label={label}) => {result}') - return result - - def setup(self): - """Check results of command line processing""" - self.opt_include_file = self.get_entered_text(INCLUDE_TESTFILE, self.opt_include_file) - self.opt_first_n_testfile = int(self.get_entered_text(FIRST_N_TESTFILE, self.opt_first_n_testfile)) - self.opt_verbose = self.get_parsed_option(VERBOSE, self.opt_verbose) - self.driver = self.driver if USE_FIREFOX else webdriver.Chrome() - debug.trace_object(5, self, label=f"{self.__class__.__name__} instance") - - def wrap_up_driver(self): - self.driver.quit() - - def return_ipynb_url_array(self): - """Returns an array of URLs of IPYNB testfiles""" - ipynb_files_all = [file for file in system.read_directory("./") if file.endswith(JUPYTER_EXTENSION)] - ipynb_files_filtered = [file for file in ipynb_files_all if not NOBATSPP in file] - ipynb_url = [] - - # Create a copy of the original list - ipynb_files = ipynb_files_all.copy() - - # Apply filtering conditions - # A) SELECT_BATSPP selects each and every file - if not SELECT_NOBATSPP: - ipynb_files = ipynb_files_filtered.copy() - - # B) RANDOMIZE_TESTS randomizes the order of tests - if RANDOMIZE_TESTS: - random.shuffle(ipynb_files) - - # C) DISABLE_SINGLE_INPUT when false only selects one file for test (hello-world-basic.ipynb) - if not DISABLE_SINGLE_INPUT: - if self.opt_first_n_testfile: - ipynb_files = ipynb_files[:self.opt_first_n_testfile] - elif not RANDOMIZE_TESTS: - ipynb_files = [IPYNB_HELLO_WORLD_BASIC] - else: - ipynb_files = [random.choice(ipynb_files)] - - if self.opt_include_file: - # If an include file is specified, only include that file - ipynb_files = [self.opt_include_file] - - # If neither opt_first_n_testfile nor opt_include_file is specified, - # the list ipynb_files will remain as is (all test files). - - # Sort array alphabetically - ipynb_files.sort() - - # Iterate through all files present in the array - for file in ipynb_files: - file_url = TESTFILE_URL + file - print (file_url) - ipynb_url.append(file_url) - return ipynb_url - - def automate_testfile(self, url_arr:str): - """Automates the testfile using URLs from argument""" - test_count = 1 - print("\nDuration for each testfiles (in seconds):") - for url in url_arr: - if not url.startswith("http"): - url = TESTFILE_URL + url - start_time = time.time() - - ## OLD: driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() - driver = self.driver - debug.trace_expr(5, url) - driver.get(url) - time.sleep(1) - if JUPYTER_PASSWORD: - token_input_box = driver.find_element(By.ID, ID_PASSWORD_INPUT) - token_input_submit = driver.find_element(By.ID, ID_LOGIN_SUBMIT) - token_input_box.send_keys(JUPYTER_PASSWORD) - token_input_submit.click() - - # TODO: In the case of Invalid Credentials - try: - time.sleep(1) - driver.find_element(By.ID, ID_KERNELLINK).click() - time.sleep(3) - driver.find_element(By.ID, ID_RESTART_RUN_ALL).click() - time.sleep(3) - driver.find_element(By.XPATH, XPATH_RESTART_RUN_ALL_WARNING_RED).click() - time.sleep(AUTOMATION_DURATION_RERUN) - driver.find_element(By.ID, ID_FILELINK).click() - time.sleep(2) - driver.find_element(By.ID, ID_SAVE_CHECKPOINT).click() - time.sleep(2) - driver.find_element(By.ID, ID_FILELINK).click() - time.sleep(2) - driver.find_element(By.ID, ID_CLOSE_AND_HALT).click() - time.sleep(2) - ## TODO: put quit in new wrap_up method - ## OLD: driver.quit() - self.wrap_up_driver() - except: - system.print_exception_info(f"navigating url {url}") - self.wrap_up_driver() - finally: - self.wrap_up_driver() - end_time = time.time() - - print(f"#{test_count}. {url.split('/')[-1]}: {round(end_time - start_time, 2)}") - test_count += 1 - if END_PAUSE: - time.sleep(END_PAUSE) - - def run_main_step(self): - """Process main script""" - start_time_main = time.time() - ## OLD: self.automate_testfile(self.return_ipynb_url_array()) - test_files = [self.filename] if (self.filename != "-") else self.return_ipynb_url_array() - self.automate_testfile(test_files) - print(f"\nTotal Time (including pauses): {round(time.time() - start_time_main, 2)} sec\n") - -def main(): - """Entry point""" - app = AutomateIPYNB( - description = __doc__.format(script=gh.basename(__file__)), - skip_input = False, - manual_input = True, - auto_help = False, - boolean_options=[ - (VERBOSE, "Verbose Mode"), - ], - text_options=[ - (INCLUDE_TESTFILE, "Includes a single testfile for automation"), - ], - int_options=[ - (FIRST_N_TESTFILE, "Includes first N testfiles for automation"), - ], - float_options=None - ) - app.run() - -#------------------------------------------------------------------------------- - -if __name__ == '__main__': - debug.trace_current_context(level=TL.QUITE_VERBOSE) - main() diff --git a/tests/wip/automate_ipynb_experimental2.py b/tests/wip/automate_ipynb_experimental2.py deleted file mode 100644 index 0f403c93..00000000 --- a/tests/wip/automate_ipynb_experimental2.py +++ /dev/null @@ -1,318 +0,0 @@ -#! /usr/bin/env python - -# DATE: 2023-09-26 (22:38 +05:45 GMT) -# INDEV: automate_ipynb_indev.py -# Automates Jupyter Notebook testing using Selenium Webdriver -# Estimated Time (default, per testfile): (SELENIUM_SLEEP_RERUN + 20) + [0 to 1] seconds - -# TODO: (A LOT!) -# (CHECKED) 1. Convert to a class-based approach -# 2. (EXPERIMENTAL - ENV VAR) Run the command run-jupyter-notebook before starting the tests -# (50% CHECKED) 3. Track time for each testfile and finally overall testfiles (time.time) -# 4. IMP: Detect if run-jupyter-notebook is executed (if not, execute) -# 5. Fix the location of TESTFILE_URL -# 6. Add script termination for Invalid Credentials (XPATH ADDED) - -# Author: Aviyan Acharya (avyn.xyz@gmail.com) - -""" -Automates Jupyter Notebook testing using Selenium Webdriver -""" - -# Standard modules -import time -import random - -# Installed modules -from selenium import webdriver -from selenium.webdriver.common.by import By - -# Local modules -from mezcla import debug -from mezcla.main import Main -from mezcla import system -from mezcla import glue_helpers as gh - -## Debug Tracing -debug.trace(5, f"global __doc__: {__doc__}") -debug.assertion(__doc__) - -## Constants 0 (Command-line Labels) -OPT_INCLUDE_TESTFILE = "include" -OPT_FIRST_N_TESTFILE = "first" -OPT_VERBOSE = "verbose" - -## Constants I (Initials for script) -TL = debug.TL -TESTFILE_URL = "http://127.0.0.1:8888/tree/tests/" -JUPYTER_TOKEN = "111222" -JUPYTER_EXTENSION = ".ipynb" -NOBATSPP = "NOBATSPP" -IPYNB_HELLO_WORLD_BASIC = "hello-world-basic.ipynb" -COMMAND_RUN_JUPYTER = "run-jupyter-notebook" -debug.assertion(TESTFILE_URL.endswith("/")) - -## Constant II (Elements for Selenium Webdriver) -SELENIUM_SLEEP_RERUN = 40 -SELENIUM_IMPLICIT_WAIT = 10 - -# HTML IDs for each component -ID_PASSWORD_INPUT = "password_input" -ID_LOGIN_SUBMIT = "login_submit" -ID_KERNELLINK = "kernellink" -ID_RESTART_RUN_ALL = "restart_run_all" -ID_FILELINK = "filelink" -ID_SAVE_CHECKPOINT = "save_checkpoint" -ID_CLOSE_AND_HALT = "close_and_halt" -ID_MENU_CHANGE_KERNEL = "menu-change-kernel" -ID_KERNEL_SUBMENU_BASH = "kernel-submenu-bash" - -# XPATH for some HTML elements -## OLD: XPATH_RESTART_RUN_ALL_WARNING_RED = "/html/body/div[8]/div/div/div[3]/button[2]" -## OLD: XPATH_INVALID_CREDENTIALS = "/html/body/div[2]/div/div[2]/div" -XPATH_PASSWORD_INPUT = f"//input[@id='{ID_PASSWORD_INPUT}']" -XPATH_LOGIN_SUBMIT = f"//button[@id='{ID_LOGIN_SUBMIT}']" -XPATH_RESTART_RUN_ALL_WARNING_RED = "//div/button[text()='Restart and Run All Cells']" -XPATH_INVALID_CREDENTIALS = "//div[@class='message error' and text()='Invalid credentials']" -XPATH_MENU_CHANGE_KERNEL = f"//li[@id='{ID_MENU_CHANGE_KERNEL}']/a" -XPATH_KERNEL_SUBMENU_BASH = f"//li[@id='{ID_KERNEL_SUBMENU_BASH}']/a" - -## Environment options -SELECT_NOBATSPP = system.getenv_bool("SELECT_NOBATSPP", False, - description="Includes testfiles with NOBATSPP during automation (Default: False)") -JUPYTER_PASSWORD = system.getenv_text("JUPYTER_PASSWORD", JUPYTER_TOKEN, - description="Token or Password for Jupyter Notebook (DEFAULT: '111222')") -USE_FIREFOX = system.getenv_bool("USE_FIREFOX", True, - description="Uses GeckoDriver when True, else uses ChromeDriver (Default: True)") -AUTOMATION_DURATION_RERUN = system.getenv_int("AUTOMATION_DURATION_RERUN", SELENIUM_SLEEP_RERUN, - description="Sets duration (in seconds) for automating re-run for each testfile (Default: 30)") -OUTPUT_PATH = system.getenv_text("OUTPUT_PATH", ".", - description=f"Target output .{JUPYTER_EXTENSION} file path (Default: .)") -RANDOMIZE_TESTS = system.getenv_bool("RANDOMIZE_TESTS", False, - description="Randomized the testfile order during execution (Default: False)") -DISABLE_SINGLE_INPUT = system.getenv_bool("DISABLE_SINGLE_INPUT", False, - description="Disables single testfile automation and allows all testfiles (if --include not used) (Default: False)") -FORCE_RUN_JUPYTER = system.getenv_bool("FORCE_RUN_JUPYTER", True, - description="Runs the command 'run-jupyter-notebook' when script executed (Default: True)") -END_PAUSE = system.getenv_float("END_PAUSE", 0, - "Number of seconds to pause after running") -IMPLICIT_WAIT = system.getenv_float("IMPLICIT_WAIT", SELENIUM_IMPLICIT_WAIT, - "Number of seconds to pause Webdriver implicitly") -FORCE_SET_BASH_KERNEL = system.getenv_bool("FORCE_SET_BASH_KERNEL", False, - description="Force sets Bash kernel when reruning each testfile (Default: False)") - -class AutomateIPYNB: - """Consists of functions for the automation of testfiles (.ipynb)""" - - def __init__( - self, - OPT_INCLUDE_TESTFILE, - OPT_FIRST_N_TESTFILE, - OPT_VERBOSE - ): - """Initializer for class: AutomateIPYNB""" - self.OPT_INCLUDE_TESTFILE = OPT_INCLUDE_TESTFILE - self.OPT_FIRST_N_TESTFILE = OPT_FIRST_N_TESTFILE - self.OPT_VERBOSE = OPT_VERBOSE - self.driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() - - def wrapup(self): - """Process end of input""" - if self.driver: - self.driver(quit) - self.driver = None - - def return_ipynb_url_array(self): - """Returns an array of URLs of IPYNB testfiles""" - ipynb_files_all = [file for file in system.read_directory("./") if file.endswith(JUPYTER_EXTENSION)] - ipynb_files_filtered = [file for file in ipynb_files_all if not NOBATSPP in file] - ipynb_url = [] - - # Create a copy of the original list - ipynb_files = ipynb_files_all.copy() - - # Apply filtering conditions - # A) SELECT_BATSPP selects each and every file - if not SELECT_NOBATSPP: - ipynb_files = ipynb_files_filtered.copy() - - # B) RANDOMIZE_TESTS randomizes the order of tests - if RANDOMIZE_TESTS: - random.shuffle(ipynb_files) - - # C) Handle the opt_first_n_testfile and opt_include_file options - if self.OPT_FIRST_N_TESTFILE: - ipynb_files = ipynb_files[:self.OPT_FIRST_N_TESTFILE] - elif self.OPT_INCLUDE_TESTFILE: - # If an include file is specified, only include that file - ipynb_files = [self.OPT_INCLUDE_TESTFILE] - - # If neither opt_first_n_testfile nor opt_include_file is specified, - # the list ipynb_files will remain as is (all test files). - - # Iterate through all files present in the array - for file in ipynb_files: - file_url = TESTFILE_URL + file - print (file_url) - ipynb_url.append(file_url) - - return ipynb_url - - def find_element(self, how, elem_id): - """Finds ELEM_ID in DOM using HOW (e.g., By.ID)""" - # ex: token_input_box = self.find_element(By.ID, ID_PASSWORD_INPUT) - debug.trace(5, f"find_element({how}, {elem_id}); self={self}") - elem = None - try: - elem = self.driver.find_element(how, elem_id) - except: - system.print_exception_info(f"find_element {elem_id}") - debug.trace(6, f"find_element() => {elem}") - return elem - - def click_element(self, how, elem_id, delay=2): - """Finds ELEM_ID in DOM using HOW (e.g., By.ID), and it clicks if found""" - # ex: token_input_box = self.find_element(By.ID, ID_PASSWORD_INPUT) - debug.trace(5, f"find_element({how}, {elem_id}); self={self}") - result = None - try: - elem = self.driver.find_element(how, elem_id) - result = elem.click() - time.sleep(delay) - ## TODO2 (for automatic debug tracing): system.pause(delay) - except: - system.print_exception_info(f"click_element {elem_id}") - debug.trace(6, f"click_element() => {result}") - return result - - def automate_testfile(self, url_arr:str): - """Automates the testfile using URLs from argument""" - debug.trace(5, f"automate_testfile({url_arr!r})") - test_count = 1 - print("\nDuration for each testfiles (in seconds):") - for url in url_arr: - if not url.startswith("http"): - url = TESTFILE_URL + url - start_time = time.time() - - ## OLD: driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() - driver = self.driver - debug.trace_expr(5, url) - driver.get(url) - driver.implicitly_wait(IMPLICIT_WAIT) - debug.trace_expr(5, JUPYTER_PASSWORD) - - token_input_box = self.find_element(By.XPATH, XPATH_PASSWORD_INPUT) - token_input_submit = self.find_element(By.XPATH, XPATH_LOGIN_SUBMIT) - - if (JUPYTER_PASSWORD.strip() and token_input_box and token_input_submit): - # OLD: token_input_box = self.find_element(By.ID, ID_PASSWORD_INPUT) - if token_input_box is not None: - # OLD: token_input_submit = self.find_element(By.ID, ID_LOGIN_SUBMIT) - token_input_box.send_keys(JUPYTER_PASSWORD) - if token_input_box is not None: - token_input_submit.click() - # time.sleep(5) - driver.implicitly_wait(5) - - # TODO: In the case of Invalid Credentials - try: - if FORCE_SET_BASH_KERNEL: - time.sleep(1) - self.click_element(By.ID, ID_KERNELLINK, 1) - self.click_element(By.XPATH, XPATH_MENU_CHANGE_KERNEL, 2) - self.click_element(By.XPATH, XPATH_KERNEL_SUBMENU_BASH, 2) - - self.click_element(By.ID, ID_KERNELLINK, 1) - - ok = self.click_element(By.ID, ID_RESTART_RUN_ALL, 3) - if not ok: - ok = self.click_element(By.XPATH, XPATH_RESTART_RUN_ALL_WARNING_RED, AUTOMATION_DURATION_RERUN) - ## OLD: - # if not ok: - # ## TODO1: get the following to work - # ok = self.click_element(By.XPATH, "//div/button[contains(text(), 'Run All Cells')]", AUTOMATION_DURATION_RERUN) - self.click_element(By.ID, ID_FILELINK) - self.click_element(By.ID, ID_SAVE_CHECKPOINT) - self.click_element(By.ID, ID_FILELINK) - self.click_element(By.ID, ID_CLOSE_AND_HALT) - ## TODO: put quit in new wrap_up method - ## OLD: driver.quit() - except: - system.print_exception_info(f"navigating url {url}") - - finally: - ## OLD: driver.quit() - end_time = time.time() - - print(f"#{test_count}. {url.split('/')[-1]}: {round(end_time - start_time, 2)}") - test_count += 1 - if END_PAUSE: - time.sleep(END_PAUSE) - - self.wrapup() - - def do_it(self): - filename = self.OPT_INCLUDE_TESTFILE - test_files = [filename] if (filename != "-") else self.return_ipynb_url_array() - self.automate_testfile(test_files) - -## END OF AutomateIPYNB - -class RunScriptAutomateIPYNB(Main): - """Adhoc script class (e.g., no I/O loops): just for arg-parsing""" - opt_include_testfile = "" - opt_first_n_testfile = 0 - opt_verbose = "" - driver = None - - def setup(self): - """Check results of command line processing""" - # TODO: rework to make environment optional - self.opt_include_testfile = self.get_parsed_argument(OPT_INCLUDE_TESTFILE, self.opt_include_testfile) - self.opt_first_n_testfile = int(self.get_parsed_argument(OPT_FIRST_N_TESTFILE, self.opt_first_n_testfile)) - self.opt_verbose = self.get_parsed_option(OPT_VERBOSE, self.opt_verbose) - debug.trace_object(5, self, label=f"{self.__class__.__name__} instance") - - def run_main_step(self): - """Process main script""" - start_time_main = time.time() - ## OLD: self.automate_testfile(self.return_ipynb_url_array()) - # test_files = [self.filename] if (self.filename != "-") else self.return_ipynb_url_array() - # self.automate_testfile(test_files) - automate_ipynb = AutomateIPYNB( - self.opt_include_testfile, - self.opt_first_n_testfile, - self.opt_verbose - ) - if FORCE_RUN_JUPYTER: - time.sleep(1) - gh.run(COMMAND_RUN_JUPYTER) - automate_ipynb.do_it() - print(f"\nTotal Time (including pauses): {round(time.time() - start_time_main, 2)} sec\n") - -def main(): - """Entry point""" - app = RunScriptAutomateIPYNB( - description = __doc__.format(script=gh.basename(__file__)), - skip_input = False, - manual_input = True, - auto_help = False, - boolean_options=[ - (OPT_VERBOSE, "Verbose Mode"), - ], - text_options=[ - (OPT_INCLUDE_TESTFILE, "Includes a single testfile for automation"), - ], - int_options=[ - (OPT_FIRST_N_TESTFILE, "Includes first N testfiles for automation"), - ], - float_options=None - ) - app.run() - -#------------------------------------------------------------------------------- - -if __name__ == '__main__': - debug.trace_current_context(level=TL.QUITE_VERBOSE) - main() \ No newline at end of file From 9cdbbb2ebe4b8dd745cc088d01562c5503cc3694 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 3 Apr 2024 20:43:29 +0545 Subject: [PATCH 17/26] Renamed automate_ipynb.py => automate_notebook.py; Toggled FORCE_RUN_JUPYTER to False; Replaced wrapup() with driver.quit() [Webdriver object is not callable]; --first option selects the first N testfiles in alphabetical order; Added termination of script for invalid credentials; Added constant: SELENIUM_SLEEP to pause driver until all the cells are executed --- tests/automate_notebook.py | 367 +++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100755 tests/automate_notebook.py diff --git a/tests/automate_notebook.py b/tests/automate_notebook.py new file mode 100755 index 00000000..4356ccac --- /dev/null +++ b/tests/automate_notebook.py @@ -0,0 +1,367 @@ +#! /usr/bin/env python + +# DATE: 2023-09-26 (22:38 +05:45 GMT) +# INDEV: automate_notebook.py +# Automates Jupyter Notebook testing using Selenium Webdriver +# Estimated Time (default, per testfile): (SELENIUM_SLEEP_RERUN + 20) + [0 to 1] seconds + +# TODO: (A LOT!) +# 1. Convert to a class-based approach [CHECKED] +# 2. Run the command run-jupyter-notebook before starting the tests [] +# 3. Track time for each testfile and finally overall testfiles (time.time) [CHECKED] +# 4. IMP: Detect if run-jupyter-notebook is executed (if not, execute) [IMPLEMENTED; NOT FUNCTIONING] +# 5. Fix the location of TESTFILE_URL +# 6. Add script termination for Invalid Credentials (XPATH ADDED) + +# 2024-03-05: Refining the script +# 7. Run hello-world ipynb test for the default run +# 8. Sorting must be alphabetical (Completed) +# 9. Add environment variable for Jupyter Token +# 10. Add custom Jupyter commands (or nbclassic) +# 11. Option for enabling or disabling password (Complete) + +# PREQUISITIES (TEMPORARY): +# 0. The script is developed around the use of Jupyter 6 (or nbclassic) +# 1. Before executing the script, run "jupyter-nbclassic" from the root directory of shell-script +# 2. It is advised to setup a password for the notebook, and provide the password through JUPYTER_PASSWORD environment variable + +# Usage Example (run from shell-scripts/tests/): +# zavee@pop-os:~/shell-scripts/tests$ JUPYTER_PASSWORD="password" python3 automate_ipynb --include hello-world-basic.ipynb +""" +Automates Jupyter Notebook testing using Selenium Webdriver +""" + +# Standard modules +import time +import random + +# Installed modules +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.common.exceptions import NoSuchElementException + +# Local modules +from mezcla import debug +from mezcla.main import Main +from mezcla import system +from mezcla import glue_helpers as gh + +## Debug Tracing +debug.trace(5, f"global __doc__: {__doc__}") +debug.assertion(__doc__) + +## Constants 0 (Command-line Labels) +OPT_INCLUDE_TESTFILE = "include" +OPT_FIRST_N_TESTFILE = "first" +OPT_VERBOSE = "verbose" + +## Constants I (Initials for script) +TL = debug.TL +TESTFILE_URL = "http://127.0.0.1:8888/tree/tests/" +JUPYTER_TOKEN = "" +JUPYTER_EXTENSION = ".ipynb" +NOBATSPP = "NOBATSPP" +IPYNB_HELLO_WORLD_BASIC = "hello-world-basic.ipynb" +COMMAND_RUN_JUPYTER = "jupyter nbclassic --no-browser" +debug.assertion(TESTFILE_URL.endswith("/")) + +## Constant II (Elements for Selenium Webdriver) +# Waiting Time before re-running a test +SELENIUM_SLEEP_RERUN = 10 +# Implicit Wait = Amount of time before throwing a 'NoSuchElementException' +SELENIUM_IMPLICIT_WAIT = 10 +SELENIUM_SLEEP = 20 + +# HTML IDs for each component +ID_PASSWORD_INPUT = "password_input" +ID_LOGIN_SUBMIT = "login_submit" +ID_KERNELLINK = "kernellink" +ID_RESTART_RUN_ALL = "restart_run_all" +ID_FILELINK = "filelink" +ID_SAVE_CHECKPOINT = "save_checkpoint" +ID_CLOSE_AND_HALT = "close_and_halt" +ID_MENU_CHANGE_KERNEL = "menu-change-kernel" +ID_KERNEL_SUBMENU_BASH = "kernel-submenu-bash" +ID_CHECKPOINT_STATUS = "autosave_status" + +# XPATH for some HTML elements +## OLD: XPATH_RESTART_RUN_ALL_WARNING_RED = "/html/body/div[8]/div/div/div[3]/button[2]" +## OLD: XPATH_INVALID_CREDENTIALS = "/html/body/div[2]/div/div[2]/div" +XPATH_PASSWORD_INPUT = f"//*[@id='{ID_PASSWORD_INPUT}']" +XPATH_LOGIN_SUBMIT = f"//*[@id='{ID_LOGIN_SUBMIT}']" +## OLD: XPATH_RESTART_RUN_ALL_WARNING_RED = "//div/button[text()='Restart and Run All Cells']" +XPATH_RESTART_RUN_ALL_WARNING_RED = "//*[text()='Restart and Run All Cells']" +XPATH_INVALID_CREDENTIALS = "//*[@class='message error']" +XPATH_MENU_CHANGE_KERNEL = f"//li[@id='{ID_MENU_CHANGE_KERNEL}']/a" +XPATH_KERNEL_SUBMENU_BASH = f"//li[@id='{ID_KERNEL_SUBMENU_BASH}']/a" +XPATH_CHECKPOINT_STATUS = f"//span[@id='{ID_CHECKPOINT_STATUS}']" + +## Environment options +SELECT_NOBATSPP = system.getenv_bool("SELECT_NOBATSPP", False, + description="Includes testfiles with NOBATSPP during automation (Default: False)") +JUPYTER_PASSWORD = system.getenv_text("JUPYTER_PASSWORD", JUPYTER_TOKEN, + description="Token or Password for Jupyter Notebook (DEFAULT: '')") +USE_FIREFOX = system.getenv_bool("USE_FIREFOX", True, + description="Uses GeckoDriver when True, else uses ChromeDriver (Default: True)") +AUTOMATION_DURATION_RERUN = system.getenv_int("AUTOMATION_DURATION_RERUN", SELENIUM_SLEEP_RERUN, + description="Sets duration (in seconds) for automating re-run for each testfile (Default: 30)") +OUTPUT_PATH = system.getenv_text("OUTPUT_PATH", ".", + description=f"Target output .{JUPYTER_EXTENSION} file path (Default: .)") +RANDOMIZE_TESTS = system.getenv_bool("RANDOMIZE_TESTS", False, + description="Randomized the testfile order during execution (Default: False)") +DISABLE_SINGLE_INPUT = system.getenv_bool("DISABLE_SINGLE_INPUT", False, + description="Disables single testfile automation and allows all testfiles (if --include not used) (Default: False)") +FORCE_RUN_JUPYTER = system.getenv_bool("FORCE_RUN_JUPYTER", False, + description="Runs the command 'run-jupyter-notebook' when script executed (Default: True)") +END_PAUSE = system.getenv_float("END_PAUSE", 0, + "Number of seconds to pause after running") +IMPLICIT_WAIT = system.getenv_float("IMPLICIT_WAIT", SELENIUM_IMPLICIT_WAIT, + "Number of seconds to pause Webdriver implicitly") +FORCE_SET_BASH_KERNEL = system.getenv_bool("FORCE_SET_BASH_KERNEL", False, + description="Force sets Bash kernel when reruning each testfile (Default: False)") + +class AutomateNotebook: + """Consists of functions for the automation of testfiles (.ipynb)""" + + def __init__( + self, + OPT_INCLUDE_TESTFILE, + OPT_FIRST_N_TESTFILE, + OPT_VERBOSE + ): + """Initializer for class: AutomateNotebook""" + self.OPT_INCLUDE_TESTFILE = OPT_INCLUDE_TESTFILE + self.OPT_FIRST_N_TESTFILE = OPT_FIRST_N_TESTFILE + self.OPT_VERBOSE = OPT_VERBOSE + self.driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() + + ## OLD: WebDriver object is not callable + def wrapup(self): + """Process end of input""" + if self.driver: + self.driver(quit) + self.driver = None + + def return_ipynb_url_array(self): + """Returns a list of URLs of IPYNB test files based on filtering conditions.""" + debug.trace(5, f"return_ipynb_url_array(); self={self}") + + # Get all IPYNB files in the current directory + ipynb_files_all = [file for file in system.read_directory("./") if file.endswith(JUPYTER_EXTENSION)] + ipynb_files_all.sort() + + # Apply filtering conditions based on environment variables + ipynb_files_filtered = ipynb_files_all.copy() + + # Apply filtering conditions + if not SELECT_NOBATSPP: + ipynb_files_filtered = [file for file in ipynb_files_filtered if NOBATSPP not in file] + + # Randomize the order of files if specified + if RANDOMIZE_TESTS: + random.shuffle(ipynb_files_filtered) + + # Handle the opt_first_n_testfile and opt_include_file options + if self.OPT_FIRST_N_TESTFILE: + ipynb_files_filtered = ipynb_files_filtered[:self.OPT_FIRST_N_TESTFILE] + elif self.OPT_INCLUDE_TESTFILE: + ipynb_files_filtered = [self.OPT_INCLUDE_TESTFILE] + + # Generate URLs for the filtered files + ipynb_urls = [TESTFILE_URL + file for file in ipynb_files_filtered] + + # Print the URLs for debugging + print(f"IPYNB files selected for automation (RANDOMIZE_TESTS:{RANDOMIZE_TESTS})\n") + for url in ipynb_urls: + print(url) + + return ipynb_urls + + + def find_element(self, how, elem_id): + """Finds ELEM_ID in DOM using HOW (e.g., By.ID)""" + # ex: token_password_box = self.find_element(By.ID, ID_PASSWORD_INPUT) + debug.trace(5, f"find_element({how}, {elem_id}); self={self}") + elem = None + try: + elem = self.driver.find_element(how, elem_id) + except: + system.print_exception_info(f"find_element {elem_id}") + debug.trace(6, f"find_element() => {elem}") + return elem + + def click_element(self, how, elem_id, delay=2): + """Finds ELEM_ID in DOM using HOW (e.g., By.ID), and it clicks if found""" + # ex: token_password_box = self.find_element(By.ID, ID_PASSWORD_INPUT) + debug.trace(5, f"find_element({how}, {elem_id}); self={self}") + result = None + try: + elem = self.driver.find_element(how, elem_id) + result = elem.click() + time.sleep(delay) + ## TODO2 (for automatic debug tracing): system.pause(delay) + except: + system.print_exception_info(f"click_element {elem_id}") + debug.trace(6, f"click_element() => {result}") + return result + + def automate_testfile(self, url_arr:str): + """Automates the testfile using URLs from argument""" + debug.trace(5, f"automate_testfile({url_arr!r})") + + test_count = 1 + print("\nDuration for each testfiles (in seconds):\n") + ## NEW: Added an external try (nested try-catch) + try: + for url in url_arr: + if not url.startswith("http"): + url = TESTFILE_URL + url + + start_time = time.time() + # driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() + driver = self.driver + debug.trace_expr(5, url) + driver.get(url) + # driver.implicitly_wait(IMPLICIT_WAIT) + debug.trace_expr(5, JUPYTER_PASSWORD) + + token_password_box = self.find_element(By.XPATH, XPATH_PASSWORD_INPUT) + token_password_submit = self.find_element(By.XPATH, XPATH_LOGIN_SUBMIT) + + if (JUPYTER_PASSWORD.strip() and token_password_box and token_password_submit): + # OLD: token_password_box = self.find_element(By.ID, ID_PASSWORD_INPUT) + if token_password_box is not None and JUPYTER_PASSWORD != "": + # OLD: token_input_submit = self.find_element(By.ID, ID_LOGIN_SUBMIT) + token_password_box.send_keys(JUPYTER_PASSWORD) + if token_password_box is not None and JUPYTER_PASSWORD != "": + token_password_submit.click() + + ## Invalid Credentials is shown if the credentials are not matching + try: + token_invalid_credentials = self.find_element(By.XPATH, XPATH_INVALID_CREDENTIALS) + if token_invalid_credentials is not None: + raise NoSuchElementException("Invalid credentials detected") + except NoSuchElementException: + system.print_exception_info("Invalid Credentials used for notebook") + print("Invalid Credentials. Retry with another password.") + break + except Exception as e: + debug.trace_expr(6) + + driver.implicitly_wait(5) + + try: + if FORCE_SET_BASH_KERNEL: + time.sleep(1) + self.click_element(By.ID, ID_KERNELLINK) + self.click_element(By.XPATH, XPATH_MENU_CHANGE_KERNEL) + self.click_element(By.XPATH, XPATH_KERNEL_SUBMENU_BASH, 2) + + self.click_element(By.ID, ID_KERNELLINK, 1) + ok = self.click_element(By.ID, ID_RESTART_RUN_ALL, 0.25) + if not ok: + ok = self.click_element(By.XPATH, XPATH_RESTART_RUN_ALL_WARNING_RED, 0.25) + ## OLD: + # if not ok: + # ## TODO1: get the following to work + # ok = self.click_element(By.XPATH, "//div/button[contains(text(), 'Run All Cells')]", AUTOMATION_DURATION_RERUN) + # driver.implicitly_wait(IMPLICIT_WAIT) + time.sleep(SELENIUM_SLEEP) + + self.click_element(By.ID, ID_FILELINK, 0.25) + self.click_element(By.ID, ID_SAVE_CHECKPOINT, 0.25) + self.click_element(By.ID, ID_FILELINK, 0.25) + self.click_element(By.ID, ID_CLOSE_AND_HALT, 0.25) + ## TODO: put quit in new wrap_up method + ## OLD: driver.quit() + except: + system.print_exception_info(f"navigating url {url}") + + finally: + ## OLD: driver.quit() + end_time = time.time() + + print(f"\n#{test_count}. {url.split('/')[-1]}: {round(end_time - start_time, 2)}\n") + test_count += 1 + if END_PAUSE: + time.sleep(END_PAUSE) + finally: + if driver: + driver.quit() + + def do_it(self): + + ## TODO: Force run jupyter from root "shell-scripts" directory + if FORCE_RUN_JUPYTER: + time.sleep(1) + gh.run(COMMAND_RUN_JUPYTER) + + filename = self.OPT_INCLUDE_TESTFILE + ## OLD: test_files = [filename] if (filename != "-") else self.return_ipynb_url_array() + if filename in [None, ""]: + test_files = self.return_ipynb_url_array() + else: + test_files = [filename] + self.automate_testfile(test_files) + +## END OF AutomateNotebook + +class RunScriptAutomateNotebook(Main): + """Adhoc script class (e.g., no I/O loops): just for arg-parsing""" + opt_include_testfile = "" + opt_first_n_testfile = 0 + opt_verbose = "" + driver = None + + def setup(self): + """Check results of command line processing""" + # TODO: rework to make environment optional + self.opt_include_testfile = self.get_parsed_argument(OPT_INCLUDE_TESTFILE, self.opt_include_testfile) + self.opt_first_n_testfile = int(self.get_parsed_argument(OPT_FIRST_N_TESTFILE, self.opt_first_n_testfile)) + self.opt_verbose = self.get_parsed_option(OPT_VERBOSE, self.opt_verbose) + debug.trace_object(5, self, label=f"{self.__class__.__name__} instance") + + def run_main_step(self): + """Process main script""" + start_time_main = time.time() + ## OLD: self.automate_testfile(self.return_ipynb_url_array()) + # test_files = [self.filename] if (self.filename != "-") else self.return_ipynb_url_array() + # self.automate_testfile(test_files) + automate_ipynb = AutomateNotebook( + self.opt_include_testfile, + self.opt_first_n_testfile, + self.opt_verbose + ) + # if FORCE_RUN_JUPYTER: + # time.sleep(1) + # # OLD: gh.run(COMMAND_RUN_JUPYTER) + # os.system(COMMAND_RUN_JUPYTER) + automate_ipynb.do_it() + print(f"\nTotal Time (including pauses): {round(time.time() - start_time_main, 2)} sec\n") + +def main(): + """Entry point""" + app = RunScriptAutomateNotebook( + description = __doc__.format(script=gh.basename(__file__)), + skip_input = False, + manual_input = True, + auto_help = False, + boolean_options=[ + (OPT_VERBOSE, "Verbose Mode"), + ], + text_options=[ + (OPT_INCLUDE_TESTFILE, "Includes a single testfile for automation"), + ], + int_options=[ + (OPT_FIRST_N_TESTFILE, "Includes first N testfiles for automation"), + ], + float_options=None + ) + + app.run() + +#------------------------------------------------------------------------------- + +if __name__ == '__main__': + debug.trace_current_context(level=TL.QUITE_VERBOSE) + main() \ No newline at end of file From 3a9a130cbd243f939880c5a40d99c57b204619cf Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 3 Apr 2024 20:59:11 +0545 Subject: [PATCH 18/26] Rerun the test after installing csh and lynx; Commented cells using scripts from archive --- tests/trace-extensionless-shortcut-V2.ipynb | 99 ++++++--------------- 1 file changed, 26 insertions(+), 73 deletions(-) diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index ed079e9b..a62dc672 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_XQUNOUSZZXLT\\[\\]>\n" + "PROMPT_FANKHNUDTDBZ\\[\\]>\n" ] } ], @@ -292,20 +292,13 @@ "execution_count": 17, "id": "1584698d", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ps_mine.sh: command not found\n", - "N\n" - ] - } - ], + "outputs": [], "source": [ "# Large List of process with full process paths\n", "# Number of process is random\n", - "ps-mine-all | wc -l | testnum " + "\n", + "## OLD: ps_mine.sh moved to archive\n", + "# ps-mine-all | wc -l | testnum " ] }, { @@ -313,20 +306,12 @@ "execution_count": 18, "id": "c7070a99", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "do_rcsdiff.sh: command not found\n" - ] - } - ], + "outputs": [], "source": [ "# HELP REQUIRED FOR RCS FILES (TBC)\n", - "## OLD\n", - "## do-rcsdiff\n", - "do-rcsdiff | head -n 1" + "\n", + "## OLD : do_rcsdiff.sh moved to archive\n", + "# do-rcsdiff | head -n 1" ] }, { @@ -462,20 +447,12 @@ "execution_count": 24, "id": "3ca47040", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Can't exec \"domainname.sh\": No such file or directory at /home/aveey/tomProject/shell-scripts/common.perl line 549.\n", - "readline() on closed filehandle RUN_COMMAND_FILE at /home/aveey/tomProject/shell-scripts/common.perl line 550.\n", - "N\n" - ] - } - ], + "outputs": [], "source": [ "# Need Help with example\n", - "foreach \"echo $f\" *.txt | wc -l | testnum" + "\n", + "## OLD: domainname.sh moved to archive\n", + "# foreach \"echo $f\" *.txt | wc -l | testnum" ] }, { @@ -685,17 +662,10 @@ "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" - ] - } - ], + "outputs": [], "source": [ - "unigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "## OLD: count_bigrams.perl moved to archive\n", + "# unigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { @@ -705,19 +675,11 @@ "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" - ] - } - ], + "outputs": [], "source": [ - "## OLD\n", + "## OLD: count_bigrams.perl moved to archive\n", "# word-count ./man_cat.txt | testuser | testnum\n", - "word-count ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "# word-count ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { @@ -725,19 +687,11 @@ "execution_count": 39, "id": "71adad1d", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Can't open perl script \"/home/aveey/tomProject/shell-scripts/count_bigrams.perl\": No such file or directory\n" - ] - } - ], + "outputs": [], "source": [ - "## OLD\n", + "## OLD: count_bigrams.perl moved to archive\n", "# bigrams ./man_cat.txt | testuser | testnum\n", - "bigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "# bigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { @@ -823,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "id": "49d6d56d", "metadata": {}, "outputs": [ @@ -831,15 +785,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[0m\u001b[01;34mbackup\u001b[0m \u001b[01;34mduplicates\u001b[0m \u001b[01;34mnewdir1\u001b[0m\n", - "mv: cannot move 'backup' to '/tmp/test-extensionless/_temp-trash-20240131211227/backup': Directory not empty\n", - "mv: cannot move 'duplicates' to '/tmp/test-extensionless/_temp-trash-20240131211227/duplicates': Directory not empty\n", - "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_temp-trash-20240131211227/newdir1': Directory not empty\n", + "mv: cannot move 'backup' to '/tmp/test-extensionless/_temp-trash-20240404182336/backup': Directory not empty\n", + "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_temp-trash-20240404182336/newdir1': Directory not empty\n", "END\n" ] } ], "source": [ + "# NOTE (PROPOSED APPROACH): Add timestamp to the directory before moving them to trash_dir\n", "command mv -f * \"$trash_dir\"\n", "echo \"END\"" ] From 3e46e5281c1a33c4de4989f6753e59183e8948a4 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Sun, 14 Apr 2024 12:38:40 +0545 Subject: [PATCH 19/26] [WIP] Use of rename-with-file-date to create temporary testing directories; Commented implementation to avoid the use of mv -f --- tests/automate_notebook.py | 40 +++++++++++++------- tests/trace-extensionless-shortcut-V2.ipynb | 41 ++++++++++++++------- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/tests/automate_notebook.py b/tests/automate_notebook.py index 4356ccac..7067616c 100755 --- a/tests/automate_notebook.py +++ b/tests/automate_notebook.py @@ -26,7 +26,8 @@ # 2. It is advised to setup a password for the notebook, and provide the password through JUPYTER_PASSWORD environment variable # Usage Example (run from shell-scripts/tests/): -# zavee@pop-os:~/shell-scripts/tests$ JUPYTER_PASSWORD="password" python3 automate_ipynb --include hello-world-basic.ipynb +# ricekiller@pop-os:~/shell-scripts/tests$ JUPYTER_PASSWORD="password" python3 automate_ipynb --include hello-world-basic.ipynb + """ Automates Jupyter Notebook testing using Selenium Webdriver """ @@ -34,6 +35,7 @@ # Standard modules import time import random +import subprocess # Installed modules from selenium import webdriver @@ -63,6 +65,8 @@ NOBATSPP = "NOBATSPP" IPYNB_HELLO_WORLD_BASIC = "hello-world-basic.ipynb" COMMAND_RUN_JUPYTER = "jupyter nbclassic --no-browser" +COMMAND_IS_JUPYTER_RUNNING = "jupyter nbclassic list" +CURRENT_PATH = gh.real_path(".") debug.assertion(TESTFILE_URL.endswith("/")) ## Constant II (Elements for Selenium Webdriver) @@ -120,6 +124,22 @@ FORCE_SET_BASH_KERNEL = system.getenv_bool("FORCE_SET_BASH_KERNEL", False, description="Force sets Bash kernel when reruning each testfile (Default: False)") +## TODO: Force run Jupyter from the root "shell-scripts" directory +if FORCE_RUN_JUPYTER: + ## Check if Jupyter Notebook is running in the background + is_jupyter_running = gh.run(COMMAND_IS_JUPYTER_RUNNING) + jupyter_instances = is_jupyter_running.split("\n")[1:] + if len(jupyter_instances) > 0: + print("Jupyter is running") + else: + print("Jupyter is NOT running") + run_jupyter_path = gh.dirname(CURRENT_PATH) + try: + subprocess.run(COMMAND_RUN_JUPYTER, cwd=run_jupyter_path, shell=True) + except Exception as e: + print (f"Error: {e}") + ## CHECKPOINT ## + class AutomateNotebook: """Consists of functions for the automation of testfiles (.ipynb)""" @@ -136,11 +156,11 @@ def __init__( self.driver = webdriver.Firefox() if USE_FIREFOX else webdriver.Chrome() ## OLD: WebDriver object is not callable - def wrapup(self): - """Process end of input""" - if self.driver: - self.driver(quit) - self.driver = None + # def wrapup(self): + # """Process end of input""" + # if self.driver: + # self.driver(quit) + # self.driver = None def return_ipynb_url_array(self): """Returns a list of URLs of IPYNB test files based on filtering conditions.""" @@ -171,13 +191,12 @@ def return_ipynb_url_array(self): ipynb_urls = [TESTFILE_URL + file for file in ipynb_files_filtered] # Print the URLs for debugging - print(f"IPYNB files selected for automation (RANDOMIZE_TESTS:{RANDOMIZE_TESTS})\n") + print(f"IPYNB files selected for automation (RANDOMIZE_TESTS: {RANDOMIZE_TESTS})\n") for url in ipynb_urls: print(url) return ipynb_urls - def find_element(self, how, elem_id): """Finds ELEM_ID in DOM using HOW (e.g., By.ID)""" # ex: token_password_box = self.find_element(By.ID, ID_PASSWORD_INPUT) @@ -291,11 +310,6 @@ def automate_testfile(self, url_arr:str): def do_it(self): - ## TODO: Force run jupyter from root "shell-scripts" directory - if FORCE_RUN_JUPYTER: - time.sleep(1) - gh.run(COMMAND_RUN_JUPYTER) - filename = self.OPT_INCLUDE_TESTFILE ## OLD: test_files = [filename] if (filename != "-") else self.return_ipynb_url_array() if filename in [None, ""]: diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index a62dc672..eb49666b 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_FANKHNUDTDBZ\\[\\]>\n" + "PROMPT_OHHJKEHYUSXB\\[\\]>\n" ] } ], @@ -48,9 +48,12 @@ "# for f in $(typeset -f | egrep '^\\w+'); do unset -f $f; done\n", "# typeset -f | egrep '^\\w+' | wc -l\n", "\n", - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-extensionless\n", - "BIN_DIR=$PWD/.." + "## OLD: Using approach with rename-with-file-date\n", + "## Setting a temp directory for tests\n", + "# TMP=/tmp/test-extensionless\n", + "# BIN_DIR=$PWD/..\n", + "TMP=${TMP:-/tmp}\n", + "temp_dir=$TMP/trace-extensionless-shortcut-v2" ] }, { @@ -69,16 +72,28 @@ "execution_count": 5, "id": "ab954c7f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2' -> '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2.14Apr24.4'\n" + ] + } + ], "source": [ - "temp_dir=$TMP/test-3570\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# temp_dir=$TMP/test-3570\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", "## OLD \n", "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", + "\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"\n", "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -216,7 +231,7 @@ ], "source": [ "# BAD: rm -rf ./* > /dev/null\n", - "command mv -f * \"$trash_dir\"\n", + "# command mv -f * \"$trash_dir\"\n", "printf \"TOP\\nTHIS IS A TEST\\nBOTTOM\" > test.txt\n", "printf \"THIS IS A FILE TO MOVE\" > tomove.txt\n", "command mkdir newdir1\n", @@ -779,21 +794,21 @@ "cell_type": "code", "execution_count": 45, "id": "49d6d56d", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "mv: cannot move 'backup' to '/tmp/test-extensionless/_temp-trash-20240404182336/backup': Directory not empty\n", - "mv: cannot move 'newdir1' to '/tmp/test-extensionless/_temp-trash-20240404182336/newdir1': Directory not empty\n", "END\n" ] } ], "source": [ "# NOTE (PROPOSED APPROACH): Add timestamp to the directory before moving them to trash_dir\n", - "command mv -f * \"$trash_dir\"\n", + "# command mv -f * \"$trash_dir\"\n", "echo \"END\"" ] } From 0fc8a73b3f9a897958df0b5111405de0451fff76 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Tue, 16 Apr 2024 08:02:27 +0545 Subject: [PATCH 20/26] Rework with temp_dir to use rename-with-file-date [CELL_5]; Added tests for cd-real-dir [CELL_11]; Added testuserpath alias to replace /home/USER -> USER_PATH/ [CELL_4]; Added pwd with testuser to show the working of cd-like commands [C10-C12] --- tests/alias-cd-commands.ipynb | 110 ++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/tests/alias-cd-commands.ipynb b/tests/alias-cd-commands.ipynb index 37f6d41f..2a48f45c 100644 --- a/tests/alias-cd-commands.ipynb +++ b/tests/alias-cd-commands.ipynb @@ -23,7 +23,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_BLYGGVEKNCRG\\[\\]>\n" + "PROMPT_AXHVQRLAWUPC\\[\\]>\n" ] } ], @@ -60,7 +60,8 @@ "source": [ "# Global Setup\n", "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" \n", - "alias testuser=\"sed -r \"s/\"$USER\"+/user/g\"\"\n" + "alias testuser=\"sed -r \"s/\"$USER\"+/user/g\"\"\n", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n" ] }, { @@ -81,13 +82,19 @@ "# cd \"$temp_dir\"\n", "# pwd\n", "\n", - "TMP=/tmp/test-cp-mv\n", - "temp_dir=$TMP/test-6869\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# TMP=/tmp/test-cp-mv\n", + "# temp_dir=$TMP/test-6869\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p $temp_dir\n", + "# command mkdir -p $trash_dir\n", + "# command cd $temp_dir\n", "\n", - "command mkdir -p $temp_dir\n", - "command mkdir -p $trash_dir\n", - "command cd $temp_dir\n", + "TMP=${TMP:-/tmp}\n", + "temp_dir=$TMP/alias-cd-commands\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd \"$temp_dir\"\n", "\n", "## OLD\n", "# # ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", @@ -164,11 +171,23 @@ "execution_count": 10, "id": "069ed8cc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "USER_PATH/temp/tmp\n", + "USER_PATH/temp/tmp/alias-cd-commands\n" + ] + } + ], "source": [ "## chdir works as cd\n", "chdir .. > /dev/null\n", - "chdir test-6869/ > /dev/null" + "command pwd | testuserpath\n", + "## OLD: chdir \"test-6869\"/ > /dev/null\n", + "chdir \"$temp_dir\" > /dev/null\n", + "command pwd | testuserpath" ] }, { @@ -176,22 +195,57 @@ "execution_count": 11, "id": "36fb8fbd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "USER_PATH/temp/tmp\n", + "USER_PATH/temp/tmp/alias-cd-commands\n" + ] + } + ], "source": [ - "## cd-this-realdir works as cd as well\n", - "cd-this-realdir .. > /dev/null\n", - "cd-this-realdir test-6869/ > /dev/null" + "## cd-realdir - ditto for current directory\n", + "cd-realdir .. >/dev/null\n", + "command pwd | testuserpath\n", + "cd-realdir \"$temp_dir\" >/dev/null\n", + "command pwd | testuserpath" ] }, { "cell_type": "code", "execution_count": 12, + "id": "9cce96fc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "USER_PATH/temp/tmp/alias-cd-commands\n", + "USER_PATH/temp/tmp/alias-cd-commands\n" + ] + } + ], + "source": [ + "## cd-this-realdir is an alias for cd-realdir .\n", + "cd-this-realdir .. >/dev/null\n", + "## OLD: cd-this-realdir test-6869/\n", + "command pwd | testuserpath\n", + "cd-this-realdir \"$temp_dir\" >/dev/null\n", + "command pwd | testuserpath" + ] + }, + { + "cell_type": "code", + "execution_count": 13, "id": "4033a985", "metadata": {}, "outputs": [], "source": [ "## BAD: rm -rf ./* > /dev/null\n", - "command mv -f * $trash_dir\n", + "## BAD: command mv -f * $trash_dir\n", "# mkdir testdir89 testdir90\n", "command mkdir testdir89 testdir90\n", "echo \"Testfile1\" > testdir89/f11.txt\n", @@ -200,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "id": "e4b7b6fc", "metadata": {}, "outputs": [ @@ -222,9 +276,11 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "id": "14b95b96", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -240,6 +296,24 @@ "# ls\n", "command ls" ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e4b21b38", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], + "source": [ + "echo \"END\"" + ] } ], "metadata": { From 43d82292f8c0ee6b4f81e5622d034b688dee789b Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 17 Apr 2024 20:07:03 +0545 Subject: [PATCH 21/26] Rework with temp_dir to use rename-with-file-date; Added testuserpath to replace /home/USER -> USER_PATH/; Commented all instance of trash_dir and mv -f to trash_dir --- tests/alias-grep-commands.ipynb | 65 ++++++++++--- tests/alias-html-test.ipynb | 49 ++++------ tests/alias-trace-misc-commands.ipynb | 82 ++++++++-------- tests/command-override-cp-mv.ipynb | 118 ++++++++++++----------- tests/json-related-alias.ipynb | 72 ++++++++------ tests/trace-file-manipulation.ipynb | 44 ++++++--- tests/trace-line-words-commands.ipynb | 33 +++++-- tests/trace-setup-sorting-wrappers.ipynb | 20 ++-- tests/trace-unix-alias.ipynb | 34 ++++--- tests/trace-unix-general.ipynb | 58 ++++++++--- 10 files changed, 345 insertions(+), 230 deletions(-) diff --git a/tests/alias-grep-commands.ipynb b/tests/alias-grep-commands.ipynb index 86d5ff01..fcd118d3 100644 --- a/tests/alias-grep-commands.ipynb +++ b/tests/alias-grep-commands.ipynb @@ -73,6 +73,7 @@ "## Aliases for censoring username and/or numbers\n", "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" \n", "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n", "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, @@ -81,7 +82,15 @@ "execution_count": 5, "id": "482c3dcb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-grep-commands/alias-grep-commands' -> '/tmp/test-grep-commands/alias-grep-commands.16Apr24.9'\n" + ] + } + ], "source": [ "# Global setup\n", "\n", @@ -92,12 +101,17 @@ "TMP=${TMP:-/tmp}\n", "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-grep-commands; fi\n", "\n", - "temp_dir=$TMP/test-7371\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# temp_dir=$TMP/test-7371\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p $temp_dir\n", + "# command mkdir -p $trash_dir\n", + "# command cd $temp_dir\n", "\n", - "command mkdir -p $temp_dir\n", - "command mkdir -p $trash_dir\n", - "command cd $temp_dir" + "temp_dir=$TMP/alias-grep-commands\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd \"$temp_dir\"" ] }, { @@ -306,7 +320,7 @@ "metadata": {}, "outputs": [], "source": [ - "# # Halts test\n", + "## Halts test\n", "# show-line-context testgrep3" ] }, @@ -364,21 +378,24 @@ "cell_type": "code", "execution_count": 19, "id": "e51dcd01", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "-rw-rw-r-- N userxfNNN userxfNNN N N NN:NN ./ls-alR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN N NN:NN ./ls-alR.list.log\n", - "-rw-rw-r-- N userxfNNN userxfNNN N N NN:NN ./ls-aR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN N NN:NN ./ls-aR.list.log\n" + "-rw-r--r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list\n", + "-rw-r--r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-alR.list.log\n", + "-rw-r--r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list\n", + "-rw-r--r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-aR.list.log\n" ] } ], "source": [ - "prepare-find-files-here | testuser | testnum | awk '!($6=\"\")'" + "prepare-find-files-here | testuser | testnum | awk '!($6=\"\")'\n", + "# prepare-find-files-here | sed 's|\\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\([^ ]\\+\\) \\(.*\\)|\\1 \\6 \\7 \\8|'" ] }, { @@ -433,7 +450,27 @@ "# # $ make-file-listing\n", "# | cp: cannot stat 'ls-aR.list': No such file or directory\n", "# | chmod: cannot access './backup/ls-aR.list': No such file or directory\n", - "command mv -f * $trash_dir" + "## BAD: command mv -f * $trash_dir" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "dc3f2836", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], + "source": [ + "echo \"END\"" ] } ], diff --git a/tests/alias-html-test.ipynb b/tests/alias-html-test.ipynb index 26006473..e0e17097 100644 --- a/tests/alias-html-test.ipynb +++ b/tests/alias-html-test.ipynb @@ -56,60 +56,53 @@ "source": [ "# Global Setup\n", "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", - "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" " + "alias testnum=\"sed -r \"s/[0-9]/N/g\"\" \n", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "442\n" - ] - } - ], + "outputs": [], "source": [ - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-admin-commands\n", + "## OLD: Use of unique temp_dir\n", + "## Setting a temp directory for tests\n", + "# TMP=/tmp/test-admin-commands\n", "\n", - "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/..\n", + "# ## NOTE: Source it directly from the ./tests directory.\n", + "# BIN_DIR=$PWD/..\n", "\n", - "alias | wc -l" + "# alias | wc -l" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/tmp/test-admin-commands/test-5400\n" - ] - } - ], + "outputs": [], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 3245)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", + "## OLD: \n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-5400\n", + "# temp_dir=$TMP/test-5400\n", + "# command mkdir -p \"$temp_dir\"\n", + "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", + "# command pwd\n", "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-grep-commands; fi\n", + "temp_dir=$TMP/alias-html-test\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", - "command pwd\n", "\n", "## OLD\n", - "# #ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", + "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" ] }, diff --git a/tests/alias-trace-misc-commands.ipynb b/tests/alias-trace-misc-commands.ipynb index 80c7aa11..5f389cac 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -56,6 +56,7 @@ "alias testnum=\"sed -r \"s/[0-9]/N/g\"\"\n", "alias testnumhex=\"sed -r \"s/[0-9][A-F][a-F]/N/g\"\"\n", "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n", "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, @@ -64,15 +65,7 @@ "execution_count": 5, "id": "ce58f3f6-2f78-4bff-a96a-23e4f1983d94", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "renamed '/tmp/test-trace-misc/test-1001' -> '/tmp/test-trace-misc/test-1001.14Feb24.17'\n" - ] - } - ], + "outputs": [], "source": [ "# Global setup\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", @@ -82,12 +75,16 @@ "TMP=${TMP:-/tmp}\n", "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-misc; fi\n", "\n", - "temp_dir=$TMP/test-1001\n", - "rename-with-file-date \"$temp_dir\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# temp_dir=$TMP/test-1001\n", + "# rename-with-file-date \"$temp_dir\"\n", + "# mkdir -p $temp_dir\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p $trash_dir\n", "\n", - "mkdir -p $temp_dir\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "command mkdir -p $trash_dir\n", + "temp_dir=$TMP/alias-trace-misc\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", "command cd $temp_dir" ] }, @@ -539,7 +536,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/test-trace-misc/test-1001\n" + "/tmp/test-trace-misc/alias-trace-misc\n" ] } ], @@ -575,10 +572,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "11c11\n", - "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", + "15c15\n", + "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", "---\n", - "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" + "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" ] } ], @@ -599,10 +596,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "11c11\n", - "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", + "15c15\n", + "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", "---\n", - "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" + "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" ] } ], @@ -622,10 +619,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "11c11\n", - "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", + "15c15\n", + "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", "---\n", - "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n" + "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" ] } ], @@ -644,17 +641,16 @@ "name": "stdout", "output_type": "stream", "text": [ + "------------------------------------------------------------------------\n", "process1.txt vs. process2.txt\n", "Differences: process1.txt process2.txt\n", - "-rw-rw-r-- 1 userxf333 userxf333 877 Feb 14 20:59 process1.txt\n", - "-rw-rw-r-- 1 userxf333 userxf333 877 Feb 14 20:59 process2.txt\n", - "18% differences for process1.txt\n", - "11c11\n", - "< userxf333 63033 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", + "-rw-r--r-- 1 userxf333 zavee 1201 Apr 16 08:34 process1.txt\n", + "-rw-r--r-- 1 userxf333 zavee 1201 Apr 16 08:34 process2.txt\n", + "13% differences for process1.txt\n", + "15c15\n", + "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", "---\n", - "> userxf333 63034 0.0 0.0 22512 3328 pts/2 RN+ 20:59 0:00 ps -u\n", - "------------------------------------------------------------------------\n", - "\n" + "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" ] } ], @@ -691,10 +687,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-alR.list.log\n", - "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list\n", - "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-aR.list.log\n" + "-rw-r--r-- N userxfNNN zavee N NN NN:NN ./ls-alR.list\n", + "-rw-r--r-- N userxfNNN zavee NN NN NN:NN ./ls-alR.list.log\n", + "-rw-r--r-- N userxfNNN zavee N NN NN:NN ./ls-aR.list\n", + "-rw-r--r-- N userxfNNN zavee NN NN NN:NN ./ls-aR.list.log\n" ] } ], @@ -868,7 +864,7 @@ "## # NEW (Remove temp after use)\n", "## rm -rf $temp_dir > /dev/null\n", "\n", - "command mv -f * $trash_dir \n" + "## OLD & BAD: command mv -f * $trash_dir \n" ] }, { @@ -876,10 +872,18 @@ "execution_count": 43, "id": "60a12cb0-8269-4498-b05c-5bd358da8245", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done\n" + ] + } + ], "source": [ "## DEBUG:\n", - "## echo \"Done\"" + "echo \"Done\"" ] } ], diff --git a/tests/command-override-cp-mv.ipynb b/tests/command-override-cp-mv.ipynb index 50f6d9d3..3a0bb330 100644 --- a/tests/command-override-cp-mv.ipynb +++ b/tests/command-override-cp-mv.ipynb @@ -71,17 +71,27 @@ "execution_count": 4, "id": "1f0c6191", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/trace-python-commands/trace-python-commands' -> '/tmp/trace-python-commands/trace-python-commands.16Apr24.3'\n" + ] + } + ], "source": [ "# Global Setup\n", "\n", + "TMP=${TMP:-/tmp}\n", "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", " TMP=/tmp/trace-python-commands\n", "fi\n", - "temp_dir=$TMP/test-7766\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "temp_dir=$TMP/trace-python-commands\n", + "## OLD: No use of trash: trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"" ] }, @@ -95,6 +105,7 @@ "# Global Setup\n", "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"\n", "alias testnum=\"sed -r \"s/[0-9]/N/g\"\"\n", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n", "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, @@ -253,7 +264,7 @@ "output_type": "stream", "text": [ "total N \n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" ] } ], @@ -273,9 +284,9 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n" ] } ], @@ -331,7 +342,7 @@ "source": [ "# BAD: rm -rf ./* > /dev/null\n", "ls\n", - "command mv -f * \"$trash_dir\"" + "## OLD: command mv -f * \"$trash_dir\"" ] }, { @@ -381,10 +392,11 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" ] } ], @@ -404,9 +416,9 @@ "output_type": "stream", "text": [ "total N \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n" ] } ], @@ -492,14 +504,15 @@ "output_type": "stream", "text": [ "total NN \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -521,14 +534,15 @@ "output_type": "stream", "text": [ "total NN \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -637,14 +651,15 @@ "output_type": "stream", "text": [ "total NN \n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN abc\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN def\n", - "-rw-rw-r-- N userxf333 userxf333 N NN NN:NN ghi\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", - "drwxrwsr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN abc\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN cptest_dirN\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN def\n", + "-rw-r--r-- N userxf333 userxf333 N NN NN:NN ghi\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n", + "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN TDIRN\n" ] } ], @@ -658,22 +673,15 @@ "execution_count": 32, "id": "5d4aef31", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully moved to trash\n" - ] - } - ], + "outputs": [], "source": [ - "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", - " command mv -f * \"$trash_dir\"\n", - " echo \"Successfully moved to trash\"\n", - "else\n", - " echo \"Warning: Current directory not in TMP\"\n", - "fi" + "## OLD: No use of trash_dir\n", + "# if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + "# command mv -f * \"$trash_dir\"\n", + "# echo \"Successfully moved to trash\"\n", + "# else\n", + "# echo \"Warning: Current directory not in TMP\"\n", + "# fi" ] } ], diff --git a/tests/json-related-alias.ipynb b/tests/json-related-alias.ipynb index 22956dfc..5d082b15 100644 --- a/tests/json-related-alias.ipynb +++ b/tests/json-related-alias.ipynb @@ -114,22 +114,36 @@ "execution_count": 7, "id": "87325c19", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-json-alias/json-related-alias' -> '/tmp/test-json-alias/json-related-alias.16Apr24'\n" + ] + } + ], "source": [ "# Global setup\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 1210)\n", "## *** All output from one run to the next needs to be the same ***\n", "# Setting a temp directory for tests\n", - "TMP=/tmp/test-json-alias\n", + "\n", + "## OLD: TMP=/tmp/test-json-alias\n", "\n", "## OLD:0\n", "## NOTE: Source it directly from the ./tests directory.\n", "## BIN_DIR=$PWD/..\n", "\n", - "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-3214\n", "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-json-alias; fi\n", + "## temp_dir=$TMP/test-$$\n", + "temp_dir=$TMP/json-related-alias\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd \"$temp_dir\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", @@ -145,22 +159,15 @@ "execution_count": 8, "id": "9a135b2b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/tmp/test-json-alias/test-3214\n" - ] - } - ], + "outputs": [], "source": [ "## Moved contents from Global Setup that creates output (leads to Assertion failed)\n", "\n", - "mkdir -p \"$temp_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", - "command pwd\n" + "## OLD: Moved all contents to above cell\n", + "# mkdir -p \"$temp_dir\"\n", + "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", + "# command pwd\n" ] }, { @@ -470,7 +477,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "intersection.perl: command not found\n" + "This\n", + "is\n", + "Line\n", + "1\n", + "3\n", + "5\n" ] } ], @@ -489,7 +501,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], @@ -508,7 +520,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "intersection.perl: command not found\n" + "7\n", + "9\n", + "B.\n" ] } ], @@ -529,7 +543,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], @@ -548,7 +562,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "intersection.perl: command not found\n" + "1 3 5 7 9\n", + "This is Line B.\n" ] } ], @@ -567,7 +582,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], @@ -586,7 +601,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "hexview.perl: command not found\n", + "00000000 48 69 20 4D 6F 6D 2C 20 - 0D 49 20 61 6D 20 75 73 Hi Mom, .I am us\n", + "00000010 69 6E 67 20 55 62 75 6E - 74 75 0A ing Ubuntu.\n", " 1 6 27 _ubuntu-with-cr.out_\n" ] } @@ -628,7 +644,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "hexview.perl: command not found\n", + "00000000 48 69 20 4D 6F 6D 2C 20 - 49 20 61 6D 20 75 73 69 Hi Mom, I am usi\n", + "00000010 6E 67 20 55 62 75 6E 74 - 75 0A ng Ubuntu.\n", " 1 6 26 _ubuntu-without-cr.out_\n" ] } @@ -670,7 +687,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "hexview.perl: command not found\n", + "00000000 48 69 20 4D 6F 6D 2C 20 - 49 20 61 6D 20 75 73 69 Hi Mom, I am usi\n", + "00000010 6E 67 20 55 62 75 6E 74 - 75 0A ng Ubuntu.\n", " 1 6 26 _alt-remove-cr.out_\n" ] } @@ -760,7 +778,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/test-json-alias/test-3214\n" + "/tmp/test-json-alias/json-related-alias\n" ] } ], diff --git a/tests/trace-file-manipulation.ipynb b/tests/trace-file-manipulation.ipynb index d33ed5e9..e28ff017 100644 --- a/tests/trace-file-manipulation.ipynb +++ b/tests/trace-file-manipulation.ipynb @@ -27,7 +27,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_TDITLAHWPHUL\\[\\]>\n" + "PROMPT_TUIGPLAHUZJT\\[\\]>\n" ] } ], @@ -78,11 +78,13 @@ "metadata": {}, "outputs": [], "source": [ - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-file-manipulation\n", + "## Setting a temp directory for tests\n", + "## OLD: Reworked with temp-dir\n", + "# TMP=/tmp/test-file-manipulation\n", "\n", "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/..\n", + "## OLD\n", + "# BIN_DIR=$PWD/..\n", "\n", "## OLD\n", "# alias | wc -l" @@ -93,25 +95,41 @@ "execution_count": 6, "id": "ab954c7f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-trace-file/trace-file-manipulation' -> '/tmp/test-trace-file/trace-file-manipulation.16Apr24'\n" + ] + } + ], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 9890)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-9890\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", "\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# temp_dir=$TMP/test-9890\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p \"$temp_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", + "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-file; fi\n", + "temp_dir=$TMP/trace-file-manipulation\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", + "command cd $temp_dir\n", "\n", "## OLD:\n", "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", @@ -628,9 +646,9 @@ "metadata": {}, "outputs": [], "source": [ - "# CLEARS THE TEST FOLDER\n", - "# Bad: rm -rf ./* > /dev/null\n", - "command mv -f * \"$trash_dir\"" + "## CLEARS THE TEST FOLDER\n", + "## Bad: rm -rf ./* > /dev/null\n", + "## Bad 2: command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-line-words-commands.ipynb b/tests/trace-line-words-commands.ipynb index 968d6830..0edcac5a 100644 --- a/tests/trace-line-words-commands.ipynb +++ b/tests/trace-line-words-commands.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_LZVBUZWMGJED\\[\\]>\n" + "PROMPT_MOMQYZNZZMVP\\[\\]>\n" ] } ], @@ -62,10 +62,10 @@ "outputs": [], "source": [ "# Setting a temp directory for tests\n", - "TMP=/tmp/test-linewords\n", + "## OLD: TMP=/tmp/test-linewords\n", "\n", "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/.." + "## OLD: BIN_DIR=$PWD/.." ] }, { @@ -73,19 +73,34 @@ "execution_count": 5, "id": "ab954c7f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-trace-line-words/trace-line-words-commands' -> '/tmp/test-trace-line-words/trace-line-words-commands.16Apr24'\n" + ] + } + ], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 6439)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-6439\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# temp_dir=$TMP/test-6439\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "# command mkdir -p \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", "\n", - "command mkdir -p \"$trash_dir\"\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-line-words; fi\n", + "temp_dir=$TMP/trace-line-words-commands\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", + "command cd $temp_dir\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -363,7 +378,7 @@ "source": [ "## OLD & BAD\n", "# rm -rf ./* > /dev/null\n", - "command mv -f * \"$trash_dir\"\n", + "# command mv -f * \"$trash_dir\"\n", "echo \"Done\"" ] } diff --git a/tests/trace-setup-sorting-wrappers.ipynb b/tests/trace-setup-sorting-wrappers.ipynb index 1c54df1f..8fa3b8e1 100644 --- a/tests/trace-setup-sorting-wrappers.ipynb +++ b/tests/trace-setup-sorting-wrappers.ipynb @@ -10,7 +10,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_VUQPAXZFXUQO\\[\\]>\n" + "PROMPT_DKQQARMRPJAU\\[\\]>\n" ] } ], @@ -47,10 +47,10 @@ "outputs": [], "source": [ "# Setting a temp directory for tests\n", - "TMP=/tmp/test-setupsort\n", + "# TMP=/tmp/test-setupsort\n", "\n", "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/..\n", + "## OLD: BIN_DIR=$PWD/..\n", "\n", "## OLD\n", "# alias | wc -l | test" @@ -76,22 +76,16 @@ "execution_count": 5, "id": "ab954c7f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "renamed '/tmp/test-setupsort/test-6411' -> '/tmp/test-setupsort/test-6411.13Oct23.3'\n" - ] - } - ], + "outputs": [], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 6411)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-6411\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-setup-sorting-wrappers; fi\n", + "temp_dir=$TMP/trace-setup-sorting-wrappers\n", "rename-with-file-date \"$temp_dir\"\n", "\n", "## OLD\n", diff --git a/tests/trace-unix-alias.ipynb b/tests/trace-unix-alias.ipynb index a85744ff..5628df6a 100644 --- a/tests/trace-unix-alias.ipynb +++ b/tests/trace-unix-alias.ipynb @@ -76,12 +76,12 @@ "# Global Setup\n", "TMP=${TMP:-/tmp}\n", "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", - " TMP=/tmp/trace-unix-commands\n", + " TMP=/tmp/trace-unix-alias\n", "fi\n", - "temp_dir=$TMP/test-7766\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "temp_dir=$TMP/test-unix-alias\n", + "## OLD: trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", + "## OLD: command mkdir -p \"$trash_dir\"\n", "command cd \"$temp_dir\"" ] }, @@ -329,7 +329,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "1\n" ] } ], @@ -696,10 +696,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Fri Feb N N:N:N PM +N N\n", + "start: Tue Apr N N:N:N PM +N N\n", "+ eval ''\n", "+ set - -o xtrace\n", - "end: Fri Feb N N:N:N PM +N N\n" + "end: Tue Apr N N:N:N PM +N N\n" ] } ], @@ -726,10 +726,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Fri Feb N N:N:N PM +N N\n", + "start: Tue Apr N N:N:N PM +N N\n", "+ eval ''\n", "+ set - -o xtrace\n", - "end: Fri Feb N N:N:N PM +N N\n" + "end: Tue Apr N N:N:N PM +N N\n" ] } ], @@ -919,17 +919,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "Successfully moved to trash\n" + "Done\n" ] } ], "source": [ - "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", - " command mv -f * \"$trash_dir\"\n", - " echo \"Successfully moved to trash\"\n", - "else\n", - " echo \"Warning: Current directory not in TMP\"\n", - "fi" + "## OLD: No use of trash_dir\n", + "# if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + "# command mv -f * \"$trash_dir\"\n", + "# echo \"Successfully moved to trash\"\n", + "# else\n", + "# echo \"Warning: Current directory not in TMP\"\n", + "# fi\n", + "echo \"Done\"" ] } ], diff --git a/tests/trace-unix-general.ipynb b/tests/trace-unix-general.ipynb index 7ad225e6..e755b148 100644 --- a/tests/trace-unix-general.ipynb +++ b/tests/trace-unix-general.ipynb @@ -37,7 +37,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_WBFDTPJVNJFD\\[\\]>\n" + "PROMPT_YMJHFZGOKIZS\\[\\]>\n" ] } ], @@ -87,16 +87,29 @@ "execution_count": 6, "id": "ab954c7f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-trace-line-words/trace-line-words-commands' -> '/tmp/test-trace-line-words/trace-line-words-commands.16Apr24.4'\n" + ] + } + ], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 3245)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", + "## OLD: Dropped the use of trash-dirs\n", "## temp_dir=$TMP/test-$$\n", - "TMP=/tmp/test-unix\n", - "temp_dir=$TMP/test-3245\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# TMP=/tmp/test-unix\n", + "# temp_dir=$TMP/test-3245\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-line-words; fi\n", + "temp_dir=$TMP/trace-line-words-commands\n", "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", @@ -104,9 +117,10 @@ "# cd \"$temp_dir\"\n", "# pwd\n", "\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "## TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", "\n", "## OLD\n", @@ -203,7 +217,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "(standard_in) 1: syntax error\n", + "bash: [: -eq: unary operator expected\n", + "2\n" ] } ], @@ -233,7 +249,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "(standard_in) 1: syntax error\n", + "bash: [: -eq: unary operator expected\n", + "2\n" ] } ], @@ -262,7 +280,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "(standard_in) 1: syntax error\n", + "bash: [: -eq: unary operator expected\n", + "2\n" ] } ], @@ -291,7 +311,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "(standard_in) 1: syntax error\n", + "bash: [: -eq: unary operator expected\n", + "2\n" ] } ], @@ -301,10 +323,14 @@ "# ps-mem | testnum | awk '!($1=$7=$8=$11=\"\")' | tail -n 5 \n", "\n", "ps-mem > ps_mem_alt.out 2>/dev/null\n", - "cat ps_mem.out | head -n 2 | tail -n 1 | awk '{print $3}' > outma1.txt\n", - "cat ps_mem.out | head -n 3 | tail -n 1 | awk '{print $3}' > outma2.txt\n", - "VAL1=$(cat outma1.txt)\n", - "VAL2=$(cat outma2.txt)\n", + "\n", + "## OLD: syntax error \n", + "# cat ps_mem.out | head -n 2 | tail -n 1 | awk '{print $3}' > outma1.txt\n", + "# cat ps_mem.out | head -n 3 | tail -n 1 | awk '{print $3}' > outma2.txt\n", + "# VAL1=$(cat outma1.txt)\n", + "# VAL2=$(cat outma2.txt)\n", + "VAL1=$(awk 'NR==2 {print $3}' ps_mem_alt.out)\n", + "VAL2=$(awk 'NR==3 {print $3}' ps_mem_alt.out)\n", "\n", "# Compares %MEM for first two processes\n", "[ $(echo \"$VAL1 >= $VAL2\" | bc -l) -eq 1 ]; echo $?;" @@ -448,7 +474,7 @@ } ], "source": [ - "command mv -f * \"$trash_dir\"\n", + "## OLD: command mv -f * \"$trash_dir\"\n", "echo \"Done\"" ] } From d0aea27cf3049343abea0d7546cc946d37d486e1 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 17 Apr 2024 20:07:38 +0545 Subject: [PATCH 22/26] Added testuser alias in Global Setup (trace-setup-sorting-wrappers); Rework with temp_dir to use rename-with-file-date; Commented ln-symbolic command as the link with same name exists (For demonstration) --- tests/dir-aliases-test-revised.ipynb | 57 ++++++++----------- tests/test-check-errors.ipynb | 40 +++++++++---- tests/test-cond-env-setting.ipynb | 43 +++++++++----- tests/test-tomohara-aliases-access.ipynb | 22 +++++-- tests/trace-extensionless-shortcut-V2.ipynb | 4 +- ...trace-extensionless-shortcut-unicode.ipynb | 27 ++++++--- 6 files changed, 117 insertions(+), 76 deletions(-) diff --git a/tests/dir-aliases-test-revised.ipynb b/tests/dir-aliases-test-revised.ipynb index 3b816e7e..20062093 100644 --- a/tests/dir-aliases-test-revised.ipynb +++ b/tests/dir-aliases-test-revised.ipynb @@ -256,7 +256,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "1\n" ] } ], @@ -281,13 +281,17 @@ "#\n", "# Test safe symbolic links\n", "## temp_dir=$TMP/test-$$\n", - "temp_dir=\"$TMP/test-7919\"\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-grep-commands; fi\n", + "\n", + "## OLD: temp_dir=$TMP/test-7919\n", + "temp_dir=$TMP/dir-aliases-test-revised\n", "#\n", "# Move existing file out of way\n", "rename-with-file-date \"$temp_dir\" > /dev/null\n", "#\n", "# Create dir and make current\n", - "mkdir -p \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "## BAD:\n", "## cd \"$temp_dir\"\n", @@ -329,20 +333,7 @@ "execution_count": 21, "id": "a82827b2", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "link-symbolic\n", - "link-symbolic-force\n", - "link-symbolic-regular\n", - "link-symbolic-safe\n", - "ln-symbolic\n", - "ln-symbolic-force\n" - ] - } - ], + "outputs": [], "source": [ "## DEBUG\n", "show-macros-proper | grep symbolic | extract_matches.perl \"alias ([^=]+)=\" | sort -u" @@ -558,33 +549,33 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 33, "id": "b0bc416c", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "## HALT (TBF)\n", "# ln-symbolic SHOULD GENERATE AN ERROR AS PREVIOUS LINK WITH SAME NAME EXISTS\n", "# ln: failed to create symbolic link 'temp-link': File exist\n", "## BAD: ln-symbolic /tmp temp-link\n", - "##\n", - "ln-symbolic /tmp temp-link 2>&1 | grep -c exists" + "\n", + "## OLD (Halts test): ln-symbolic /tmp temp-link 2>1 | grep -c exists" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "id": "40e0e1ae-a8aa-4ae1-9073-d1dfa52266ef", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'temp-link/tmp' -> '/tmp'\n" + ] + } + ], "source": [ "# ln-symbolic-force SHOULD BYPASS THE CONDITION\n", "# ln: failed to create symbolic link 'temp-link': File exist\n", @@ -644,7 +635,7 @@ "output_type": "stream", "text": [ "total\n", - "-rw-rw-r-- file1\n", + "-rw-r--r-- file1\n", "lrwxrwxrwx link1 -> file1\n", "lrwxrwxrwx temp-link -> /tmp\n", "lrwxrwxrwx temp-link-safe -> /tmp/tmp\n" @@ -668,8 +659,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "temp-link-safe\n", "temp-link\n", + "temp-link-safe\n", "link1\n" ] } diff --git a/tests/test-check-errors.ipynb b/tests/test-check-errors.ipynb index c8d7f0a9..fd9cea7b 100644 --- a/tests/test-check-errors.ipynb +++ b/tests/test-check-errors.ipynb @@ -27,7 +27,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_NSGMXBMINMVZ\\[\\]>\n" + "PROMPT_JNIQNAOQMMFT\\[\\]>\n" ] } ], @@ -62,8 +62,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Setting a temp directory for tests\n", - "TMP=/tmp/test-check-errors\n", + "## OLD: Contents moved to cell below\n", + "## Setting a temp directory for tests\n", + "# TMP=/tmp/test-check-errors\n", "\n", "## NOTE: Source it directly from the ./tests directory.\n", "BIN_DIR=$PWD/.." @@ -83,14 +84,20 @@ "# cd \"$temp_dir\"\n", "# pwd\n", "\n", - "temp_dir=$TMP/test-2334\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp_dirs\n", + "# temp_dir=$TMP/test-2334\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p \"$temp_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-check-errors; fi\n", + "temp_dir=$TMP/test-check-errors\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", - "\n", "## OLD: Debug\n", "# command pwd\n", "\n", @@ -125,7 +132,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/test-check-errors/test-2334\n" + "/tmp/test-check-errors/test-check-errors\n" ] } ], @@ -168,7 +175,7 @@ "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", - "Requirement already satisfied: mezcla in /home/aveey/.local/lib/python3.10/site-packages (1.3.9.6)\n" + "Requirement already satisfied: mezcla in /home/zavee/.local/lib/python3.10/site-packages (1.3.9.9)\n" ] } ], @@ -385,10 +392,19 @@ "execution_count": 21, "id": "f8a387ac", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], "source": [ "# BAD: /bin/rm -rf $temp_dir > /dev/null\n", - "command mv -f * \"$trash_dir\"" + "## OLD: command mv -f * \"$trash_dir\"\n", + "echo \"END\"" ] } ], diff --git a/tests/test-cond-env-setting.ipynb b/tests/test-cond-env-setting.ipynb index 58340447..414254e2 100644 --- a/tests/test-cond-env-setting.ipynb +++ b/tests/test-cond-env-setting.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_OCDYSMBBXUCA\\[\\]>\n" + "PROMPT_EGMOSAEFKOZZ\\[\\]>\n" ] } ], @@ -75,7 +75,7 @@ "outputs": [], "source": [ "# Setting a temp directory for tests\n", - "TMP=/tmp/test-cond-env\n", + "## OLD: TMP=/tmp/test-cond-env\n", "\n", "# OLD\n", "# ## NOTE: Source it directly from the ./tests directory.\n", @@ -91,24 +91,39 @@ "execution_count": 6, "id": "be943c71", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-cond-env-setting/cond-env-settings' -> '/tmp/test-cond-env-setting/cond-env-settings.16Apr24'\n" + ] + } + ], "source": [ "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 1710)\n", "## *** All output from one run to the next needs to be the same ***\n", "\n", - "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-1710\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", + "# # temp_dir=$TMP/test-$$\n", + "# temp_dir=$TMP/test-1710\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# ## OLD\n", + "# # mkdir -p \"$temp_dir\"\n", + "# # # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# # cd \"$temp_dir\"\n", + "# command mkdir -p \"$temp_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "# # # TODO: /bin/rm -rvf \"$temp_dir\"\n", + "# command cd \"$temp_dir\"\n", + "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-cond-env-setting; fi\n", "\n", + "temp_dir=$TMP/cond-env-settings\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", + "command cd $temp_dir\n", "\n", "## OLD: For debugging\n", "# pwd\n", @@ -269,7 +284,7 @@ } ], "source": [ - "command mv -f * \"$trash_dir\"\n", + "## OLD: No use og trash_dir: command mv -f * \"$trash_dir\"\n", "echo \"Done!\"" ] } diff --git a/tests/test-tomohara-aliases-access.ipynb b/tests/test-tomohara-aliases-access.ipynb index e86f217f..a0a52987 100644 --- a/tests/test-tomohara-aliases-access.ipynb +++ b/tests/test-tomohara-aliases-access.ipynb @@ -13,16 +13,26 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/tomasohara-shell-scripts' -> '/tmp/tomasohara-shell-scripts.16Apr24'\n" + ] + } + ], "source": [ "# Set directory for alias work\n", "export TEMP_TOM_BIN=/tmp/tomasohara-shell-scripts\n", "export TOM_ALIAS_FILE=\"$TEMP_TOM_BIN/tomohara-aliases.bash\"\n", "# mkdir -p \"$TEMP_TOM_BIN\"\n", - "## OLD\n", - "export trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "\n", + "## OLD: Dropped the use of trash_dir\n", + "# export trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "rename-with-file-date \"$TEMP_TOM_BIN\"\n", "command mkdir -p \"$TEMP_TOM_BIN\"\n", - "command mkdir -p \"$trash_dir\"\n", "command cd \"$TEMP_TOM_BIN\"" ] }, @@ -37,7 +47,7 @@ "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", - "100 146k 100 146k 0 0 363k 0 --:--:-- --:--:-- --:--:-- 363k\n" + "100 144k 100 144k 0 0 366k 0 --:--:-- --:--:-- --:--:-- 366k\n" ] } ], @@ -103,7 +113,7 @@ "## OLD\n", "# rm -rf \"$TEMP_TOM_BIN\"\n", "# BAD: rm -rf \"$TEMP_TOM_BIN\" > /dev/null\n", - "command mv -f * \"$trash_dir\"" + "# BAD TOO: command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index eb49666b..979a2ae7 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_OHHJKEHYUSXB\\[\\]>\n" + "PROMPT_OVLPJNQIIUQT\\[\\]>\n" ] } ], @@ -77,7 +77,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "renamed '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2' -> '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2.14Apr24.4'\n" + "renamed '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2' -> '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2.14Apr24.6'\n" ] } ], diff --git a/tests/trace-extensionless-shortcut-unicode.ipynb b/tests/trace-extensionless-shortcut-unicode.ipynb index 1874467d..5340a9fd 100644 --- a/tests/trace-extensionless-shortcut-unicode.ipynb +++ b/tests/trace-extensionless-shortcut-unicode.ipynb @@ -34,8 +34,8 @@ "# typeset -f | egrep '^\\w+' | wc -l\n", "# Setting a temp directory for tests\n", "\n", - "TMP=/tmp/test-extensionless\n", "## OLD\n", + "# TMP=/tmp/test-extensionless\n", "# BIN_DIR=$PWD/.." ] }, @@ -54,7 +54,8 @@ } ], "source": [ - "alias | wc -l" + "## OLD: For debuging\n", + "# alias | wc -l" ] }, { @@ -64,17 +65,25 @@ "metadata": {}, "outputs": [], "source": [ - "temp_dir=$TMP/test-3570\n", + "\n", "## OLD\n", "# mkdir -p \"$temp_dir\"\n", "# cd \"$temp_dir\"\n", "# pwd\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", "\n", - "command mkdir -p \"$temp_dir\"\n", - "command mkdir -p \"$trash_dir\"\n", - "command cd \"$temp_dir\"\n", + "## OLD: Used the concept of trash-dir, instead use unique temp-dirs\n", + "# temp_dir=$TMP/test-3570\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# command mkdir -p \"$temp_dir\"\n", + "# command mkdir -p \"$trash_dir\"\n", + "# command cd \"$temp_dir\"\n", "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/trace-extensionless-shortcut-unicode; fi\n", + "temp_dir=$TMP/extensionless-shortcut-unicode\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd $temp_dir\n", "## OLD\n", "# #ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -150,7 +159,7 @@ "# pwd\n", "# rm -rf ./*\n", "## BAD: rm -rf ./* > /dev/null\n", - "command mv -f * \"$trash_dir\"\n", + "## BAD TOO: command mv -f * \"$trash_dir\"\n", "uname -r > version1.txt" ] }, @@ -329,7 +338,7 @@ ], "source": [ "echo \"END\"\n", - "command mv -f * \"$trash_dir\"" + "## OLD: command mv -f * \"$trash_dir\"" ] } ], From 6ed3548125e3280b2a1307bd0c6018b856119fd1 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Wed, 17 Apr 2024 20:12:52 +0545 Subject: [PATCH 23/26] Modified the setup of temp_dir and removed instance of trash_dir; Commented mv -f to trash_dir at the end of test --- tests/more-tomohara-aliases-test.ipynb | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/more-tomohara-aliases-test.ipynb b/tests/more-tomohara-aliases-test.ipynb index 5feee8a5..0499b6db 100644 --- a/tests/more-tomohara-aliases-test.ipynb +++ b/tests/more-tomohara-aliases-test.ipynb @@ -18,7 +18,8 @@ "# Global Setup\n", "## TEST: cd /usr/local/misc/programs/bash/shell-scripts-aviyan/tests\n", "## For number of digits not being critical\n", - "alias testnum=\"sed -r \"s/[0-9][0-9]*/N/g\"\"" + "alias testnum=\"sed -r \"s/[0-9][0-9]*/N/g\"\"\n", + "alias testuser=\"sed -r \"s/\"$USER\"+/userxf333/g\"\"" ] }, { @@ -47,11 +48,21 @@ "# Setup temp. dir\n", "# note: variable not used in rm as a precaution\n", "# BAD: /bin/rm -rf \"/tmp/test-dir-15485863\"\n", - "test_dir=\"/tmp/test-dir-15485863\"\n", - "trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", - "mkdir -p \"$test_dir\"\n", - "mkdir -p \"$trash_dir\"\n", - "command cd \"$test_dir\"" + "\n", + "## OLD: Used the concept of trash-dir\n", + "# test_dir=\"/tmp/test-dir-15485863\"\n", + "# trash_dir=$TMP/\"_temp-trash-$(date \"+%Y%m%d%H%M%S\")\"\n", + "# mkdir -p \"$test_dir\"\n", + "# mkdir -p \"$trash_dir\"\n", + "# command cd \"$test_dir\"\n", + "\n", + "\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-more-tomohara-aliases; fi\n", + "temp_dir=$TMP/more-tomohara-aliases-test\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd \"$temp_dir\"" ] }, { @@ -179,7 +190,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "-rw-rw-r-- N username N mon hh:mm mno\n" + "-rw-rw-r-- N username er N mon hh:mm mno\n" ] } ], @@ -191,10 +202,19 @@ "cell_type": "code", "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], "source": [ "# Remove everything after use\n", - "command mv -f * \"$trash_dir\"" + "## OLD: command mv -f * \"$trash_dir\"\n", + "echo \"END\"" ] } ], From d6c55d72382b8dbcf9f7c23dfa68087cc99592cc Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Tue, 23 Apr 2024 19:54:08 +0545 Subject: [PATCH 24/26] Uncommented the cell for testing hist alias; Updated the regex for pattern matching of timestamps (Cell 9); Redefined the test for perlgrep command using 'conditional-echo' (Cell 23) --- tests/alias-trace-misc-commands.ipynb | 62 +++++++++++++++++---------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/tests/alias-trace-misc-commands.ipynb b/tests/alias-trace-misc-commands.ipynb index 5f389cac..a358341c 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -65,7 +65,15 @@ "execution_count": 5, "id": "ce58f3f6-2f78-4bff-a96a-23e4f1983d94", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed '/tmp/test-trace-misc/alias-trace-misc' -> '/tmp/test-trace-misc/alias-trace-misc.22Apr24.5'\n" + ] + } + ], "source": [ "# Global setup\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", @@ -128,7 +136,15 @@ "execution_count": 9, "id": "e149fbc9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], "source": [ "##1 SHOWS HISTORY OF BASH COMMANDS\n", "## BAD: alias hist='history $LINES'\n", @@ -137,7 +153,9 @@ "\n", "## CREATES ERROR (INVALID SYNTAX)\n", "# $ hist\n", - "# $ h" + "# $ h\n", + "# [ hist | perl -pe 's/^\\d+\\s+\\[\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\]$//' ]; echo $?\n", + "hist | perl -pe 's/^\\d+\\s+\\[\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\]$//' >/dev/null && echo $?" ] }, { @@ -572,10 +590,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "15c15\n", - "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n", "---\n", - "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -596,10 +614,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "15c15\n", - "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n", "---\n", - "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -619,10 +637,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "15c15\n", - "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n", "---\n", - "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -644,13 +662,13 @@ "------------------------------------------------------------------------\n", "process1.txt vs. process2.txt\n", "Differences: process1.txt process2.txt\n", - "-rw-r--r-- 1 userxf333 zavee 1201 Apr 16 08:34 process1.txt\n", - "-rw-r--r-- 1 userxf333 zavee 1201 Apr 16 08:34 process2.txt\n", - "13% differences for process1.txt\n", - "15c15\n", - "< ricekil+ 35128 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n", + "-rw-rw-r-- 1 userxf333 userxf333 958 Apr 22 13:51 process1.txt\n", + "-rw-rw-r-- 1 userxf333 userxf333 958 Apr 22 13:51 process2.txt\n", + "16% differences for process1.txt\n", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n", "---\n", - "> ricekil+ 35129 0.0 0.0 22512 3328 pts/8 RN+ 08:34 0:00 ps -u\n" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -687,10 +705,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "-rw-r--r-- N userxfNNN zavee N NN NN:NN ./ls-alR.list\n", - "-rw-r--r-- N userxfNNN zavee NN NN NN:NN ./ls-alR.list.log\n", - "-rw-r--r-- N userxfNNN zavee N NN NN:NN ./ls-aR.list\n", - "-rw-r--r-- N userxfNNN zavee NN NN NN:NN ./ls-aR.list.log\n" + "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-alR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-alR.list.log\n", + "-rw-rw-r-- N userxfNNN userxfNNN N NN NN:NN ./ls-aR.list\n", + "-rw-rw-r-- N userxfNNN userxfNNN NN NN NN:NN ./ls-aR.list.log\n" ] } ], From 9db8e7b2b176827ba7ac392ae8c8fc1de00ae589 Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Tue, 23 Apr 2024 19:54:39 +0545 Subject: [PATCH 25/26] Uncommented tests for count_bigrams.perl (Cell 38-40); Added test for rename-with-file-date (Cell 36); Updated the comment for do_rcsdiff [Permission Denied)] (Cell 18) --- tests/trace-extensionless-shortcut-V2.ipynb | 133 ++++++++++++-------- 1 file changed, 78 insertions(+), 55 deletions(-) diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index 979a2ae7..14b14bcc 100644 --- a/tests/trace-extensionless-shortcut-V2.ipynb +++ b/tests/trace-extensionless-shortcut-V2.ipynb @@ -25,7 +25,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "PROMPT_OVLPJNQIIUQT\\[\\]>\n" + "PROMPT_HPWYCJDVJGTI\\[\\]>\n" ] } ], @@ -77,7 +77,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "renamed '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2' -> '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2.14Apr24.6'\n" + "renamed '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2' -> '/home/zavee/temp/tmp/trace-extensionless-shortcut-v2.23Apr24.7'\n" ] } ], @@ -307,13 +307,21 @@ "execution_count": 17, "id": "1584698d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "N\n" + ] + } + ], "source": [ "# Large List of process with full process paths\n", "# Number of process is random\n", "\n", "## OLD: ps_mine.sh moved to archive\n", - "# ps-mine-all | wc -l | testnum " + "ps-mine-all | wc -l | testnum " ] }, { @@ -326,6 +334,8 @@ "# HELP REQUIRED FOR RCS FILES (TBC)\n", "\n", "## OLD : do_rcsdiff.sh moved to archive\n", + "\n", + "## OLD 2: bash: /home/zavee/tomProject/shell-scripts/archive/do_rcsdiff.sh: Permission denied\n", "# do-rcsdiff | head -n 1" ] }, @@ -417,44 +427,15 @@ "name": "stdout", "output_type": "stream", "text": [ - " Suppress normal output; instead print a count of matching lines\n", - " Suppress normal output; instead print the name of each input\n", - " file from which no output would normally have been printed.\n", - " Suppress normal output; instead print the name of each input\n", - " file from which output would normally have been printed.\n", - " output, grep ensures that the standard input is positioned to\n", - " lines, it outputs any trailing context lines. When the -c or\n", - " --count option is also used, grep does not output a count\n", - " used, grep stops after outputting NUM non-matching lines.\n", - " with each such part on a separate output line.\n", - " Quiet; do not write anything to standard output. Exit\n", - " line of output. If -o (--only-matching) is specified, print the\n", - " Suppress the prefixing of file names on output. This is the\n", - " Prefix each line of output with the 1-based line number within\n", - " is useful with options that prefix their output to the actual\n", - " -lZ outputs a zero byte after each file name instead of the\n", - " usual newline. This option makes the output unambiguous, even\n", - " Print NUM lines of output context. Places a line containing a\n", - " bytes indicate binary data; these are either output bytes that\n", - " By default, TYPE is binary, and grep suppresses output after\n", - " null input binary data is discovered, and suppresses output\n", - " lines that contain improperly encoded data. When some output is\n", - " suppressed, grep follows any output with a one-line message\n", - " Warning: The -a option might output binary garbage, which can\n", - " have nasty side effects if the output is a terminal and if the\n", - " Use line buffering on output. This can cause a performance\n", - " Treat input and output data as sequences of lines, each\n", - " various parts of the output. Its value is a colon-separated\n", - " The following example outputs the location and contents of any line\n", - " rectory whose names contain “g” and end in “.h”. The -n option outputs\n", - " file names to be output even if only one file name happens to be of the\n" + "0\n" ] } ], "source": [ - "## OLD\n", + "## OLD: Command revised to show the working of perlgrep\n", "# perlgrep \"print\" ./grep_manual.txt\n", - "perlgrep \"output\" ./grep_manual.txt" + "# [ \"$(perlgrep \"print\" ./grep_manual.txt | wc -w)\" -gt 300 ]; echo $?\n", + "[ \"$(cat ./grep_manual.txt | perlgrep -c \"print\")\" -gt 10 ]; echo $?" ] }, { @@ -651,18 +632,36 @@ "name": "stdout", "output_type": "stream", "text": [ - "cp: cannot stat 'processall.md': No such file or directory\n", - "N\n" + "'processL.md' -> 'processL.md.23Apr24'\n" ] } ], "source": [ - "copy-with-file-date *.md | wc -l | testnum" + "## OLD: copy-with-file-date *.md | wc -l | testnum\n", + "copy-with-file-date processL.md" ] }, { "cell_type": "code", "execution_count": 36, + "id": "59ae3af6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "renamed 'versionI.txt' -> 'versionI.txt.23Apr24'\n" + ] + } + ], + "source": [ + "rename-with-file-date versionI.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 37, "id": "d9ba3659", "metadata": {}, "outputs": [], @@ -672,46 +671,70 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "c7e4c426", "metadata": { "scrolled": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cat\tN\n" + ] + } + ], "source": [ "## OLD: count_bigrams.perl moved to archive\n", - "# unigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "unigrams man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "1d96c16e", "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cat\tN\n" + ] + } + ], "source": [ "## OLD: count_bigrams.perl moved to archive\n", "# word-count ./man_cat.txt | testuser | testnum\n", - "# word-count ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "word-count man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "71adad1d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'(coreutils):cat\tN\n" + ] + } + ], "source": [ "## OLD: count_bigrams.perl moved to archive\n", "# bigrams ./man_cat.txt | testuser | testnum\n", - "# bigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" + "bigrams ./man_cat.txt | grep -w \"cat\" | head -n 1 | testnum" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "d57951d5", "metadata": {}, "outputs": [], @@ -722,7 +745,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "86419b9f", "metadata": {}, "outputs": [ @@ -742,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "id": "d9ed2744", "metadata": {}, "outputs": [], @@ -754,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "f45efa52", "metadata": {}, "outputs": [ @@ -773,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "addf3591", "metadata": {}, "outputs": [ @@ -792,7 +815,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "49d6d56d", "metadata": { "scrolled": true From 2fe7f17eb7b47d204effe4d4346d65cf711b358c Mon Sep 17 00:00:00 2001 From: Aviyan Acharya Date: Fri, 26 Apr 2024 14:12:46 +0545 Subject: [PATCH 26/26] Modified show-python-path command to check if the output consists of more than 1 line (Cell 15) & path to mezcla (Cell 16); Used conditional-echo commands for python-lint, python-import-path tests, python-module-version (Cell 17, 18, 24, 26, 27, 28); Test for url-path uses path to tests/batspp_report.py (Cell 61); Commented final instance of trash_dir use (Cell 65) --- tests/trace-python-commands.ipynb | 288 +++++++++++++++++++----------- 1 file changed, 184 insertions(+), 104 deletions(-) diff --git a/tests/trace-python-commands.ipynb b/tests/trace-python-commands.ipynb index 6034f10f..935293bb 100644 --- a/tests/trace-python-commands.ipynb +++ b/tests/trace-python-commands.ipynb @@ -38,8 +38,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "testuser\n", - "testuser operator docker\n" + "ricekiller\n", + "ricekiller docker\n" ] } ], @@ -54,7 +54,15 @@ "execution_count": 4, "id": "6e085f64-e505-458b-af13-9d46d12913cc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "*** Warning: should be run as operator ***\n" + ] + } + ], "source": [ "# Warn if user not in operators group\n", "# note: The bash kernel restarts, \n", @@ -169,8 +177,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "renamed '/home/testuser/temp/tmp/trace-python-commands' -> '/home/testuser/temp/tmp/trace-python-commands.03Feb24.11'\n", - "/home/testuser/temp/tmp/trace-python-commands\n" + "/home/zavee/tomProject/shell-scripts\n", + "renamed '/home/zavee/temp/tmp/trace-python-commands' -> '/home/zavee/temp/tmp/trace-python-commands.26Apr24.26'\n", + "/home/zavee/temp/tmp/trace-python-commands\n" ] } ], @@ -182,6 +191,7 @@ "## /home/testuser/temp/tmp/batspp/tmp_subprocess_/global-test-dir\n", "## TODO2: make use the following in the other tests as well (see tomohara-aliases.bash)\n", "BIN_DIR=$TOM_BIN\n", + "echo $BIN_DIR\n", "##\n", "## NOTE: For reproducability, the directory name needs to be fixed\n", "## In place of $$, use a psuedo random number (e,g., 7766)\n", @@ -248,6 +258,7 @@ "# Sample Output: 23\n", "## BAD: ps-python-full | wc -l | testnum\n", "## NOTE: this differs based on running processes\n", + "export TOM_BIN=\"${TOM_BIN:-}:$TOM_BIN/archive\"\n", "full=$(ps-python-full | wc -l)" ] }, @@ -261,7 +272,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "1\n" ] } ], @@ -276,18 +287,19 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 14, "id": "3c7a4a1d-83ec-4bb0-9556-7abc80e3a5e5", "metadata": {}, "outputs": [], "source": [ "## DEBUG:\n", - "## show-python-path | head -4" + "## show-python-path | head -4\n", + "# export PYTHONPATH=\"$PYTHONPATH:$HOME/tomProject/mezcla\"" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "f7249c59-054a-4382-af5c-6119b323bff7", "metadata": {}, "outputs": [ @@ -295,19 +307,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "PYTHONPATH:\n" + "0\n" ] } ], "source": [ "# show-python-path DISPLAYS ALL THE AVAILABLE PATHS OF PYTHON\n", "## OLD: show-python-path | testuser\n", - "show-python-path 2>&1 | head -1" + "# show-python-path 2>&1 | head -1\n", + "[ \"$(show-python-path | wc -l)\" -gt 1 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 16, "id": "17e83d2a-cf5c-48bd-b4d2-302b4b0a140c", "metadata": {}, "outputs": [ @@ -315,18 +328,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], "source": [ "# Mezcla should be in the path\n", - "show-python-path | sort -u | grep -c 'mezcla'" + "## OLD: show-python-path | sort -u | grep -c 'mezcla'\n", + "[ \"$(show-python-path | perl-grep 'mezcla')\" ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "bbb90e81-74ac-4634-a9d2-0b632d824bf4", "metadata": {}, "outputs": [ @@ -334,20 +348,24 @@ "name": "stdout", "output_type": "stream", "text": [ - "NN\n" + "0\n" ] } ], "source": [ + "## NOTE: Requires pylint\n", + "\n", "# function python-lint() { python-lint-work \"$@\" 2>&1 | $EGREP -v '(Exactly one space required)|\\((bad-continuation|bad-whitespace|bad-indentation|bare-except|c-extension-no-member|consider-using-enumerate|consider-using-with|global-statement|global-variable-not-assigned|keyword-arg-before-vararg|len-as-condition|line-too-long|logging-not-lazy|misplaced-comparison-constant|missing-final-newline|redefined-variable-type|redundant-keyword-arg|superfluous-parens|too-many-arguments|too-many-instance-attributes|trailing-newlines|useless-\\S+|wrong-import-order|wrong-import-position)\\)' | $PAGER; }\n", "## OLD: python-lint os | testnum | testuser\n", "## BAD: python-lint os | head | testnum | testuser\n", - "python-lint os | grep -c Redefining | testnum" + "\n", + "# python-lint os | grep -c Redefining | testnum\n", + "[ \"$(python-lint os | perl-grep -c Redefining )\" -gt 1 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "5039b234", "metadata": { "scrolled": true @@ -357,8 +375,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n", - "N\n" + "0\n" ] } ], @@ -367,13 +384,17 @@ "# TODO2: rework link test using small python program put in test resources dir (e.g., test/resources/bad_lint.py)\n", "## BAD: # function python-lint-work() { python-lint-full \"$@\" 2>&1 | $EGREP -v '\\((bad-continuation|bad-option-value|fixme|invalid-name|locally-disabled|too-few-public-methods|too-many-\\S+|trailing-whitespace|star-args|unnecessary-pass)\\)' | $EGREP -v '^(([A-Z]:[0-9]+)|(Your code has been rated)|(No config file found)|(\\-\\-\\-\\-\\-))' | $PAGER; }\n", "## BAD: python-lint-work os | head | testnum\n", - "python-lint os | grep -c bare-except\n", - "python-lint-work os | grep -c bare-except | testnum" + "\n", + "# python-lint os | grep -c bare-except\n", + "# python-lint os\n", + "\n", + "# python-lint-work os | grep -c bare-except | testnum\n", + "[ \"$(python-lint-work os | perl -ne 'print \"$1\\n\" if /([A-Z]\\d{4,})/' | sort | uniq | wc -l)\" -gt 10 ]; echo $?\n" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 19, "id": "cab9db0c", "metadata": {}, "outputs": [ @@ -381,7 +402,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "C0116:\n", + "E0601:\n", "R1705:\n", "W0621:\n" ] @@ -396,7 +417,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "207d98f0", "metadata": {}, "outputs": [], @@ -408,7 +429,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "6e4b2871", "metadata": {}, "outputs": [], @@ -424,7 +445,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "id": "4a313b5a-c666-4890-9655-c6f9850bf653", "metadata": {}, "outputs": [ @@ -437,16 +458,20 @@ } ], "source": [ - "# mezcla MODULE IS USED FOR TEST\n", + "## mezcla MODULE IS USED FOR TEST\n", + "\n", + "# $ python-import-path 'mezcla'\n", + "# | matches /home/zavee/tomProject/mezcla/mezcla/__init__.py\n", "\n", "## BAD: python-import-path 'mezcla' | testnum\n", - "python-import-path 'mezcla' | perl-grep -c \"matches \\S+/Mezcla/mezcla/__init__.py\"\n", - "## OLD: linebr" + "# python-import-path 'mezcla' | perl-grep -c \"matches \\S+/mezcla/mezcla/__init__.py\"\n", + "\n", + "[ \"$(python-import-path 'mezcla' | perl-grep -c \"matches \\S+/mezcla/mezcla/__init__.py\")\" -eq 1 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "id": "dd9e32d2-2f31-4049-b0a1-4b65dd2df006", "metadata": {}, "outputs": [ @@ -468,7 +493,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "id": "c83d89b2-c550-4430-a770-50facaba14c3", "metadata": {}, "outputs": [ @@ -476,19 +501,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "NN\n" + "0\n" ] } ], "source": [ "# WORKS WELL, SHOWS SOME ISSUES ON BATSPP 2.1.X\n", "## BAD: python-import-path-all 'mezcla' | grep mezcla | head -n 5 | testnum\n", - "python-import-path-all 'mezcla' | grep -c mezcla | testnum" + "[ \"$(python-import-path-all 'mezcla' | grep -c mezcla)\" -gt 10 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "id": "852d5ab4", "metadata": {}, "outputs": [], @@ -501,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "id": "e82509c6", "metadata": {}, "outputs": [ @@ -509,32 +534,61 @@ "name": "stdout", "output_type": "stream", "text": [ - "N.N.N.N\n", - "0.03user 0.01system 0:00.05elapsed 98%CPU (0avgtext+0avgdata 17236maxresident)k\n", - "0inputs+8outputs (0major+2890minor)pagefaults 0swaps\n", - "------------------------------------------------------------------------------------------------------------------------------------\n", - "N.N.N.N\n", - "------------------------------------------------------------------------------------------------------------------------------------\n", - "['PYTHONN_PLUS', 'TL', '__VERSION__', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'debug', 'gh', 'glue_helpers', 'my_re', 'my_regex', 'sys', 'system', 'tpo_common', 'version']\n", - "0.04user 0.00system 0:00.05elapsed 98%CPU (0avgtext+0avgdata 16972maxresident)k\n", - "0inputs+8outputs (0major+2881minor)pagefaults 0swaps\n", - "------------------------------------------------------------------------------------------------------------------------------------\n" + "0\n" + ] + } + ], + "source": [ + "## MODULE USED: mezcla | sed filter replaces versin number with XX\n", + "# python-module-version-full mezcla | testnum\n", + "# linebr\n", + "# python-module-version mezcla | testnum\n", + "# linebr\n", + "# python-package-members mezcla | testnum\n", + "# linebr\n", + "\n", + "[ \"$(python-module-version-full mezcla | testnum)\" == \"N.N.N.N\" ]; echo $?" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "e2cc5d95", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" ] } ], "source": [ - "# MODULE USED: mezcla | sed filter replaces versin number with XX\n", - "python-module-version-full mezcla | testnum\n", - "linebr\n", - "python-module-version mezcla | testnum\n", - "linebr\n", - "python-package-members mezcla | testnum\n", - "linebr" + "[ \"$(python-module-version mezcla | testnum)\" == \"N.N.N.N\" ]; echo $?" ] }, { "cell_type": "code", "execution_count": 28, + "id": "d1da1f97", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "[ \"$(python-package-members mezcla | perl-grep -c \"glue_helpers\")\" -eq 1 ]; echo $?" + ] + }, + { + "cell_type": "code", + "execution_count": 29, "id": "caf8bfd0", "metadata": {}, "outputs": [], @@ -592,7 +646,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "id": "1912bb79-d984-4788-84d6-3759caf3383d", "metadata": {}, "outputs": [], @@ -603,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "30fc8ae2-fb50-4f19-908e-1178ef19776e", "metadata": { "scrolled": true @@ -626,7 +680,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "d98b6d58", "metadata": {}, "outputs": [ @@ -653,7 +707,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "93146b8d", "metadata": {}, "outputs": [ @@ -679,7 +733,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "9dcb601f", "metadata": {}, "outputs": [ @@ -707,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "8080d06d", "metadata": {}, "outputs": [ @@ -733,7 +787,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "b8c1c892", "metadata": { "scrolled": true @@ -761,10 +815,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "488f8718-37d7-46e7-9b09-bb5ba822b55b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "N.NN.N\n" + ] + } + ], "source": [ "## THIS PART IS SLOW IN EXECUTION\n", "\n", @@ -776,10 +838,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "0cc12ce8-2a70-4cc6-b31d-32f6a4b222fd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " --- modulename: template, funcname: \n", + "template.py(NN): \"\"\"\n", + "template.py(NN): from mezcla import debug\n", + " --- modulename: _bootstrap, funcname: _find_and_load\n", + "(NNNN): --- modulename: _bootstrap, funcname: __init__\n" + ] + } + ], "source": [ "# STATEMENT TRACING WORKS WELL / ISSUES WITH TESTUSER\n", "## BAD: python-trace l $BIN_DIR/tests/auto_batspp.py | testuser | testnum\n", @@ -790,7 +864,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 39, "id": "c0b6f931", "metadata": {}, "outputs": [ @@ -817,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 40, "id": "2e0b2a50-1897-4828-aafc-e743b1b95a4f", "metadata": {}, "outputs": [], @@ -830,7 +904,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 41, "id": "218b4eda-a344-432e-a2cc-4bbe6003c61f", "metadata": {}, "outputs": [], @@ -841,7 +915,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 42, "id": "cdd86ce9-6fb4-4c6f-98f8-e34d75f77942", "metadata": {}, "outputs": [ @@ -849,8 +923,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "NN% differences for template.py\n", - "-N% differences for *.mako\n" + "NN% differences for template.py\n" ] } ], @@ -886,7 +959,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 43, "id": "9a40ffff", "metadata": {}, "outputs": [], @@ -902,7 +975,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 44, "id": "b6e7b1d1", "metadata": {}, "outputs": [], @@ -915,7 +988,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 45, "id": "5dbc85eb", "metadata": {}, "outputs": [], @@ -946,7 +1019,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 46, "id": "9322aa5a", "metadata": {}, "outputs": [], @@ -973,7 +1046,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 47, "id": "caa3332b", "metadata": {}, "outputs": [], @@ -995,7 +1068,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 48, "id": "9c155aa3", "metadata": {}, "outputs": [], @@ -1013,7 +1086,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 49, "id": "53136103", "metadata": {}, "outputs": [], @@ -1028,7 +1101,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 50, "id": "31d1b151", "metadata": {}, "outputs": [], @@ -1040,7 +1113,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 51, "id": "3b6aab89", "metadata": {}, "outputs": [], @@ -1056,7 +1129,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 52, "id": "88b697b0-82c6-48c2-8b0d-96d922b177b6", "metadata": {}, "outputs": [], @@ -1069,7 +1142,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 53, "id": "c3845ce6-bf26-423c-81f3-356acca66f8d", "metadata": {}, "outputs": [ @@ -1104,7 +1177,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 54, "id": "833520df-e503-4131-bbdd-98bd990a9d2f", "metadata": {}, "outputs": [ @@ -1112,8 +1185,6 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.06user 0.02system 0:00.08elapsed 101%CPU (0avgtext+0avgdata 17476maxresident)k\n", - "0inputs+24outputs (0major+3403minor)pagefaults 0swaps\n", "1\n", "2\n", "6\n", @@ -1134,7 +1205,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 55, "id": "4f226d82-2376-4caf-9b40-49a742a06980", "metadata": {}, "outputs": [ @@ -1154,7 +1225,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 56, "id": "4a08ccc0-4d02-49a9-9744-ff4d2707f812", "metadata": {}, "outputs": [ @@ -1176,7 +1247,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 57, "id": "59e5fe12-c47b-4600-9487-e1a746aece67", "metadata": {}, "outputs": [ @@ -1200,7 +1271,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 58, "id": "2c5ba0e4-e09e-4703-856c-5b5c436f6d7c", "metadata": {}, "outputs": [], @@ -1210,7 +1281,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 59, "id": "df7835ca-a1c2-4ad9-9acb-4bb8a63afcbc", "metadata": {}, "outputs": [ @@ -1234,7 +1305,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 60, "id": "4c49d849-0dfe-484e-ba6c-8ee27ca755ff", "metadata": {}, "outputs": [ @@ -1256,7 +1327,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 61, "id": "d1ea335b-91bd-4016-8456-6dbfb6f0aaf3", "metadata": {}, "outputs": [ @@ -1264,7 +1335,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], @@ -1273,12 +1344,17 @@ "# file:////home/shell-scripts/tests/auto_batspp.py\n", "## OLD: url-path $BIN_DIR/tests/auto_batspp.py | testuser\n", "## OLD: url-path $BIN_DIR/tests/auto_batspp.py | testuser | remove-control-chars\n", - "url-path $BIN_DIR/tests/auto_batspp.py | grep -c \"file:////.*/tests/auto_batspp.py\"" + "\n", + "# OLD: url-path $BIN_DIR/tests/auto_batspp.py | grep -c \"file:////.*/tests/auto_batspp.py\"\n", + "\n", + "# NEW Test url-path:\n", + "# file:////home/shell-scripts/tests/batspp_report.py\n", + "[ \"$(url-path $BIN_DIR/tests/batspp_report.py | perl-grep -c \"file:////.*/tests/batspp_report\\.py\")\" -eq 1 ]; echo $?" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 62, "id": "b49f6117-3b7a-47e5-a51f-5456514a1353", "metadata": {}, "outputs": [], @@ -1289,7 +1365,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 63, "id": "c57545c5", "metadata": {}, "outputs": [], @@ -1304,7 +1380,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 64, "id": "008e51b7", "metadata": {}, "outputs": [ @@ -1322,7 +1398,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 65, "id": "a3d18560", "metadata": {}, "outputs": [ @@ -1330,17 +1406,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "Successfully moved to trash\n" + "End\n" ] } ], "source": [ - "if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", - " command mv -f * \"$trash_dir\"\n", - " echo \"Successfully moved to trash\"\n", - "else\n", - " echo \"Warning: Current directory not in TMP\"\n", - "fi" + "## OLD: Use of trash_dir is removed\n", + "\n", + "# if [[ \"$PWD\" = *\"/tmp/\"* ]]; then\n", + "# command mv -f * \"$trash_dir\"\n", + "# echo \"Successfully moved to trash\"\n", + "# else\n", + "# echo \"Warning: Current directory not in TMP\"\n", + "# fi\n", + "\n", + "echo \"End\"" ] } ],