|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #!/usr/bin/env python3
-
- from .utils import (
- execute,
- KOSMORRO,
- )
- import tempfile
- from os import path, environ
- from sys import platform
-
-
- def test_json_output():
- result = execute(
- KOSMORRO
- + ["--latitude=50.5876", "--longitude=3.0624", "-d2020-01-27", "--format=json"]
- )
- assert result.is_successful()
- assert (
- result.stdout
- == """{
- "ephemerides": [
- {
- "object": {
- "identifier": "SUN",
- "type": "STAR",
- "radius": 696342
- },
- "rise_time": "2020-01-27T07:31:00",
- "culmination_time": "2020-01-27T12:01:00",
- "set_time": "2020-01-27T16:30:00"
- },
- {
- "object": {
- "identifier": "MOON",
- "type": "SATELLITE",
- "radius": 1737.4
- },
- "rise_time": "2020-01-27T09:06:00",
- "culmination_time": "2020-01-27T14:09:00",
- "set_time": "2020-01-27T19:13:00"
- },
- {
- "object": {
- "identifier": "MERCURY",
- "type": "PLANET",
- "radius": 2439.7
- },
- "rise_time": "2020-01-27T08:10:00",
- "culmination_time": "2020-01-27T12:49:00",
- "set_time": "2020-01-27T17:28:00"
- },
- {
- "object": {
- "identifier": "VENUS",
- "type": "PLANET",
- "radius": 6051.8
- },
- "rise_time": "2020-01-27T09:01:00",
- "culmination_time": "2020-01-27T14:35:00",
- "set_time": "2020-01-27T20:10:00"
- },
- {
- "object": {
- "identifier": "MARS",
- "type": "PLANET",
- "radius": 3396.2
- },
- "rise_time": "2020-01-27T04:19:00",
- "culmination_time": "2020-01-27T08:23:00",
- "set_time": "2020-01-27T12:28:00"
- },
- {
- "object": {
- "identifier": "JUPITER",
- "type": "PLANET",
- "radius": 71492
- },
- "rise_time": "2020-01-27T06:15:00",
- "culmination_time": "2020-01-27T10:18:00",
- "set_time": "2020-01-27T14:21:00"
- },
- {
- "object": {
- "identifier": "SATURN",
- "type": "PLANET",
- "radius": 60268
- },
- "rise_time": "2020-01-27T06:56:00",
- "culmination_time": "2020-01-27T11:09:00",
- "set_time": "2020-01-27T15:22:00"
- },
- {
- "object": {
- "identifier": "URANUS",
- "type": "PLANET",
- "radius": 25559
- },
- "rise_time": "2020-01-27T10:21:00",
- "culmination_time": "2020-01-27T17:25:00",
- "set_time": "2020-01-27T00:33:00"
- },
- {
- "object": {
- "identifier": "NEPTUNE",
- "type": "PLANET",
- "radius": 24764
- },
- "rise_time": "2020-01-27T09:01:00",
- "culmination_time": "2020-01-27T14:36:00",
- "set_time": "2020-01-27T20:10:00"
- },
- {
- "object": {
- "identifier": "PLUTO",
- "type": "PLANET",
- "radius": 1185
- },
- "rise_time": "2020-01-27T06:57:00",
- "culmination_time": "2020-01-27T11:04:00",
- "set_time": "2020-01-27T15:11:00"
- }
- ],
- "moon_phase": {
- "phase": "NEW_MOON",
- "time": "2020-01-24T21:41:59.705921+00:00",
- "next": {
- "phase": "FIRST_QUARTER",
- "time": "2020-02-02T01:41:40.282275+00:00"
- }
- },
- "events": [
- {
- "objects": [
- {
- "identifier": "VENUS",
- "type": "PLANET",
- "radius": 6051.8
- },
- {
- "identifier": "NEPTUNE",
- "type": "PLANET",
- "radius": 24764
- }
- ],
- "EventType": "CONJUNCTION",
- "starts_at": "2020-01-27T20:00:23.242750+00:00",
- "ends_at": null,
- "details": null
- }
- ]
- }
- """
- )
-
-
- def test_pdf_output():
- if platform != "linux":
- # Consider it works everywhere if it does at least on Linux
- return
-
- tmp_dir = tempfile.mkdtemp()
- result = execute(
- KOSMORRO
- + [
- "--latitude=50.5876",
- "--longitude=3.0624",
- "-d2020-01-27",
- "--format=pdf",
- f"--output={tmp_dir}/document.pdf",
- ]
- )
-
- if environ.get("TEXLIVE_INSTALLED") is None:
- assert not result.is_successful()
- assert (
- result.stdout
- == """Save the planet and paper!
- Consider printing your PDF document only if really necessary, and use the other side of the sheet.
- Building PDF was not possible, because some dependencies are not installed.
- Please look at the documentation at https://kosmorro.space/cli/generate-pdf/ for more information.
- """
- )
-
- return
-
- assert result.is_successful()
- assert (
- result.stdout
- == """Save the planet and paper!
- Consider printing your PDF document only if really necessary, and use the other side of the sheet.
- """
- ""
- )
-
- assert path.exists(f"{tmp_dir}/document.pdf")
|