Skip to content

Commit ddc11e8

Browse files
committed
version
1 parent 608f8a6 commit ddc11e8

File tree

5 files changed

+153
-156
lines changed

5 files changed

+153
-156
lines changed

dist/moon-1.1.8.tar.gz

818 KB
Binary file not shown.

moon/dialamoon.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
resource_path = '/'.join(('res', 'constants.json'))
1818
constants_string = pkg_resources.resource_string(resource_package, resource_path)
1919
CONSTANTS_JSON_DICT = json.loads(constants_string)
20-
else:
21-
# todo this is a workaround when troubleshooting importing resources with package_data
22-
CONSTANTS_JSON_DICT = {}
2320

2421
class Moon(CustomImage):
2522
def __init__(self, size=(1000,1000)):
@@ -84,10 +81,10 @@ def make_datetime(self, date, hour):
8481
def make_nasa_frame_id(self):
8582
#code logic courtesy of Ernie Wright
8683
year = self.datetime.year
87-
print("in make_nasa_frame_id:")
88-
print(self.datetime.year)
89-
print(self.svs_id)
90-
print()
84+
# print("in make_nasa_frame_id:")
85+
# print(self.datetime.year)
86+
# print(self.svs_id)
87+
# print()
9188

9289
#todo - check why we were checking that the year isn't 2019
9390
# if (year != 2019):
@@ -103,10 +100,10 @@ def make_nasa_frame_id(self):
103100
def make_moon_image_url(self):
104101
try:
105102
self.svs_id = self.SVS_ID_DICT[str(self.datetime.year)]
106-
print("in make_moon_image_url:")
107-
print("self.datetime.year is ", self.datetime.year)
108-
print("self.svs_id is ", self.svs_id)
109-
print()
103+
# print("in make_moon_image_url:")
104+
# print("self.datetime.year is ", self.datetime.year)
105+
# print("self.svs_id is ", self.svs_id)
106+
# print()
110107
except KeyError as e:
111108
years_available = sorted(self.SVS_ID_DICT.keys())
112109
requested_year = self.datetime.year
@@ -119,9 +116,9 @@ def make_moon_image_url(self):
119116
remote_json_dict = json.load(response)
120117
self.SVS_ID_DICT = remote_json_dict["SVS_ID_DICT"]
121118
self.svs_id = self.SVS_ID_DICT[str(self.datetime.year)]
122-
print(UPDATED_PACKAGE_EXISTS_WITH_YEAR_ID.format(
123-
year=requested_year
124-
))
119+
# print(UPDATED_PACKAGE_EXISTS_WITH_YEAR_ID.format(
120+
# year=requested_year
121+
# ))
125122
except:
126123
# datetime wasn't found so unset it
127124
self.datetime = None
@@ -135,7 +132,7 @@ def make_moon_image_url(self):
135132

136133

137134
self.frame_id = self.make_nasa_frame_id()
138-
print("setting frame id: ", self.frame_id)
135+
# print("setting frame id: ", self.frame_id)
139136
return self.SVS_URL_BASE.format(
140137
year_id_modulo = str(self.svs_id - self.svs_id % 100),
141138
year_id = str(self.svs_id),
@@ -165,21 +162,21 @@ def set_mooninfo_requested_year(self):
165162
return self.moon_year_info
166163

167164
def set_mooninfo_requested_date(self):
168-
try:
169-
print("going to try to update the moon_datetime_info: ")
170-
print(self.moon_datetime_info['time'])
171-
print(self.svs_id)
172-
print(self.get_moon_phase_date())
173-
print()
174-
except:
175-
print("no info yet")
165+
# try:
166+
# print("going to try to update the moon_datetime_info: ")
167+
# print(self.moon_datetime_info['time'])
168+
# print(self.svs_id)
169+
# print(self.get_moon_phase_date())
170+
# print()
171+
# except:
172+
# print("no info yet")
176173

177174
self.moon_datetime_info = self.moon_year_info[int(self.frame_id) - 1]
178-
print("just tried to update moon_datetime_info:")
179-
print(self.moon_datetime_info['time'])
180-
print(self.svs_id)
181-
print(self.get_moon_phase_date())
182-
print()
175+
# print("just tried to update moon_datetime_info:")
176+
# print(self.moon_datetime_info['time'])
177+
# print(self.svs_id)
178+
# print(self.get_moon_phase_date())
179+
# print()
183180

184181

185182

moon/tests/cache.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
# import unittest
2-
# from ..dialamoon import Moon
3-
# from ..terminal_ui import TerminalUi
4-
# from datetime import datetime
5-
# from time import sleep
6-
# import numpy
7-
# import copy
1+
import unittest
2+
from ..dialamoon import Moon
3+
from ..terminal_ui import TerminalUi
4+
from datetime import datetime
5+
from time import sleep
6+
import numpy
7+
import copy
88

9-
# class TestMoonCache(unittest.TestCase):
10-
# def test_caches_json_year_data(self):
11-
# m = Moon()
12-
# m.set_moon_datetime(date="2019-01-01")
13-
# m.make_json_year_mooninfo_url()
14-
# time1 = datetime.now()
15-
# m.set_mooninfo_requested_year()
16-
# time2 = datetime.now()
17-
# sleep(5)
18-
# time3 = datetime.now()
19-
# m.set_mooninfo_requested_year()
20-
# time4 = datetime.now()
21-
# assert (time4 - time3).seconds == 0
9+
class TestMoonCache(unittest.TestCase):
10+
def test_caches_json_year_data(self):
11+
m = Moon()
12+
m.set_moon_datetime(date="2019-01-01")
13+
m.make_json_year_mooninfo_url()
14+
time1 = datetime.now()
15+
m.set_mooninfo_requested_year()
16+
time2 = datetime.now()
17+
sleep(5)
18+
time3 = datetime.now()
19+
m.set_mooninfo_requested_year()
20+
time4 = datetime.now()
21+
assert (time4 - time3).seconds == 0
2222

2323

24-
# def test_changes_moon_image_on_second_request(self):
25-
# m = Moon()
26-
# m.set_moon_datetime("2019-01-01")
27-
# m.request_moon_image()
28-
# url1 = m.url
29-
# im1 = copy.deepcopy(m.image)
30-
# m.set_moon_datetime("2020-01-01")
31-
# url2 = m.url
32-
# m.request_moon_image()
33-
# im2 = m.image
34-
# assert url1 != url2 and not numpy.array_equal(im1,im2)
24+
def test_changes_moon_image_on_second_request(self):
25+
m = Moon()
26+
m.set_moon_datetime("2019-01-01")
27+
m.request_moon_image()
28+
url1 = m.url
29+
im1 = copy.deepcopy(m.image)
30+
m.set_moon_datetime("2020-01-01")
31+
url2 = m.url
32+
m.request_moon_image()
33+
im2 = m.image
34+
assert url1 != url2 and not numpy.array_equal(im1,im2)
3535

36-
# def test_caches_moon_image_from_first_request(self):
37-
# m = TerminalUi()
38-
# m.set_moon_datetime("2020-01-06")
39-
# m.request_moon_image()
40-
# url1 = m.url
41-
# im1 = copy.deepcopy(m.image)
42-
# m.set_moon_datetime("2020-01-01")
43-
# url2 = m.url
44-
# m.request_moon_image()
45-
# im2 = copy.deepcopy( m.image)
46-
# m.set_moon_datetime("2020-01-06")
47-
# url3 = m.url
48-
# time2 = datetime.now()
49-
# m.request_moon_image()
50-
# time3 = datetime.now()
51-
# im3 = copy.deepcopy(m.image)
52-
# assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
53-
# assert numpy.array_equal(im1,im3)
36+
def test_caches_moon_image_from_first_request(self):
37+
m = TerminalUi()
38+
m.set_moon_datetime("2020-01-06")
39+
m.request_moon_image()
40+
url1 = m.url
41+
im1 = copy.deepcopy(m.image)
42+
m.set_moon_datetime("2020-01-01")
43+
url2 = m.url
44+
m.request_moon_image()
45+
im2 = copy.deepcopy( m.image)
46+
m.set_moon_datetime("2020-01-06")
47+
url3 = m.url
48+
time2 = datetime.now()
49+
m.request_moon_image()
50+
time3 = datetime.now()
51+
im3 = copy.deepcopy(m.image)
52+
assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
53+
assert numpy.array_equal(im1,im3)
5454

55-
# def test_gets_json_year_data(self):
56-
# m = Moon()
57-
# m.set_moon_datetime("2019-01-01")
58-
# m.make_json_year_mooninfo_url()
59-
# m.set_mooninfo_requested_year()
60-
# assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'
55+
def test_gets_json_year_data(self):
56+
m = Moon()
57+
m.set_moon_datetime("2019-01-01")
58+
m.make_json_year_mooninfo_url()
59+
m.set_mooninfo_requested_year()
60+
assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'
6161

6262

63-
# def test_saves_time_getting_same_moon_image(self):
64-
# m = Moon()
65-
# m.set_moon_datetime("2019-01-01")
66-
# m.request_moon_image()
67-
# m.set_moon_datetime("2019-01-02")
68-
# m.request_moon_image()
69-
# time1 = datetime.now()
70-
# m.request_moon_image()
71-
# time2 = datetime.now()
72-
# assert (time2 - time1).seconds == 0
63+
def test_saves_time_getting_same_moon_image(self):
64+
m = Moon()
65+
m.set_moon_datetime("2019-01-01")
66+
m.request_moon_image()
67+
m.set_moon_datetime("2019-01-02")
68+
m.request_moon_image()
69+
time1 = datetime.now()
70+
m.request_moon_image()
71+
time2 = datetime.now()
72+
assert (time2 - time1).seconds == 0
7373

74-
# if __name__ == '__main__':
75-
# unittest.main()
74+
if __name__ == '__main__':
75+
unittest.main()

moon/tests/general.py

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,75 @@ def __init__(self, *args, **kwargs):
1010
super(TestMoon, self).__init__(*args, **kwargs)
1111
self.sm = Moon()
1212

13-
# def test_returns_error_for_datetime_format_issue(self):
14-
# m = Moon()
15-
# self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")
13+
def test_returns_error_for_datetime_format_issue(self):
14+
m = Moon()
15+
self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")
1616

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

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

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

37-
# def test_gets_json_for_requested_datetime(self):
38-
# m = Moon()
39-
# m.set_moon_datetime(date="2019-01-01", hour=1)
40-
# m.make_json_year_mooninfo_url()
41-
# m.set_mooninfo_requested_year()
42-
# m.set_mooninfo_requested_date()
43-
# assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'
37+
def test_gets_json_for_requested_datetime(self):
38+
m = Moon()
39+
m.set_moon_datetime(date="2019-01-01", hour=1)
40+
m.make_json_year_mooninfo_url()
41+
m.set_mooninfo_requested_year()
42+
m.set_mooninfo_requested_date()
43+
assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'
4444

45-
# def test_gets_moon_image_as_numpy_array(self):
46-
# m = Moon()
47-
# m.set_moon_datetime("2019-01-01")
48-
# m.request_moon_image()
49-
# self.assertIs(type(m.image), numpy.ndarray)
45+
def test_gets_moon_image_as_numpy_array(self):
46+
m = Moon()
47+
m.set_moon_datetime("2019-01-01")
48+
m.request_moon_image()
49+
self.assertIs(type(m.image), numpy.ndarray)
5050

51-
# def test_takes_optional_hour_arg(self):
52-
# m = Moon()
53-
# m.set_moon_datetime(hour=1)
54-
# assert m.datetime.hour == 1
51+
def test_takes_optional_hour_arg(self):
52+
m = Moon()
53+
m.set_moon_datetime(hour=1)
54+
assert m.datetime.hour == 1
5555

56-
# def test_can_get_last_hour_of_nonleap_year(self):
57-
# m = Moon()
58-
# m.set_moon_datetime(date="2019-12-31", hour=23)
59-
# m.request_moon_image()
60-
# m.make_json_year_mooninfo_url()
61-
# m.set_mooninfo_requested_year()
62-
# m.set_mooninfo_requested_date()
56+
def test_can_get_last_hour_of_nonleap_year(self):
57+
m = Moon()
58+
m.set_moon_datetime(date="2019-12-31", hour=23)
59+
m.request_moon_image()
60+
m.make_json_year_mooninfo_url()
61+
m.set_mooninfo_requested_year()
62+
m.set_mooninfo_requested_date()
6363

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

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

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

8383
def test_gets_new_moon_info_if_another_year_requested(self):
8484
m = Moon()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
setup(
99
name = 'moon',
1010
packages = find_packages(),
11-
version = '1.1.7',
11+
version = '1.1.8',
1212
license='MIT',
1313
description = 'Gets moon visualizations courtesy of SVS, NASA, Ernie Wright',
1414
long_description_content_type="text/markdown",
1515
long_description = long_description,
1616
author = 'Sadie Parker',
1717
author_email = '[email protected]',
1818
url = 'https://github.com/spacerest/moon',
19-
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_7.tar.gz',
19+
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_8.tar.gz',
2020
keywords = ['MOON', 'ART'],
2121
install_requires=[
2222
'numpy~=1.16',

0 commit comments

Comments
 (0)