Skip to content

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
spacerest committed Jan 1, 2022
1 parent 608f8a6 commit ddc11e8
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 156 deletions.
Binary file added dist/moon-1.1.8.tar.gz
Binary file not shown.
53 changes: 25 additions & 28 deletions moon/dialamoon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
resource_path = '/'.join(('res', 'constants.json'))
constants_string = pkg_resources.resource_string(resource_package, resource_path)
CONSTANTS_JSON_DICT = json.loads(constants_string)
else:
# todo this is a workaround when troubleshooting importing resources with package_data
CONSTANTS_JSON_DICT = {}

class Moon(CustomImage):
def __init__(self, size=(1000,1000)):
Expand Down Expand Up @@ -84,10 +81,10 @@ def make_datetime(self, date, hour):
def make_nasa_frame_id(self):
#code logic courtesy of Ernie Wright
year = self.datetime.year
print("in make_nasa_frame_id:")
print(self.datetime.year)
print(self.svs_id)
print()
# print("in make_nasa_frame_id:")
# print(self.datetime.year)
# print(self.svs_id)
# print()

#todo - check why we were checking that the year isn't 2019
# if (year != 2019):
Expand All @@ -103,10 +100,10 @@ def make_nasa_frame_id(self):
def make_moon_image_url(self):
try:
self.svs_id = self.SVS_ID_DICT[str(self.datetime.year)]
print("in make_moon_image_url:")
print("self.datetime.year is ", self.datetime.year)
print("self.svs_id is ", self.svs_id)
print()
# print("in make_moon_image_url:")
# print("self.datetime.year is ", self.datetime.year)
# print("self.svs_id is ", self.svs_id)
# print()
except KeyError as e:
years_available = sorted(self.SVS_ID_DICT.keys())
requested_year = self.datetime.year
Expand All @@ -119,9 +116,9 @@ def make_moon_image_url(self):
remote_json_dict = json.load(response)
self.SVS_ID_DICT = remote_json_dict["SVS_ID_DICT"]
self.svs_id = self.SVS_ID_DICT[str(self.datetime.year)]
print(UPDATED_PACKAGE_EXISTS_WITH_YEAR_ID.format(
year=requested_year
))
# print(UPDATED_PACKAGE_EXISTS_WITH_YEAR_ID.format(
# year=requested_year
# ))
except:
# datetime wasn't found so unset it
self.datetime = None
Expand All @@ -135,7 +132,7 @@ def make_moon_image_url(self):


self.frame_id = self.make_nasa_frame_id()
print("setting frame id: ", self.frame_id)
# print("setting frame id: ", self.frame_id)
return self.SVS_URL_BASE.format(
year_id_modulo = str(self.svs_id - self.svs_id % 100),
year_id = str(self.svs_id),
Expand Down Expand Up @@ -165,21 +162,21 @@ def set_mooninfo_requested_year(self):
return self.moon_year_info

def set_mooninfo_requested_date(self):
try:
print("going to try to update the moon_datetime_info: ")
print(self.moon_datetime_info['time'])
print(self.svs_id)
print(self.get_moon_phase_date())
print()
except:
print("no info yet")
# try:
# print("going to try to update the moon_datetime_info: ")
# print(self.moon_datetime_info['time'])
# print(self.svs_id)
# print(self.get_moon_phase_date())
# print()
# except:
# print("no info yet")

self.moon_datetime_info = self.moon_year_info[int(self.frame_id) - 1]
print("just tried to update moon_datetime_info:")
print(self.moon_datetime_info['time'])
print(self.svs_id)
print(self.get_moon_phase_date())
print()
# print("just tried to update moon_datetime_info:")
# print(self.moon_datetime_info['time'])
# print(self.svs_id)
# print(self.get_moon_phase_date())
# print()



Expand Down
134 changes: 67 additions & 67 deletions moon/tests/cache.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
# import unittest
# from ..dialamoon import Moon
# from ..terminal_ui import TerminalUi
# from datetime import datetime
# from time import sleep
# import numpy
# import copy
import unittest
from ..dialamoon import Moon
from ..terminal_ui import TerminalUi
from datetime import datetime
from time import sleep
import numpy
import copy

# class TestMoonCache(unittest.TestCase):
# def test_caches_json_year_data(self):
# m = Moon()
# m.set_moon_datetime(date="2019-01-01")
# m.make_json_year_mooninfo_url()
# time1 = datetime.now()
# m.set_mooninfo_requested_year()
# time2 = datetime.now()
# sleep(5)
# time3 = datetime.now()
# m.set_mooninfo_requested_year()
# time4 = datetime.now()
# assert (time4 - time3).seconds == 0
class TestMoonCache(unittest.TestCase):
def test_caches_json_year_data(self):
m = Moon()
m.set_moon_datetime(date="2019-01-01")
m.make_json_year_mooninfo_url()
time1 = datetime.now()
m.set_mooninfo_requested_year()
time2 = datetime.now()
sleep(5)
time3 = datetime.now()
m.set_mooninfo_requested_year()
time4 = datetime.now()
assert (time4 - time3).seconds == 0


# def test_changes_moon_image_on_second_request(self):
# m = Moon()
# m.set_moon_datetime("2019-01-01")
# m.request_moon_image()
# url1 = m.url
# im1 = copy.deepcopy(m.image)
# m.set_moon_datetime("2020-01-01")
# url2 = m.url
# m.request_moon_image()
# im2 = m.image
# assert url1 != url2 and not numpy.array_equal(im1,im2)
def test_changes_moon_image_on_second_request(self):
m = Moon()
m.set_moon_datetime("2019-01-01")
m.request_moon_image()
url1 = m.url
im1 = copy.deepcopy(m.image)
m.set_moon_datetime("2020-01-01")
url2 = m.url
m.request_moon_image()
im2 = m.image
assert url1 != url2 and not numpy.array_equal(im1,im2)

# def test_caches_moon_image_from_first_request(self):
# m = TerminalUi()
# m.set_moon_datetime("2020-01-06")
# m.request_moon_image()
# url1 = m.url
# im1 = copy.deepcopy(m.image)
# m.set_moon_datetime("2020-01-01")
# url2 = m.url
# m.request_moon_image()
# im2 = copy.deepcopy( m.image)
# m.set_moon_datetime("2020-01-06")
# url3 = m.url
# time2 = datetime.now()
# m.request_moon_image()
# time3 = datetime.now()
# im3 = copy.deepcopy(m.image)
# assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
# assert numpy.array_equal(im1,im3)
def test_caches_moon_image_from_first_request(self):
m = TerminalUi()
m.set_moon_datetime("2020-01-06")
m.request_moon_image()
url1 = m.url
im1 = copy.deepcopy(m.image)
m.set_moon_datetime("2020-01-01")
url2 = m.url
m.request_moon_image()
im2 = copy.deepcopy( m.image)
m.set_moon_datetime("2020-01-06")
url3 = m.url
time2 = datetime.now()
m.request_moon_image()
time3 = datetime.now()
im3 = copy.deepcopy(m.image)
assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
assert numpy.array_equal(im1,im3)

# def test_gets_json_year_data(self):
# m = Moon()
# m.set_moon_datetime("2019-01-01")
# m.make_json_year_mooninfo_url()
# m.set_mooninfo_requested_year()
# assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'
def test_gets_json_year_data(self):
m = Moon()
m.set_moon_datetime("2019-01-01")
m.make_json_year_mooninfo_url()
m.set_mooninfo_requested_year()
assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'


# def test_saves_time_getting_same_moon_image(self):
# m = Moon()
# m.set_moon_datetime("2019-01-01")
# m.request_moon_image()
# m.set_moon_datetime("2019-01-02")
# m.request_moon_image()
# time1 = datetime.now()
# m.request_moon_image()
# time2 = datetime.now()
# assert (time2 - time1).seconds == 0
def test_saves_time_getting_same_moon_image(self):
m = Moon()
m.set_moon_datetime("2019-01-01")
m.request_moon_image()
m.set_moon_datetime("2019-01-02")
m.request_moon_image()
time1 = datetime.now()
m.request_moon_image()
time2 = datetime.now()
assert (time2 - time1).seconds == 0

# if __name__ == '__main__':
# unittest.main()
if __name__ == '__main__':
unittest.main()
118 changes: 59 additions & 59 deletions moon/tests/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,75 @@ def __init__(self, *args, **kwargs):
super(TestMoon, self).__init__(*args, **kwargs)
self.sm = Moon()

# def test_returns_error_for_datetime_format_issue(self):
# m = Moon()
# self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")
def test_returns_error_for_datetime_format_issue(self):
m = Moon()
self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")

# def test_returns_helpful_error_for_datetime_range_issue(self):
# m = Moon()
# self.assertRaisesRegex(KeyError, r"Cannot find year .* in this version "\
# "of the package. This package can get moons for years .* -"\
# " .*. Please try a different year or check for an update "\
# "for this package.",
# m.set_moon_datetime, "1900-01-01")
def test_returns_helpful_error_for_datetime_range_issue(self):
m = Moon()
self.assertRaisesRegex(KeyError, r"Cannot find year .* in this version "\
"of the package. This package can get moons for years .* -"\
" .*. Please try a different year or check for an update "\
"for this package.",
m.set_moon_datetime, "1900-01-01")

# def test_makes_a_moon_image_url(self):
# m = Moon()
# m.set_moon_datetime(date="2019-01-01", hour=0)
# assert m.url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/"\
# "a004442/frames/730x730_1x1_30p/moon.0001.jpg"
def test_makes_a_moon_image_url(self):
m = Moon()
m.set_moon_datetime(date="2019-01-01", hour=0)
assert m.url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/"\
"a004442/frames/730x730_1x1_30p/moon.0001.jpg"

# def test_makes_a_json_data_url(self):
# m = Moon()
# m.set_moon_datetime("2019-01-01")
# m.make_json_year_mooninfo_url()
# assert m.json_url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/mooninfo_2019.json"
def test_makes_a_json_data_url(self):
m = Moon()
m.set_moon_datetime("2019-01-01")
m.make_json_year_mooninfo_url()
assert m.json_url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/mooninfo_2019.json"

# def test_gets_json_for_requested_datetime(self):
# m = Moon()
# m.set_moon_datetime(date="2019-01-01", hour=1)
# m.make_json_year_mooninfo_url()
# m.set_mooninfo_requested_year()
# m.set_mooninfo_requested_date()
# assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'
def test_gets_json_for_requested_datetime(self):
m = Moon()
m.set_moon_datetime(date="2019-01-01", hour=1)
m.make_json_year_mooninfo_url()
m.set_mooninfo_requested_year()
m.set_mooninfo_requested_date()
assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'

# def test_gets_moon_image_as_numpy_array(self):
# m = Moon()
# m.set_moon_datetime("2019-01-01")
# m.request_moon_image()
# self.assertIs(type(m.image), numpy.ndarray)
def test_gets_moon_image_as_numpy_array(self):
m = Moon()
m.set_moon_datetime("2019-01-01")
m.request_moon_image()
self.assertIs(type(m.image), numpy.ndarray)

# def test_takes_optional_hour_arg(self):
# m = Moon()
# m.set_moon_datetime(hour=1)
# assert m.datetime.hour == 1
def test_takes_optional_hour_arg(self):
m = Moon()
m.set_moon_datetime(hour=1)
assert m.datetime.hour == 1

# def test_can_get_last_hour_of_nonleap_year(self):
# m = Moon()
# m.set_moon_datetime(date="2019-12-31", hour=23)
# m.request_moon_image()
# m.make_json_year_mooninfo_url()
# m.set_mooninfo_requested_year()
# m.set_mooninfo_requested_date()
def test_can_get_last_hour_of_nonleap_year(self):
m = Moon()
m.set_moon_datetime(date="2019-12-31", hour=23)
m.request_moon_image()
m.make_json_year_mooninfo_url()
m.set_mooninfo_requested_year()
m.set_mooninfo_requested_date()

# assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/"\
# "frames/730x730_1x1_30p/moon.8760.jpg"
assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/"\
"frames/730x730_1x1_30p/moon.8760.jpg"

# def test_can_get_last_hour_of_year(self):
# m = Moon()
# m.set_moon_datetime(date="2020-12-31", hour=23)
# m.request_moon_image()
# assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004768/"\
# "frames/730x730_1x1_30p/moon.8784.jpg"
def test_can_get_last_hour_of_year(self):
m = Moon()
m.set_moon_datetime(date="2020-12-31", hour=23)
m.request_moon_image()
assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004768/"\
"frames/730x730_1x1_30p/moon.8784.jpg"

# def test_can_get_moon_for_2022(self):
# # note: this is just helpful for testing a version of `moon` where
# # the SVS_ID has been added to the github repo but the user
# # hasn't updated the package to include the new SVS_ID
# m = Moon()
# m.set_moon_datetime(date="2022-01-15")
# m.request_moon_image()
# assert m.SVS_ID_DICT["2022"] == 4955
def test_can_get_moon_for_2022(self):
# note: this is just helpful for testing a version of `moon` where
# the SVS_ID has been added to the github repo but the user
# hasn't updated the package to include the new SVS_ID
m = Moon()
m.set_moon_datetime(date="2022-01-15")
m.request_moon_image()
assert m.SVS_ID_DICT["2022"] == 4955

def test_gets_new_moon_info_if_another_year_requested(self):
m = Moon()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
setup(
name = 'moon',
packages = find_packages(),
version = '1.1.7',
version = '1.1.8',
license='MIT',
description = 'Gets moon visualizations courtesy of SVS, NASA, Ernie Wright',
long_description_content_type="text/markdown",
long_description = long_description,
author = 'Sadie Parker',
author_email = '[email protected]',
url = 'https://github.com/spacerest/moon',
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_7.tar.gz',
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_8.tar.gz',
keywords = ['MOON', 'ART'],
install_requires=[
'numpy~=1.16',
Expand Down

0 comments on commit ddc11e8

Please sign in to comment.