Bläddra i källkod

test: rewrite command line tests

pull/195/head
Jérôme Deuchnord 2 år sedan
förälder
incheckning
2f6142cebe
Ingen känd nyckel hittad för denna signaturen i databasen GPG-nyckel ID: 9F72B1EF93EDE1D4
16 ändrade filer med 462 tillägg och 229 borttagningar
  1. +3
    -0
      .editorconfig
  2. +5
    -5
      .github/workflows/tests.yml
  3. +4
    -0
      .gitignore
  4. +0
    -139
      .scripts/tests-e2e.sh
  5. +1
    -1
      CONTRIBUTING.md
  6. +3
    -8
      Makefile
  7. +1
    -0
      Pipfile
  8. +74
    -75
      Pipfile.lock
  9. +6
    -1
      _kosmorro/main.py
  10. +0
    -0
      test/events.py
  11. +4
    -0
      tests/__init__.py
  12. +34
    -0
      tests/basic_command.py
  13. +44
    -0
      tests/dates.py
  14. +58
    -0
      tests/dates.t
  15. +202
    -0
      tests/position.t
  16. +23
    -0
      tests/testutil.py

+ 3
- 0
.editorconfig Visa fil

@@ -12,6 +12,9 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.t]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2



.github/workflows/e2e.yml → .github/workflows/tests.yml Visa fil

@@ -1,4 +1,4 @@
name: E2E tests
name: Tests

on:
push:
@@ -34,12 +34,12 @@ jobs:
sudo apt update
sudo apt install ruby
sudo gem install ronn
pip install -U setuptools pip requests wheel Babel
pip install -U setuptools pip requests wheel Babel pipenv
pipenv sync --dev

- name: E2E tests
- name: Run tests
run: |
export ENVIRONMENT="CI"
bash .scripts/tests-e2e.sh
make tests

- name: manpage (section 1)
run: |

+ 4
- 0
.gitignore Visa fil

@@ -14,3 +14,7 @@ coverage.xml

# Compiled internationalization files
*.mo

# Error test reports:
/tests/*.t.err
/cli-tests

+ 0
- 139
.scripts/tests-e2e.sh Visa fil

@@ -1,139 +0,0 @@
#!/bin/bash

VERSION=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' _kosmorro/__version__.py)
PYTHON_BIN=$(command -v python)
PIP_BIN=$(command -v pip)

if python3 --version > /dev/null; then
PYTHON_BIN=$(command -v python3)
PIP_BIN=$(command -v pip3)
fi

failures=''

function fail() {
failures="$failures\n\n - $1\n\n$2"
}

function run() {
eval "$1" &> /tmp/output.txt
return $?
}

function canRun() {
if [[ "$1" != "" && "$1" != "$ENVIRONMENT" ]]; then
return 1
fi

return 0
}

# Asserts that command $1 has finished with sucess
# $1: the command to run
function assertSuccess() {
if ! canRun "$2"; then
echo -n 'I'
return
fi

run "$1"
returned=$?

if [ $returned -ne 0 ]; then
fail "Failed asserting that command '$1' finishes with success, returned status $returned." "$(cat /tmp/output.txt)"
echo -n 'F'
return
fi

echo -n '.'
}

# Asserts that command $1 has finished with sucess
# $1: the command to run
function assertFailure() {
if ! canRun "$2"; then
echo -n 'I'
return
fi

run "$1"
returned=$?

if [ $returned -eq 0 ]; then
fail "Failed asserting that command '$1' finishes with failure." "$(cat /tmp/output.txt)"
echo -n 'F'
return
fi

echo -n '.'
}

mkdir -p $HOME/kosmorro/export

echo
echo "==== RUNNING E2E TESTS ===="
echo

# Create the package and install it
assertSuccess "make build"
assertSuccess "$PIP_BIN install dist/kosmorro-$VERSION.tar.gz" "CI"

KOSMORRO_COMMAND="kosmorro --debug"

assertSuccess "$KOSMORRO_COMMAND"
assertSuccess "$KOSMORRO_COMMAND -h"

assertSuccess "$KOSMORRO_COMMAND -d 2020-01-27"
assertFailure "$KOSMORRO_COMMAND -d yolo-yo-lo"
assertFailure "$KOSMORRO_COMMAND -d 2020-13-32"
assertFailure "$KOSMORRO_COMMAND --date=1789-05-05"
assertFailure "$KOSMORRO_COMMAND --date=3000-01-01"
assertSuccess "$KOSMORRO_COMMAND --date='+3y 5m3d'"
assertSuccess "$KOSMORRO_COMMAND --date='-1y3d'"
assertFailure "$KOSMORRO_COMMAND --date='+3d4m"
assertFailure "$KOSMORRO_COMMAND -date='3y'"

assertFailure "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624"

assertSuccess "$KOSMORRO_COMMAND --position=\"9F25J3H5+M8\""
assertFailure "$KOSMORRO_COMMAND --position=\"J3H5+M8\""

assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876,3.0624\""
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;-3.0624\""
assertSuccess "$KOSMORRO_COMMAND --position=\"-50.5876;-3.0624\""
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876,-3.0624\""
assertSuccess "$KOSMORRO_COMMAND --position=\"-50.5876,-3.0624\""
assertSuccess "$KOSMORRO_COMMAND --position=\"\""
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27"

assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --timezone=1"
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --timezone=-1"
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --format=json"
assertFailure "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --format=pdf"

# Environment variables
assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=1 kosmorro -d 2020-01-27"
assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=-1 kosmorro -d 2020-01-27"

# Missing dependencies, should fail
assertFailure "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document.pdf"
assertFailure "ls $HOME/kosmorro/export/document.pdf"

assertSuccess "sudo apt-get install -y texlive texlive-latex-extra" "CI"

# Dependencies installed, should not fail
assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document.pdf"
assertSuccess "ls $HOME/kosmorro/export/document.pdf"

assertSuccess "$KOSMORRO_COMMAND --position=\"50.5876;3.0624\" -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document-no-graph.pdf --no-graph"
assertSuccess "ls $HOME/kosmorro/export/document-no-graph.pdf"

# man page
assertSuccess "man --pager=cat kosmorro"

if [ "$failures" != "" ]; then
echo -e "\n$failures"
exit 2
fi

echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="

+ 1
- 1
CONTRIBUTING.md Visa fil

@@ -80,7 +80,7 @@ Kosmorro's unit tests use Python's official `unittest` module. They live in the
You can also run them by invoking the following command:

```shell
make test
make tests
```

Note: there are currently some memory leaks in the unit tests, making the result quite difficult to read. I am working to fix this.


+ 3
- 8
Makefile Visa fil

@@ -1,14 +1,9 @@
black:
pipenv run black kosmorro _kosmorro setup.py

.PHONY: test
test:
export LC_ALL=C.UTF-8; \
export LANG=C.UTF-8; \
unset KOSMORRO_LATITUDE; \
unset KOSMORRO_LONGITUDE; \
unset KOSMORRO_TIMEZONE; \
LANG=C pipenv run python3 -m coverage run -m unittest test
.PHONY: tests
tests:
pipenv run python -m unittest tests

build: manpages
python3 setup.py sdist bdist_wheel


+ 1
- 0
Pipfile Visa fil

@@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages]
babel = "*"
black = "*"
scripttest = "*"

[packages]
tabulate = "*"


+ 74
- 75
Pipfile.lock Visa fil

@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "c0f10aa43311aa11cb405e4ea09d56e767df4289654ca5eac7e8ad5d280f43e6"
"sha256": "cf762a0bcf8d764a3750ae9cfeaee7732aed6d51e90651b0429af06b2cdd5fd6"
},
"pipfile-spec": 6,
"requires": {
@@ -39,37 +39,37 @@
},
"numpy": {
"hashes": [
"sha256:1a784e8ff7ea2a32e393cc53eb0003eca1597c7ca628227e34ce34eb11645a0e",
"sha256:2ba579dde0563f47021dcd652253103d6fd66165b18011dce1a0609215b2791e",
"sha256:3537b967b350ad17633b35c2f4b1a1bbd258c018910b518c30b48c8e41272717",
"sha256:3c40e6b860220ed862e8097b8f81c9af6d7405b723f4a7af24a267b46f90e461",
"sha256:598fe100b2948465cf3ed64b1a326424b5e4be2670552066e17dfaa67246011d",
"sha256:620732f42259eb2c4642761bd324462a01cdd13dd111740ce3d344992dd8492f",
"sha256:709884863def34d72b183d074d8ba5cfe042bc3ff8898f1ffad0209161caaa99",
"sha256:75579acbadbf74e3afd1153da6177f846212ea2a0cc77de53523ae02c9256513",
"sha256:7c55407f739f0bfcec67d0df49103f9333edc870061358ac8a8c9e37ea02fcd2",
"sha256:a1f2fb2da242568af0271455b89aee0f71e4e032086ee2b4c5098945d0e11cf6",
"sha256:a290989cd671cd0605e9c91a70e6df660f73ae87484218e8285c6522d29f6e38",
"sha256:ac4fd578322842dbda8d968e3962e9f22e862b6ec6e3378e7415625915e2da4d",
"sha256:ad09f55cc95ed8d80d8ab2052f78cc21cb231764de73e229140d81ff49d8145e",
"sha256:b9205711e5440954f861ceeea8f1b415d7dd15214add2e878b4d1cf2bcb1a914",
"sha256:bba474a87496d96e61461f7306fba2ebba127bed7836212c360f144d1e72ac54",
"sha256:bebab3eaf0641bba26039fb0b2c5bf9b99407924b53b1ea86e03c32c64ef5aef",
"sha256:cc367c86eb87e5b7c9592935620f22d13b090c609f1b27e49600cd033b529f54",
"sha256:ccc6c650f8700ce1e3a77668bb7c43e45c20ac06ae00d22bdf6760b38958c883",
"sha256:cf680682ad0a3bef56dae200dbcbac2d57294a73e5b0f9864955e7dd7c2c2491",
"sha256:d2910d0a075caed95de1a605df00ee03b599de5419d0b95d55342e9a33ad1fb3",
"sha256:d5caa946a9f55511e76446e170bdad1d12d6b54e17a2afe7b189112ed4412bb8",
"sha256:d89b0dc7f005090e32bb4f9bf796e1dcca6b52243caf1803fdd2b748d8561f63",
"sha256:d95d16204cd51ff1a1c8d5f9958ce90ae190be81d348b514f9be39f878b8044a",
"sha256:e4d5a86a5257843a18fb1220c5f1c199532bc5d24e849ed4b0289fb59fbd4d8f",
"sha256:e58ddb53a7b4959932f5582ac455ff90dcb05fac3f8dcc8079498d43afbbde6c",
"sha256:e80fe25cba41c124d04c662f33f6364909b985f2eb5998aaa5ae4b9587242cce",
"sha256:eda2829af498946c59d8585a9fd74da3f810866e05f8df03a86f70079c7531dd",
"sha256:fd0a359c1c17f00cb37de2969984a74320970e0ceef4808c32e00773b06649d9"
"sha256:01721eefe70544d548425a07c80be8377096a54118070b8a62476866d5208e33",
"sha256:0318c465786c1f63ac05d7c4dbcecd4d2d7e13f0959b01b534ea1e92202235c5",
"sha256:05a0f648eb28bae4bcb204e6fd14603de2908de982e761a2fc78efe0f19e96e1",
"sha256:1412aa0aec3e00bc23fbb8664d76552b4efde98fb71f60737c83efbac24112f1",
"sha256:25b40b98ebdd272bc3020935427a4530b7d60dfbe1ab9381a39147834e985eac",
"sha256:2d4d1de6e6fb3d28781c73fbde702ac97f03d79e4ffd6598b880b2d95d62ead4",
"sha256:38e8648f9449a549a7dfe8d8755a5979b45b3538520d1e735637ef28e8c2dc50",
"sha256:4a3d5fb89bfe21be2ef47c0614b9c9c707b7362386c9a3ff1feae63e0267ccb6",
"sha256:635e6bd31c9fb3d475c8f44a089569070d10a9ef18ed13738b03049280281267",
"sha256:73101b2a1fef16602696d133db402a7e7586654682244344b8329cdcbbb82172",
"sha256:791492091744b0fe390a6ce85cc1bf5149968ac7d5f0477288f78c89b385d9af",
"sha256:7a708a79c9a9d26904d1cca8d383bf869edf6f8e7650d85dbc77b041e8c5a0f8",
"sha256:88c0b89ad1cc24a5efbb99ff9ab5db0f9a86e9cc50240177a571fbe9c2860ac2",
"sha256:8a326af80e86d0e9ce92bcc1e65c8ff88297de4fa14ee936cb2293d414c9ec63",
"sha256:8a92c5aea763d14ba9d6475803fc7904bda7decc2a0a68153f587ad82941fec1",
"sha256:91c6f5fc58df1e0a3cc0c3a717bb3308ff850abdaa6d2d802573ee2b11f674a8",
"sha256:95b995d0c413f5d0428b3f880e8fe1660ff9396dcd1f9eedbc311f37b5652e16",
"sha256:9749a40a5b22333467f02fe11edc98f022133ee1bfa8ab99bda5e5437b831214",
"sha256:978010b68e17150db8765355d1ccdd450f9fc916824e8c4e35ee620590e234cd",
"sha256:9a513bd9c1551894ee3d31369f9b07460ef223694098cf27d399513415855b68",
"sha256:a75b4498b1e93d8b700282dc8e655b8bd559c0904b3910b144646dbbbc03e062",
"sha256:c6a2324085dd52f96498419ba95b5777e40b6bcbc20088fddb9e8cbb58885e8e",
"sha256:d7a4aeac3b94af92a9373d6e77b37691b86411f9745190d2c351f410ab3a791f",
"sha256:d9e7912a56108aba9b31df688a4c4f5cb0d9d3787386b87d504762b6754fbb1b",
"sha256:dff4af63638afcc57a3dfb9e4b26d434a7a602d225b42d746ea7fe2edf1342fd",
"sha256:e46ceaff65609b5399163de5893d8f2a82d3c77d5e56d976c8b5fb01faa6b671",
"sha256:f01f28075a92eede918b965e86e8f0ba7b7797a95aa8d35e1cc8821f5fc3ad6a",
"sha256:fd7d7409fa643a91d0a05c7554dd68aa9c9bb16e186f6ccfe40d6e003156e33a"
],
"markers": "python_version >= '3.7'",
"version": "==1.21.0"
"version": "==1.21.1"
},
"openlocationcode": {
"hashes": [
@@ -205,57 +205,56 @@
},
"regex": {
"hashes": [
"sha256:0eb2c6e0fcec5e0f1d3bcc1133556563222a2ffd2211945d7b1480c1b1a42a6f",
"sha256:15dddb19823f5147e7517bb12635b3c82e6f2a3a6b696cc3e321522e8b9308ad",
"sha256:173bc44ff95bc1e96398c38f3629d86fa72e539c79900283afa895694229fe6a",
"sha256:1c78780bf46d620ff4fff40728f98b8afd8b8e35c3efd638c7df67be2d5cddbf",
"sha256:2366fe0479ca0e9afa534174faa2beae87847d208d457d200183f28c74eaea59",
"sha256:2bceeb491b38225b1fee4517107b8491ba54fba77cf22a12e996d96a3c55613d",
"sha256:2ddeabc7652024803666ea09f32dd1ed40a0579b6fbb2a213eba590683025895",
"sha256:2fe5e71e11a54e3355fa272137d521a40aace5d937d08b494bed4529964c19c4",
"sha256:319eb2a8d0888fa6f1d9177705f341bc9455a2c8aca130016e52c7fe8d6c37a3",
"sha256:3f5716923d3d0bfb27048242a6e0f14eecdb2e2a7fac47eda1d055288595f222",
"sha256:422dec1e7cbb2efbbe50e3f1de36b82906def93ed48da12d1714cabcd993d7f0",
"sha256:4c9c3155fe74269f61e27617529b7f09552fbb12e44b1189cebbdb24294e6e1c",
"sha256:4f64fc59fd5b10557f6cd0937e1597af022ad9b27d454e182485f1db3008f417",
"sha256:564a4c8a29435d1f2256ba247a0315325ea63335508ad8ed938a4f14c4116a5d",
"sha256:59506c6e8bd9306cd8a41511e32d16d5d1194110b8cfe5a11d102d8b63cf945d",
"sha256:598c0a79b4b851b922f504f9f39a863d83ebdfff787261a5ed061c21e67dd761",
"sha256:59c00bb8dd8775473cbfb967925ad2c3ecc8886b3b2d0c90a8e2707e06c743f0",
"sha256:6110bab7eab6566492618540c70edd4d2a18f40ca1d51d704f1d81c52d245026",
"sha256:6afe6a627888c9a6cfbb603d1d017ce204cebd589d66e0703309b8048c3b0854",
"sha256:791aa1b300e5b6e5d597c37c346fb4d66422178566bbb426dd87eaae475053fb",
"sha256:8394e266005f2d8c6f0bc6780001f7afa3ef81a7a2111fa35058ded6fce79e4d",
"sha256:875c355360d0f8d3d827e462b29ea7682bf52327d500a4f837e934e9e4656068",
"sha256:89e5528803566af4df368df2d6f503c84fbfb8249e6631c7b025fe23e6bd0cde",
"sha256:99d8ab206a5270c1002bfcf25c51bf329ca951e5a169f3b43214fdda1f0b5f0d",
"sha256:9a854b916806c7e3b40e6616ac9e85d3cdb7649d9e6590653deb5b341a736cec",
"sha256:b85ac458354165405c8a84725de7bbd07b00d9f72c31a60ffbf96bb38d3e25fa",
"sha256:bc84fb254a875a9f66616ed4538542fb7965db6356f3df571d783f7c8d256edd",
"sha256:c92831dac113a6e0ab28bc98f33781383fe294df1a2c3dfd1e850114da35fd5b",
"sha256:cbe23b323988a04c3e5b0c387fe3f8f363bf06c0680daf775875d979e376bd26",
"sha256:ccb3d2190476d00414aab36cca453e4596e8f70a206e2aa8db3d495a109153d2",
"sha256:d8bbce0c96462dbceaa7ac4a7dfbbee92745b801b24bce10a98d2f2b1ea9432f",
"sha256:db2b7df831c3187a37f3bb80ec095f249fa276dbe09abd3d35297fc250385694",
"sha256:e586f448df2bbc37dfadccdb7ccd125c62b4348cb90c10840d695592aa1b29e0",
"sha256:e5983c19d0beb6af88cb4d47afb92d96751fb3fa1784d8785b1cdf14c6519407",
"sha256:e6a1e5ca97d411a461041d057348e578dc344ecd2add3555aedba3b408c9f874",
"sha256:eaf58b9e30e0e546cdc3ac06cf9165a1ca5b3de8221e9df679416ca667972035",
"sha256:ed693137a9187052fc46eedfafdcb74e09917166362af4cc4fddc3b31560e93d",
"sha256:edd1a68f79b89b0c57339bce297ad5d5ffcc6ae7e1afdb10f1947706ed066c9c",
"sha256:f080248b3e029d052bf74a897b9d74cfb7643537fbde97fe8225a6467fb559b5",
"sha256:f9392a4555f3e4cb45310a65b403d86b589adc773898c25a39184b1ba4db8985",
"sha256:f98dc35ab9a749276f1a4a38ab3e0e2ba1662ce710f6530f5b0a6656f1c32b58"
"sha256:026beb631097a4a3def7299aa5825e05e057de3c6d72b139c37813bfa351274b",
"sha256:14caacd1853e40103f59571f169704367e79fb78fac3d6d09ac84d9197cadd16",
"sha256:16d9eaa8c7e91537516c20da37db975f09ac2e7772a0694b245076c6d68f85da",
"sha256:18fdc51458abc0a974822333bd3a932d4e06ba2a3243e9a1da305668bd62ec6d",
"sha256:28e8af338240b6f39713a34e337c3813047896ace09d51593d6907c66c0708ba",
"sha256:3835de96524a7b6869a6c710b26c90e94558c31006e96ca3cf6af6751b27dca1",
"sha256:3905c86cc4ab6d71635d6419a6f8d972cab7c634539bba6053c47354fd04452c",
"sha256:3c09d88a07483231119f5017904db8f60ad67906efac3f1baa31b9b7f7cca281",
"sha256:4551728b767f35f86b8e5ec19a363df87450c7376d7419c3cac5b9ceb4bce576",
"sha256:459bbe342c5b2dec5c5223e7c363f291558bc27982ef39ffd6569e8c082bdc83",
"sha256:4f421e3cdd3a273bace013751c345f4ebeef08f05e8c10757533ada360b51a39",
"sha256:577737ec3d4c195c4aef01b757905779a9e9aee608fa1cf0aec16b5576c893d3",
"sha256:57fece29f7cc55d882fe282d9de52f2f522bb85290555b49394102f3621751ee",
"sha256:7976d410e42be9ae7458c1816a416218364e06e162b82e42f7060737e711d9ce",
"sha256:85f568892422a0e96235eb8ea6c5a41c8ccbf55576a2260c0160800dbd7c4f20",
"sha256:8764a78c5464ac6bde91a8c87dd718c27c1cabb7ed2b4beaf36d3e8e390567f9",
"sha256:8935937dad2c9b369c3d932b0edbc52a62647c2afb2fafc0c280f14a8bf56a6a",
"sha256:8fe58d9f6e3d1abf690174fd75800fda9bdc23d2a287e77758dc0e8567e38ce6",
"sha256:937b20955806381e08e54bd9d71f83276d1f883264808521b70b33d98e4dec5d",
"sha256:9569da9e78f0947b249370cb8fadf1015a193c359e7e442ac9ecc585d937f08d",
"sha256:a3b73390511edd2db2d34ff09aa0b2c08be974c71b4c0505b4a048d5dc128c2b",
"sha256:a4eddbe2a715b2dd3849afbdeacf1cc283160b24e09baf64fa5675f51940419d",
"sha256:a5c6dbe09aff091adfa8c7cfc1a0e83fdb8021ddb2c183512775a14f1435fe16",
"sha256:b63e3571b24a7959017573b6455e05b675050bbbea69408f35f3cb984ec54363",
"sha256:bb350eb1060591d8e89d6bac4713d41006cd4d479f5e11db334a48ff8999512f",
"sha256:bf6d987edd4a44dd2fa2723fca2790f9442ae4de2c8438e53fcb1befdf5d823a",
"sha256:bfa6a679410b394600eafd16336b2ce8de43e9b13f7fb9247d84ef5ad2b45e91",
"sha256:c856ec9b42e5af4fe2d8e75970fcc3a2c15925cbcc6e7a9bcb44583b10b95e80",
"sha256:cea56288eeda8b7511d507bbe7790d89ae7049daa5f51ae31a35ae3c05408531",
"sha256:ea212df6e5d3f60341aef46401d32fcfded85593af1d82b8b4a7a68cd67fdd6b",
"sha256:f35567470ee6dbfb946f069ed5f5615b40edcbb5f1e6e1d3d2b114468d505fc6",
"sha256:fbc20975eee093efa2071de80df7f972b7b35e560b213aafabcec7c0bd00bd8c",
"sha256:ff4a8ad9638b7ca52313d8732f37ecd5fd3c8e3aff10a8ccb93176fd5b3812f6"
],
"version": "==2021.7.6"
"version": "==2021.8.3"
},
"scripttest": {
"hashes": [
"sha256:951cfc25219b0cd003493a565f2e621fd791beaae9f9a3bdd7024d8626419c38"
],
"index": "pypi",
"version": "==1.3"
},
"tomli": {
"hashes": [
"sha256:0713b16ff91df8638a6a694e295c8159ab35ba93e3424a626dd5226d386057be",
"sha256:be670d0d8d7570fd0ea0113bd7bb1ba3ac6706b4de062cc4c952769355c9c268"
"sha256:8dd0e9524d6f386271a36b41dbf6c57d8e32fd96fd22b6584679dc569d20899f",
"sha256:a5b75cb6f3968abb47af1b40c1819dc519ea82bcc065776a866e8d74c5ca9442"
],
"markers": "python_version >= '3.6'",
"version": "==1.0.4"
"version": "==1.2.1"
}
}
}

+ 6
- 1
_kosmorro/main.py Visa fil

@@ -35,7 +35,12 @@ def main():
print(colored(error.args[0], color="red", attrs=["bold"]))
return -1

position = get_position(args.position) if args.position not in [None, ""] else None
position = None

if args.position not in [None, ""]:
position = get_position(args.position)
elif env_vars.position not in [None, ""]:
position = get_position(env_vars.position)

if output_format == "pdf":
print(


+ 0
- 0
test/events.py Visa fil


+ 4
- 0
tests/__init__.py Visa fil

@@ -0,0 +1,4 @@
#!/usr/bin/env python3

from .basic_command import BasicCommandTestCase
from .dates import DateCommandTestCase

+ 34
- 0
tests/basic_command.py Visa fil

@@ -0,0 +1,34 @@
import unittest
import kosmorrolib
from _kosmorro.i18n import strings

from datetime import date
from .testutil import run_cmd, IntegrationTestCase


class BasicCommandTestCase(IntegrationTestCase):
def test_help(self):
for arg in ['--help', '-h']:
r = run_cmd(self.env, arg)
self.assertEqual(0, r.returncode)
self.assertTrue(
r.stdout.startswith("usage: kosmorro [-h] [--version] [--clear-cache] [--format {text,json,pdf}]")
)

def test_command_without_arguments(self):
expected_moon_phase = kosmorrolib.get_moon_phase()
r = run_cmd(self.env)

self.assertEqual(0, r.returncode)
self.assertRegex(
r.stdout,
r"^%s\n\nMoon phase: %s\n%s on .+\n\n" % (
date.today().strftime("%A %B %d, %Y"),
strings.from_moon_phase(expected_moon_phase.phase_type),
strings.from_moon_phase(expected_moon_phase.get_next_phase())
)
)


if __name__ == '__main__':
unittest.main()

+ 44
- 0
tests/dates.py Visa fil

@@ -0,0 +1,44 @@
import unittest
import kosmorrolib

from datetime import date
from .testutil import run_cmd, IntegrationTestCase
from _kosmorro.i18n import strings


class DateCommandTestCase(IntegrationTestCase):
def test_invalid_string(self):
r = run_cmd(self.env, "--date=this-is-a-highly-invalid-string", accept_non_zero=True)
self.assertEqual(255, r.returncode)
self.assertEqual(
r.stdout,
"\x1b[1m\x1b[31mThe date this-is-a-highly-invalid-string does not match "
"the required YYYY-MM-DD format or the offset format.\x1b[0m\n"
)

def test_invalid_date(self):
r = run_cmd(self.env, "--date=2020-13-32", accept_non_zero=True)
self.assertEqual(255, r.returncode)
self.assertEqual(
r.stdout,
"\x1b[1m\x1b[31mThe date 2020-13-32 is not valid: month must be in 1..12\x1b[0m\n"
)

def test_specific_date(self):
asked_date = date(2020, 1, 27)
expected_moon_phase = kosmorrolib.get_moon_phase(for_date=asked_date)

for arg in ['--date', '-d']:
r = run_cmd(self.env, "%s 2020-01-27" % arg)
self.assertRegex(
r.stdout,
r"^%s\n\nMoon phase: %s\n%s on .+\n\n" % (
asked_date.strftime("%A %B %d, %Y"),
strings.from_moon_phase(expected_moon_phase.phase_type),
strings.from_moon_phase(expected_moon_phase.get_next_phase())
)
)


if __name__ == '__main__':
unittest.main()

+ 58
- 0
tests/dates.t Visa fil

@@ -0,0 +1,58 @@
First, prepare the Python environment:
$ KOSMORRO="$TESTDIR/../kosmorro --no-colors"

---

If user tries to set an invalid a date, an error is displayed:

$ $KOSMORRO -d 2020-13-32
\x1b[1m\x1b[31mThe date 2020-13-32 is not valid: month must be in 1..12\x1b[0m (esc)
[255]

---

If user gives a date out of bound, an error is displayed:

$ $KOSMORRO --date=1789-05-05
\x1b[33mMoon phase can only be displayed between Aug 09, 1899 and Sep 26, 2053\x1b[0m (esc)
[1]

$ $KOSMORRO --date=3000-01-01
\x1b[33mMoon phase can only be displayed between Aug 09, 1899 and Sep 26, 2053\x1b[0m (esc)
[1]

---

User can give a relative date:

$ $KOSMORRO --date='+3y 5m3d'
(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday) (January|February|March|April|June|July|August|September|October|November|December) \d{1,2}, \d{4} (re)
Moon phase: .+ (re)
(.+) on (Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday) (January|February|March|April|June|July|August|September|October|November|December) \d{1,2}, \d{4} at \d{2}:\d{2} (re)
(Expected events:)? (re)
(\d{2}:\d{2} .+)? (re)
Note: All the hours are given in the UTC timezone.

$ $KOSMORRO --date='-1y3d'
(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday) (January|February|March|April|June|July|August|September|October|November|December) \d{1,2}, \d{4} (re)
Moon phase: .+ (re)
(.+) on (Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday) (January|February|March|April|June|July|August|September|October|November|December) \d{1,2}, \d{4} at \d{2}:\d{2} (re)
(Expected events:)? (re)
(\d{2}:\d{2} .+)? (re)

---

If the format of the relative date is incorrect, an error is displayed:

$ $KOSMORRO --date='+3d4m'
\x1b[1m\x1b[31mThe date +3d4m does not match the required YYYY-MM-DD format or the offset format.\x1b[0m (esc)
[255]

$ $KOSMORRO -date='3y'
\x1b[1m\x1b[31mThe date ate=3y does not match the required YYYY-MM-DD format or the offset format.\x1b[0m (esc)
[255]

+ 202
- 0
tests/position.t Visa fil

@@ -0,0 +1,202 @@
First, prepare the Python environment:
$ KOSMORRO="$TESTDIR/../kosmorro --no-colors"

---

User can give a position in Plus Code format:

$ $KOSMORRO --position="9F25J3H5+M8" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 06:01 13:54 21:47
Moon 21:04 - 03:33
Mercury 04:55 13:06 21:17
Venus 08:49 15:58 23:08
Mars 08:21 15:38 22:54
Jupiter 22:53 04:00 09:03
Saturn 22:08 02:43 07:13
Uranus 01:10 08:35 16:01
Neptune 23:34 05:24 11:09
Pluto 21:31 01:39 05:43
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

---

If the Plus Code is in a short format, then an error is displayed:

$ $KOSMORRO --position="J3H5+M8" --date="2021-07-22"
The given Plus Code seems to be a short code, please provide a full code.
[1]

---

User can give a position in the 'latitude,longitude' format:

$ $KOSMORRO --position="50.5876,3.0624" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 06:01 13:54 21:46
Moon 21:04 - 03:33
Mercury 04:55 13:06 21:17
Venus 08:49 15:58 23:07
Mars 08:21 15:38 22:54
Jupiter 22:53 04:00 09:03
Saturn 22:08 02:42 07:13
Uranus 01:10 08:35 16:00
Neptune 23:34 05:23 11:09
Pluto 21:31 01:39 05:43
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

$ $KOSMORRO --position="50.5876;-3.0624" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 06:26 14:19 22:11
Moon 21:30 00:10 03:59
Mercury 05:20 13:31 21:42
Venus 09:13 16:23 23:32
Mars 08:46 16:02 23:19
Jupiter 23:17 04:24 09:28
Saturn 22:32 03:07 07:38
Uranus 01:35 09:00 16:25
Neptune 00:02 05:48 -
Pluto 21:55 02:03 06:07
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

$ $KOSMORRO --position="-50.5876;-3.0624" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 09:59 14:19 18:39
Moon 16:31 00:12 08:54
Mercury 09:26 13:31 17:36
Venus 11:22 16:24 21:26
Mars 11:09 16:03 20:57
Jupiter 21:14 04:24 11:30
Saturn 19:24 03:07 10:46
Uranus 04:15 09:00 13:44
Neptune 23:21 05:48 12:11
Pluto 17:52 02:03 10:10
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

$ $KOSMORRO --position="50.5876,-3.0624" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 06:26 14:19 22:11
Moon 21:30 00:10 03:59
Mercury 05:20 13:31 21:42
Venus 09:13 16:23 23:32
Mars 08:46 16:02 23:19
Jupiter 23:17 04:24 09:28
Saturn 22:32 03:07 07:38
Uranus 01:35 09:00 16:25
Neptune 00:02 05:48 -
Pluto 21:55 02:03 06:07
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

$ $KOSMORRO --position="-50.5876,-3.0624" --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 09:59 14:19 18:39
Moon 16:31 00:12 08:54
Mercury 09:26 13:31 17:36
Venus 11:22 16:24 21:26
Mars 11:09 16:03 20:57
Jupiter 21:14 04:24 11:30
Saturn 19:24 03:07 10:46
Uranus 04:15 09:00 13:44
Neptune 23:21 05:48 12:11
Pluto 17:52 02:03 10:10
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

---

Giving an empty string as a position is equivalent as giving no position at all:

$ $KOSMORRO --position="" --date="2021-07-22"
Thursday July 22, 2021
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

---

If coordinates are set in the KOSMORRO_POSITION environment variable, then the '--position' argument is not needed:

$ KOSMORRO_POSITION="50.5876,-3.0624" $KOSMORRO --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 09:59 14:19 18:39
Moon 16:31 00:12 08:54
Mercury 09:26 13:31 17:36
Venus 11:22 16:24 21:26
Mars 11:09 16:03 20:57
Jupiter 21:14 04:24 11:30
Saturn 19:24 03:07 10:46
Uranus 04:15 09:00 13:44
Neptune 23:21 05:48 12:11
Pluto 17:52 02:03 10:10
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

$ KOSMORRO_POSITION="9F25J3H5+M8" $KOSMORRO --date="2021-07-22"
Thursday July 22, 2021
Object Rise time Culmination time Set time
-------- ----------- ------------------ ----------
Sun 06:01 13:54 21:47
Moon 21:04 - 03:33
Mercury 04:55 13:06 21:17
Venus 08:49 15:58 23:08
Mars 08:21 15:38 22:54
Jupiter 22:53 04:00 09:03
Saturn 22:08 02:43 07:13
Uranus 01:10 08:35 16:01
Neptune 23:34 05:24 11:09
Pluto 21:31 01:39 05:43
Moon phase: Waxing Gibbous
Full Moon on Saturday July 24, 2021 at 02:36
Note: All the hours are given in the UTC timezone.

+ 23
- 0
tests/testutil.py Visa fil

@@ -0,0 +1,23 @@
#!/usr/bin/env python3

import unittest

from abc import ABC
from scripttest import TestFileEnvironment, ProcResult

BASE_COMMAND = '../kosmorro --no-colors'


nb_runs = 0


def run_cmd(env: TestFileEnvironment, args: str = "", accept_non_zero: bool = False) -> ProcResult:
return env.run("%s %s" % (BASE_COMMAND, args), expect_stderr=True, expect_error=accept_non_zero)


class IntegrationTestCase(ABC, unittest.TestCase):
def setUp(self) -> None:
self.env = TestFileEnvironment('cli-tests')
self.env.clear()
self.env.environ['LANG'] = "C"
self.env.environ['KOSMORRO_TIMEZONE'] = "0"

Laddar…
Avbryt
Spara