diff --git a/local-workflows.sh b/local-workflows.sh index 68cea96b..b4c9f333 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 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" diff --git a/tests/alias-cd-commands.ipynb b/tests/alias-cd-commands.ipynb index b6b073d8..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_PIVYDHUVDODH\\[\\]>\n" + "PROMPT_AXHVQRLAWUPC\\[\\]>\n" ] } ], @@ -60,29 +60,13 @@ "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", + "alias testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\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,16 +76,25 @@ "## *** 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", - "command mkdir -p $temp_dir\n", - "command cd $temp_dir\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", + "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", @@ -110,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "9e1fb88a", "metadata": {}, "outputs": [ @@ -131,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "6a1cb00b", "metadata": {}, "outputs": [ @@ -152,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "8a6085e9", "metadata": {}, "outputs": [], @@ -163,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "6cce12a4", "metadata": {}, "outputs": [], @@ -175,26 +168,73 @@ }, { "cell_type": "code", - "execution_count": 11, + "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" ] }, { "cell_type": "code", - "execution_count": 12, + "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-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 works as cd as well\n", - "cd-this-realdir .. > /dev/null\n", - "cd-this-realdir test-6869/ > /dev/null" + "## 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" ] }, { @@ -204,7 +244,8 @@ "metadata": {}, "outputs": [], "source": [ - "rm -rf ./* > /dev/null\n", + "## BAD: rm -rf ./* > /dev/null\n", + "## BAD: command mv -f * $trash_dir\n", "# mkdir testdir89 testdir90\n", "command mkdir testdir89 testdir90\n", "echo \"Testfile1\" > testdir89/f11.txt\n", @@ -237,7 +278,9 @@ "cell_type": "code", "execution_count": 15, "id": "14b95b96", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -253,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": { diff --git a/tests/alias-grep-commands.ipynb b/tests/alias-grep-commands.ipynb index c2c6630c..fcd118d3 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" + "0\n" ] } ], @@ -34,65 +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\n", - "\n", - "## NOTE: Source it directly from the ./tests directory.\n", - "BIN_DIR=$PWD/.." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "acd1700d", - "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "437\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": [ @@ -101,62 +73,75 @@ "## 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 ' ' '-'\"" ] }, { "cell_type": "code", - "execution_count": 7, - "id": "2f7150b0", + "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", + "# 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", - "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-7371\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-grep-commands; fi\n", "\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd\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", + "temp_dir=$TMP/alias-grep-commands\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", - "\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": [ - "440\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": [ @@ -164,18 +149,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": [], @@ -186,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "37c6221e", "metadata": {}, "outputs": [ @@ -194,29 +185,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": [], @@ -224,8 +204,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", @@ -239,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "id": "f906642e", "metadata": {}, "outputs": [ @@ -274,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "id": "b209fa0d", "metadata": {}, "outputs": [ @@ -295,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "id": "66375e3e", "metadata": {}, "outputs": [ @@ -316,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "id": "4a61dbfa", "metadata": {}, "outputs": [ @@ -335,18 +315,18 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "id": "690311c9", "metadata": {}, "outputs": [], "source": [ - "# # Halts test\n", + "## Halts test\n", "# show-line-context testgrep3" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "id": "c1709353", "metadata": { "scrolled": true @@ -367,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "id": "4221570d", "metadata": {}, "outputs": [ @@ -386,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 18, "id": "76128375", "metadata": {}, "outputs": [], @@ -396,28 +376,31 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 19, "id": "e51dcd01", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "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 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|'" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "id": "584ac3a6", "metadata": {}, "outputs": [ @@ -437,7 +420,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "id": "4da38cda", "metadata": {}, "outputs": [], @@ -447,7 +430,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "id": "f7c048b8", "metadata": {}, "outputs": [], @@ -458,7 +441,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "id": "1572700d", "metadata": {}, "outputs": [], @@ -466,7 +449,28 @@ "# # # 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", + "## 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 0fbdb6d1..a358341c 100755 --- a/tests/alias-trace-misc-commands.ipynb +++ b/tests/alias-trace-misc-commands.ipynb @@ -50,18 +50,14 @@ "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 testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n", + "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, { @@ -69,16 +65,35 @@ "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", "## 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", - "##\n", - "mkdir -p \"$temp_dir\"" + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then TMP=/tmp/test-trace-misc; fi\n", + "\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", + "temp_dir=$TMP/alias-trace-misc\n", + "rename-with-file-date \"$temp_dir\"\n", + "command mkdir -p \"$temp_dir\"\n", + "command cd $temp_dir" ] }, { @@ -95,45 +110,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": [], @@ -147,20 +123,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": [], @@ -170,10 +133,18 @@ }, { "cell_type": "code", - "execution_count": 12, + "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", @@ -182,12 +153,14 @@ "\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 $?" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "id": "ed1a5eb4", "metadata": {}, "outputs": [ @@ -195,7 +168,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "DDD MMM N N:N:N N\n" + "0\n" ] } ], @@ -203,12 +176,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": [ @@ -217,11 +192,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" ] } ], @@ -235,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "0a69f15f", "metadata": {}, "outputs": [ @@ -243,18 +218,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": [ @@ -262,18 +237,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": [ @@ -281,20 +256,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": [ @@ -302,14 +277,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" ] } ], @@ -339,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "id": "95bda88c", "metadata": {}, "outputs": [ @@ -347,9 +316,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "204K\t.\n", - "16K\t./backup\n", - "8K\t./info\n" + "12K\t.\n" ] } ], @@ -369,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "id": "db031306", "metadata": {}, "outputs": [ @@ -377,9 +344,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" ] @@ -402,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "id": "ae8977b2", "metadata": {}, "outputs": [ @@ -410,35 +374,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": [ @@ -458,7 +417,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 20, "id": "a8c89aa1", "metadata": {}, "outputs": [ @@ -468,8 +427,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" ] } ], @@ -481,7 +439,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 21, "id": "9f2bfe8c", "metadata": { "scrolled": true @@ -507,7 +465,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 22, "id": "5c1dc2a2", "metadata": {}, "outputs": [], @@ -527,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "id": "895d01b9", "metadata": {}, "outputs": [], @@ -539,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 24, "id": "4e48f66b", "metadata": {}, "outputs": [], @@ -553,7 +511,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 25, "id": "d5cf2239", "metadata": {}, "outputs": [], @@ -586,7 +544,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "id": "0c36d6d5", "metadata": { "scrolled": true @@ -596,9 +554,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/alias-trace-misc\n" ] } ], @@ -626,7 +582,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "id": "a19413d5", "metadata": {}, "outputs": [ @@ -634,12 +590,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", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 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" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -652,7 +606,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "id": "169b9a64", "metadata": {}, "outputs": [ @@ -660,12 +614,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", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 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" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -677,7 +629,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 29, "id": "636168eb", "metadata": {}, "outputs": [ @@ -685,12 +637,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", + "12c12\n", + "< ricekil+ 16431 0.0 0.0 22512 3328 pts/7 RN+ 13:51 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" + "> ricekil+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -701,7 +651,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 30, "id": "486aec7d", "metadata": {}, "outputs": [ @@ -709,18 +659,16 @@ "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", - "---\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", "------------------------------------------------------------------------\n", - "\n" + "process1.txt vs. process2.txt\n", + "Differences: process1.txt process2.txt\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+ 16432 0.0 0.0 22512 3328 pts/7 RN+ 13:51 0:00 ps -u\n" ] } ], @@ -731,7 +679,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 31, "id": "903ac57f", "metadata": {}, "outputs": [], @@ -749,7 +697,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 32, "id": "cbe6782b", "metadata": {}, "outputs": [ @@ -757,16 +705,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" ] } ], @@ -780,7 +722,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 33, "id": "1985ac69", "metadata": {}, "outputs": [], @@ -793,43 +735,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 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" ] }, { "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" @@ -837,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "aa359b7a-165a-4909-9e1a-405940dc564d", "metadata": {}, "outputs": [], @@ -848,7 +786,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "06a251ce-184b-4c6d-81e0-ae6a7bfe5837", "metadata": {}, "outputs": [], @@ -859,7 +797,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "1c375a69", "metadata": {}, "outputs": [], @@ -890,17 +828,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": [], @@ -913,7 +859,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "id": "198d4bae", "metadata": {}, "outputs": [], @@ -925,26 +871,37 @@ }, { "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", - "rm $HOME/info/.noice-signature" + "\n", + "## OLD & BAD: command mv -f * $trash_dir \n" ] }, { "cell_type": "code", - "execution_count": null, + "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/automate_notebook.py b/tests/automate_notebook.py new file mode 100755 index 00000000..7067616c --- /dev/null +++ b/tests/automate_notebook.py @@ -0,0 +1,381 @@ +#! /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/): +# ricekiller@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 +import subprocess + +# 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" +COMMAND_IS_JUPYTER_RUNNING = "jupyter nbclassic list" +CURRENT_PATH = gh.real_path(".") +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)") + +## 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)""" + + 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): + + 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 diff --git a/tests/batspp_report.py b/tests/batspp_report.py index 85cb0161..a9765353 100755 --- a/tests/batspp_report.py +++ b/tests/batspp_report.py @@ -575,7 +575,7 @@ def print_test_array(arr): 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}. {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}. {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") diff --git a/tests/command-override-cp-mv.ipynb b/tests/command-override-cp-mv.ipynb index 7cb5c9cb..3a0bb330 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" + "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,66 @@ "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", - "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 ' ' '-'\"" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "8093ffd1", + "id": "1f0c6191", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "443\n" + "renamed '/tmp/trace-python-commands/trace-python-commands' -> '/tmp/trace-python-commands/trace-python-commands.16Apr24.3'\n" ] } ], "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", - "TMP=./tmp/test-cp-mv\n", - "BIN_DIR=$PWD/..\n", - "## temp_dir=$TMP/test-$$\n", - "temp_dir=$TMP/test-1210\n", - "\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd | testuser\n", + "# 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/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", - "# TODO: /bin/rm -rvf \"$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 ' ' -\"" + "# command mkdir -p \"$trash_dir\"\n", + "command cd \"$temp_dir\"" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "8a0854c8", + "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 testuserpath=\"sed 's|/home/[^/]\\+/|USER_PATH/|'\"\n", + "alias linebr=\"printf '%132s\\n' ' ' | tr ' ' '-'\"" ] }, { @@ -116,13 +119,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "443\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 +147,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "474\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 \"$?\"" ] }, { @@ -198,16 +214,18 @@ "# 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": [], "source": [ + "## WORK OF ALIASES\n", "## CREATES TEST SUBJECTS\n", "touch abc def ghi\n", "mkdir mvtest_dir1" @@ -216,7 +234,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "01f003bf", + "id": "86397b57", "metadata": {}, "outputs": [ { @@ -230,7 +248,6 @@ } ], "source": [ - "## WORK OF ALIASES\n", "mv abc ./mvtest_dir1\n", "move def ./mvtest_dir1\n", "move-force ghi ./mvtest_dir1" @@ -247,7 +264,7 @@ "output_type": "stream", "text": [ "total N \n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" + "drwxr-xr-x N userxf333 userxf333 NNNN NN NN:NN mvtest_dirN\n" ] } ], @@ -313,9 +330,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", + "## OLD: command mv -f * \"$trash_dir\"" ] }, { @@ -366,9 +393,10 @@ "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", + "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" + "-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" ] } ], @@ -477,13 +505,14 @@ "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", + "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-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" + "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" ] } ], @@ -506,13 +535,14 @@ "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", + "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-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" + "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" ] } ], @@ -549,26 +579,13 @@ "execution_count": 26, "id": "29b8b028", "metadata": {}, - "outputs": [ - { - "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" - ] - } - ], + "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" ] }, { @@ -578,8 +595,9 @@ "metadata": {}, "outputs": [], "source": [ - "rm -rf ./* > /dev/null\n", - "mkdir testdir1" + "# BAD: rm -rf ./* > /dev/null\n", + "# command mv -f * \"$trash_dir\"\n", + "# mkdir testdir1" ] }, { @@ -587,17 +605,9 @@ "execution_count": 28, "id": "453d4af0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-r--r--r-- N userxf333 userxf333 NNNN NN NN:NN ./testdirN//.bashrc\n" - ] - } - ], + "outputs": [], "source": [ - "copy-readonly ~/.bashrc ./testdir1/ | awk '!($6=\"\")' | testnum | testuser" + "# copy-readonly ~/.bashrc testdir1 | awk '!($6=\"\")' | testnum | testuser" ] }, { @@ -605,17 +615,9 @@ "execution_count": 29, "id": "167288de", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "# ~/.bashrc: executed by bash(1) for non-login shells.\n" - ] - } - ], + "outputs": [], "source": [ - "cat ./testdir1/.bashrc | head -n 1" + "# cat testdir1/.bashrc | head -n 1" ] }, { @@ -640,14 +642,24 @@ "cell_type": "code", "execution_count": 31, "id": "d6cf3aca", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "total N \n", - "drwxr-sr-x N userxf333 userxf333 NNNN NN NN:NN testdirN\n" + "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 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" ] } ], @@ -655,6 +667,22 @@ "# AFTER fix-dir-permissions\n", "ls -l | awk '!($6=\"\")' | testnum | testuser" ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "5d4aef31", + "metadata": {}, + "outputs": [], + "source": [ + "## 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" + ] } ], "metadata": { 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/download-and-test-tomohara-aliases.ipynb b/tests/download-and-test-tomohara-aliases.ipynb index 71cc509c..f4444246 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/_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", "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/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": [], 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": { 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/more-tomohara-aliases-test.ipynb b/tests/more-tomohara-aliases-test.ipynb index 5dda6c97..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\"\"" ] }, { @@ -46,10 +47,22 @@ "source": [ "# Setup temp. dir\n", "# note: variable not used in rm as a precaution\n", - "/bin/rm -rf \"/tmp/test-dir-15485863\"\n", - "test_dir=\"/tmp/test-dir-15485863\"\n", - "mkdir -p \"$test_dir\"\n", - "command cd \"$test_dir\"" + "# BAD: /bin/rm -rf \"/tmp/test-dir-15485863\"\n", + "\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\"" ] }, { @@ -177,13 +190,32 @@ "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" ] } ], "source": [ "cat dir_perl.out | head -n 4 | tail -n 1 | testnum" ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], + "source": [ + "# Remove everything after use\n", + "## OLD: command mv -f * \"$trash_dir\"\n", + "echo \"END\"" + ] } ], "metadata": { diff --git a/tests/test-check-errors.ipynb b/tests/test-check-errors.ipynb index 2cc1d9bc..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_NOJPPBQVRZOM\\[\\]>\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,11 +84,20 @@ "# cd \"$temp_dir\"\n", "# pwd\n", "\n", - "temp_dir=$TMP/test-2334\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", - "# TODO: /bin/rm -rvf \"$temp_dir\"\n", "command cd \"$temp_dir\"\n", - "\n", "## OLD: Debug\n", "# command pwd\n", "\n", @@ -122,7 +132,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/test-check-errors/test-2334\n" + "/tmp/test-check-errors/test-check-errors\n" ] } ], @@ -159,12 +169,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/zavee/.local/lib/python3.10/site-packages (1.3.9.9)\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 +291,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "True\n" + "False\n" ] } ], @@ -373,9 +392,19 @@ "execution_count": 21, "id": "f8a387ac", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "END\n" + ] + } + ], "source": [ - "/bin/rm -rf $temp_dir > /dev/null" + "# BAD: /bin/rm -rf $temp_dir > /dev/null\n", + "## 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 dcb40c1d..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_RGGQLGHSXGBZ\\[\\]>\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,23 +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", + "# # 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", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "# cd \"$temp_dir\"\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", - "# # TODO: /bin/rm -rvf \"$temp_dir\"\n", - "command cd \"$temp_dir\"\n", + "command cd $temp_dir\n", "\n", "## OLD: For debugging\n", "# pwd\n", @@ -209,13 +225,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 +284,7 @@ } ], "source": [ + "## 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 83042556..a0a52987 100644 --- a/tests/test-tomohara-aliases-access.ipynb +++ b/tests/test-tomohara-aliases-access.ipynb @@ -13,14 +13,27 @@ "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 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\"" + "\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 cd \"$TEMP_TOM_BIN\"" ] }, { @@ -34,7 +47,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 144k 100 144k 0 0 366k 0 --:--:-- --:--:-- --:--:-- 366k\n" ] } ], @@ -53,7 +66,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 +112,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", + "# BAD TOO: command mv -f * \"$trash_dir\"" ] } ], 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": [ diff --git a/tests/trace-extensionless-shortcut-V2.ipynb b/tests/trace-extensionless-shortcut-V2.ipynb index 0100f43f..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_QEEKCWGSYOEQ\\[\\]>\n" + "PROMPT_HPWYCJDVJGTI\\[\\]>\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,14 +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.23Apr24.7'\n" + ] + } + ], "source": [ - "temp_dir=$TMP/test-3570\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 cd \"$temp_dir\"\n", "#ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", "alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" @@ -213,7 +230,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", @@ -301,6 +319,8 @@ "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 " ] }, @@ -309,20 +329,14 @@ "execution_count": 18, "id": "c7070a99", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\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", + "\n", + "## OLD 2: bash: /home/zavee/tomProject/shell-scripts/archive/do_rcsdiff.sh: Permission denied\n", + "# do-rcsdiff | head -n 1" ] }, { @@ -413,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", - " 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", - " 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 message to standard\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", - " 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 $?" ] }, { @@ -458,18 +443,12 @@ "execution_count": 24, "id": "3ca47040", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "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" ] }, { @@ -653,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": [], @@ -674,7 +671,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "c7e4c426", "metadata": { "scrolled": false @@ -689,12 +686,13 @@ } ], "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" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "1d96c16e", "metadata": { "scrolled": true @@ -709,14 +707,14 @@ } ], "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" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "71adad1d", "metadata": {}, "outputs": [ @@ -724,19 +722,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "cat(N):user\tN\n" + "'(coreutils):cat\tN\n" ] } ], "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" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "d57951d5", "metadata": {}, "outputs": [], @@ -747,7 +745,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "86419b9f", "metadata": {}, "outputs": [ @@ -767,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "id": "d9ed2744", "metadata": {}, "outputs": [], @@ -779,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "f45efa52", "metadata": {}, "outputs": [ @@ -798,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "addf3591", "metadata": {}, "outputs": [ @@ -817,9 +815,11 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "49d6d56d", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -830,6 +830,8 @@ } ], "source": [ + "# NOTE (PROPOSED APPROACH): Add timestamp to the directory before moving them to trash_dir\n", + "# 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..5340a9fd 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" ] } ], @@ -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/.." ] }, @@ -49,12 +49,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "440\n" + "438\n" ] } ], "source": [ - "alias | wc -l" + "## OLD: For debuging\n", + "# alias | wc -l" ] }, { @@ -64,15 +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", "\n", - "command mkdir -p \"$temp_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 ' ' -\"" @@ -134,12 +145,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", + "## BAD TOO: command mv -f * \"$trash_dir\"\n", "uname -r > version1.txt" ] }, @@ -181,7 +201,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,11 +210,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" ] @@ -215,7 +243,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 +252,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 +337,8 @@ } ], "source": [ - "echo \"END\"" + "echo \"END\"\n", + "## OLD: command mv -f * \"$trash_dir\"" ] } ], diff --git a/tests/trace-file-manipulation.ipynb b/tests/trace-file-manipulation.ipynb index dc69016b..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_DXHRQXUOVQEL\\[\\]>\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,24 +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", - "\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", - "# 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", @@ -173,7 +192,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", @@ -627,8 +646,9 @@ "metadata": {}, "outputs": [], "source": [ - "# CLEARS THE TEST FOLDER\n", - "rm -rf ./* > /dev/null" + "## 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 421977d4..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_LAUPWREDQERO\\[\\]>\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,16 +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", + "# 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", + "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", @@ -171,7 +189,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 +378,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 c4b89fa7..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", @@ -138,7 +146,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", @@ -147,21 +163,23 @@ "## 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\"" ] }, { "cell_type": "code", "execution_count": 10, - "id": "ab954c7f", + "id": "7b9a14cc", "metadata": {}, "outputs": [ { "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" ] } ], @@ -173,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", @@ -229,16 +248,6 @@ { "cell_type": "code", "execution_count": 12, - "id": "a918c4f3", - "metadata": {}, - "outputs": [], - "source": [ - "## BAD: source $BIN_DIR/tomohara-aliases.bash" - ] - }, - { - "cell_type": "code", - "execution_count": 13, "id": "0359b346", "metadata": {}, "outputs": [], @@ -249,12 +258,13 @@ "# 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)" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "e7d436e5", "metadata": {}, "outputs": [ @@ -262,7 +272,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "1\n" ] } ], @@ -277,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": [ @@ -296,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": [ @@ -316,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": [ @@ -335,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 @@ -358,8 +375,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n", - "N\n" + "0\n" ] } ], @@ -368,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": [ @@ -382,7 +402,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "C0116:\n", + "E0601:\n", "R1705:\n", "W0621:\n" ] @@ -397,7 +417,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "207d98f0", "metadata": {}, "outputs": [], @@ -409,7 +429,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "6e4b2871", "metadata": {}, "outputs": [], @@ -425,7 +445,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "id": "4a313b5a-c666-4890-9655-c6f9850bf653", "metadata": {}, "outputs": [ @@ -438,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": [ @@ -469,7 +493,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "id": "c83d89b2-c550-4430-a770-50facaba14c3", "metadata": {}, "outputs": [ @@ -477,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": [], @@ -502,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "id": "e82509c6", "metadata": {}, "outputs": [ @@ -510,28 +534,61 @@ "name": "stdout", "output_type": "stream", "text": [ - "N.N.N.N\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", - "------------------------------------------------------------------------------------------------------------------------------------\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": [], @@ -589,7 +646,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "id": "1912bb79-d984-4788-84d6-3759caf3383d", "metadata": {}, "outputs": [], @@ -600,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "30fc8ae2-fb50-4f19-908e-1178ef19776e", "metadata": { "scrolled": true @@ -623,7 +680,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "d98b6d58", "metadata": {}, "outputs": [ @@ -650,7 +707,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "93146b8d", "metadata": {}, "outputs": [ @@ -676,7 +733,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "9dcb601f", "metadata": {}, "outputs": [ @@ -704,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "8080d06d", "metadata": {}, "outputs": [ @@ -730,7 +787,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "b8c1c892", "metadata": { "scrolled": true @@ -758,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", @@ -773,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", @@ -787,7 +864,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 39, "id": "c0b6f931", "metadata": {}, "outputs": [ @@ -814,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 40, "id": "2e0b2a50-1897-4828-aafc-e743b1b95a4f", "metadata": {}, "outputs": [], @@ -827,7 +904,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 41, "id": "218b4eda-a344-432e-a2cc-4bbe6003c61f", "metadata": {}, "outputs": [], @@ -838,7 +915,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 42, "id": "cdd86ce9-6fb4-4c6f-98f8-e34d75f77942", "metadata": {}, "outputs": [ @@ -846,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" ] } ], @@ -883,7 +959,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 43, "id": "9a40ffff", "metadata": {}, "outputs": [], @@ -899,7 +975,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 44, "id": "b6e7b1d1", "metadata": {}, "outputs": [], @@ -912,7 +988,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 45, "id": "5dbc85eb", "metadata": {}, "outputs": [], @@ -943,7 +1019,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 46, "id": "9322aa5a", "metadata": {}, "outputs": [], @@ -970,7 +1046,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 47, "id": "caa3332b", "metadata": {}, "outputs": [], @@ -992,7 +1068,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 48, "id": "9c155aa3", "metadata": {}, "outputs": [], @@ -1010,7 +1086,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 49, "id": "53136103", "metadata": {}, "outputs": [], @@ -1025,7 +1101,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 50, "id": "31d1b151", "metadata": {}, "outputs": [], @@ -1037,7 +1113,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 51, "id": "3b6aab89", "metadata": {}, "outputs": [], @@ -1053,7 +1129,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 52, "id": "88b697b0-82c6-48c2-8b0d-96d922b177b6", "metadata": {}, "outputs": [], @@ -1066,7 +1142,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 53, "id": "c3845ce6-bf26-423c-81f3-356acca66f8d", "metadata": {}, "outputs": [ @@ -1101,7 +1177,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 54, "id": "833520df-e503-4131-bbdd-98bd990a9d2f", "metadata": {}, "outputs": [ @@ -1129,7 +1205,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 55, "id": "4f226d82-2376-4caf-9b40-49a742a06980", "metadata": {}, "outputs": [ @@ -1149,7 +1225,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 56, "id": "4a08ccc0-4d02-49a9-9744-ff4d2707f812", "metadata": {}, "outputs": [ @@ -1171,7 +1247,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 57, "id": "59e5fe12-c47b-4600-9487-e1a746aece67", "metadata": {}, "outputs": [ @@ -1195,7 +1271,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 58, "id": "2c5ba0e4-e09e-4703-856c-5b5c436f6d7c", "metadata": {}, "outputs": [], @@ -1205,7 +1281,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 59, "id": "df7835ca-a1c2-4ad9-9acb-4bb8a63afcbc", "metadata": {}, "outputs": [ @@ -1229,7 +1305,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 60, "id": "4c49d849-0dfe-484e-ba6c-8ee27ca755ff", "metadata": {}, "outputs": [ @@ -1251,7 +1327,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 61, "id": "d1ea335b-91bd-4016-8456-6dbfb6f0aaf3", "metadata": {}, "outputs": [ @@ -1259,7 +1335,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "0\n" ] } ], @@ -1268,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": [], @@ -1284,7 +1365,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 63, "id": "c57545c5", "metadata": {}, "outputs": [], @@ -1296,6 +1377,51 @@ "## DEBUG:\n", "## command pwd | sed -r \"s/\"$USER\"+/user/g\"" ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "008e51b7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "[[ \"$PWD\" = *\"/tmp/\"* ]]; echo $?" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "a3d18560", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "End\n" + ] + } + ], + "source": [ + "## 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\"" + ] } ], "metadata": { 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 ef3248ee..5628df6a 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" + "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,21 +73,16 @@ "metadata": {}, "outputs": [], "source": [ - "TMP=/tmp/test-unix-alias\n", - "BIN_DIR=$PWD/..\n", - "temp_dir=$TMP/test-2899\n", - "\n", - "## OLD\n", - "# mkdir -p \"$temp_dir\"\n", - "# cd \"$temp_dir\"\n", - "# pwd\n", - "\n", + "# Global Setup\n", + "TMP=${TMP:-/tmp}\n", + "if [ \"$DEBUG_LEVEL\" -lt 4 ]; then \n", + " TMP=/tmp/trace-unix-alias\n", + "fi\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 cd \"$temp_dir\"\n", - "\n", - "## OLD\n", - "## ALIAS FOR PRINTING SEPERATION LINES (FOR JUPYTER)\n", - "# alias linebr=\"printf '%*s\\n' \"${COLUMNS:-$(tput cols)}\" '' | tr ' ' -\"" + "## OLD: command mkdir -p \"$trash_dir\"\n", + "command cd \"$temp_dir\"" ] }, { @@ -87,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 ' ' '-'\"" ] }, { @@ -103,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 \"$?\"" ] }, { @@ -122,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 \"$?\"" ] }, { @@ -161,30 +180,15 @@ "metadata": { "scrolled": true }, - "outputs": [ - { - "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" - ] - } - ], + "outputs": [], "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", - "\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" + "echo \"Hi Dad!\" > hidad.txt" ] }, { @@ -192,19 +196,11 @@ "execution_count": 11, "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" + "## Dropped support\n", + "# do-make \"hidad.txt\"\n", + "# cat _make.log" ] }, { @@ -217,17 +213,13 @@ "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" + "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 $?" ] }, { @@ -240,7 +232,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "do-merge MODFILE1 OLDFILE MODFILE2 > NEWFILE tf1.txt tf2.txt\n" + "0\n" ] } ], @@ -253,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 $?" ] }, { @@ -318,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", @@ -336,12 +329,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "/tmp/test-unix-alias/test-2899/himom.txt\n" + "1\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 $?" ] }, { @@ -354,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 $?" ] }, { @@ -398,10 +393,10 @@ "name": "stdout", "output_type": "stream", "text": [ + "Linux\n", "Real: 0.00 seconds\n", "User: 0.00 seconds\n", - "Sys: 0.00 seconds\n", - "Linux\n" + "Sys: 0.00 seconds\n" ] } ], @@ -429,7 +424,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "VERSION_ID=\"N\"\n" + "VERSION_ID=\"N.N\"\n" ] } ], @@ -449,13 +444,7 @@ "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" + "system_status.sh: command not found\n" ] } ], @@ -557,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" ] }, { @@ -579,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 $?" ] }, { @@ -597,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!'" @@ -628,6 +620,7 @@ } ], "source": [ + "# OLD: perl-print '2\\n3\\n5\\n7\\n11'\n", "perl-print '2\\n3\\n5\\n7\\n11'" ] }, @@ -641,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 $? " ] }, { @@ -659,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 $? " ] }, { @@ -701,10 +696,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Tue Sep 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: Tue Sep N N:N:N PM +N N\n" + "end: Tue Apr N N:N:N PM +N N\n" ] } ], @@ -731,10 +726,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "start: Tue Sep 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: Tue Sep N N:N:N PM +N N\n" + "end: Tue Apr N N:N:N PM +N N\n" ] } ], @@ -756,8 +751,7 @@ "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", + "hidad.txt himom.txt \u001b[0m\u001b[01;34mtestfolder\u001b[0m tf1.txt tf2.txt tf3.txt\n", "'tf2.txt' -> 'testfolder/tf2.txt'\n" ] } @@ -803,8 +797,7 @@ "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" + "hidad.txt.gz himom.txt.gz testfolder\ttf1.txt.gz tf2.txt.gz\ttf3.txt.gz\n" ] } ], @@ -840,8 +833,7 @@ "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" + "hidad.txt himom.txt testfolder tf1.txt tf2.txt tf3.txt\n" ] } ], @@ -877,8 +869,7 @@ "name": "stdout", "output_type": "stream", "text": [ - ".txt\tN\n", - ".log\tN\n" + ".txt\tN\n" ] } ], @@ -900,8 +891,7 @@ "name": "stdout", "output_type": "stream", "text": [ - ".txt\tN\n", - ".log\tN\n" + ".txt\tN\n" ] } ], @@ -929,12 +919,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "Done!\n" + "Done\n" ] } ], "source": [ - "echo \"Done!\"" + "## 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 84ef8ea2..e755b148 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_YMJHFZGOKIZS\\[\\]>\n" ] } ], @@ -84,34 +85,31 @@ { "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": [], + "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", - "temp_dir=$TMP/test-3245\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", @@ -119,8 +117,10 @@ "# cd \"$temp_dir\"\n", "# pwd\n", "\n", + "rename-with-file-date \"$temp_dir\"\n", "command mkdir -p \"$temp_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", @@ -130,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "ec6df159", "metadata": { "scrolled": true @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "85787c44", "metadata": {}, "outputs": [ @@ -174,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "15465d13", "metadata": { "scrolled": true @@ -188,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "3c57d3b0", "metadata": {}, "outputs": [ @@ -196,7 +196,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "ps_mine.sh: command not found\n", + "1\n" ] } ], @@ -206,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "2395c71a", "metadata": { "scrolled": false @@ -216,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" ] } ], @@ -238,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "bc13426e", "metadata": {}, "outputs": [ @@ -246,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" ] } ], @@ -267,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "b688da20", "metadata": {}, "outputs": [ @@ -275,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" ] } ], @@ -296,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "775ea494", "metadata": {}, "outputs": [ @@ -304,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" ] } ], @@ -314,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 $?;" @@ -325,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "6ed9a120", "metadata": {}, "outputs": [ @@ -333,7 +346,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "ps_mine.sh: command not found\n", + "1\n" ] } ], @@ -353,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "bf36bf1a", "metadata": {}, "outputs": [ @@ -373,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "f7af5f4b", "metadata": {}, "outputs": [ @@ -394,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "e73cd7c1", "metadata": {}, "outputs": [], @@ -410,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "079b0855", "metadata": {}, "outputs": [ @@ -433,7 +447,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "1e7238c8", "metadata": {}, "outputs": [], @@ -447,7 +461,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "7762153f", "metadata": {}, "outputs": [ @@ -460,6 +474,7 @@ } ], "source": [ + "## OLD: command mv -f * \"$trash_dir\"\n", "echo \"Done\"" ] } 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