def test_saves_moon_image_if_cache_toggled_on(self): m = MoonBot(cache_dir="cached_moons/") cached_img_fn = "cached_moons/2020-2-2-0.jpg" # delete the file if it already exists if os.path.isfile(cached_img_fn): os.remove(cached_img_fn) file_exists_before_check = os.path.isfile(cached_img_fn) m.get_moon(date="2020-02-02") assert not file_exists_before_check and os.path.isfile(cached_img_fn)
def test_can_get_moon_aspects(self): bot = MoonBot(cache_dir="cached_moons/") bot.set_modes("moons2",astrology=True) bot.get_moon(date="2020-02-02") bot.make_ascii_tweet() print(bot.aspects) assert bot.aspects == []
def test_finds_least_frequent_luminosity_values(self): bot = MoonBot(cache_dir="cached_moons/") bot.get_moon(date="2020-02-20") bot.set_modes(gradient_symbols="inverted_moons", astrology=True) bot.make_ascii_tweet() print(bot.least_often_gradient_value1) print(bot.least_often_gradient_value2) assert bot.least_often_gradient_value1
def test_can_get_average_luminosity_of_white_image(self): #TODO do more testing on luminosity stuff, all it does now is make histogram bot = MoonBot(cache_dir="cached_moons/") img = np.full((500, 500, 3), 255, dtype = np.uint8) #make a moon but replace it with the white img bot.get_moon(date="2020-02-20") bot.moon.image = img bot.make_histogram() bot.calculate_luminosity() assert bot.average_luminosity == 1
def test_uses_cached_moon_image_if_cache_toggled_on(self): m = MoonBot(cache_dir="cached_moons/") cached_img_fn = "cached_moons/2020-2-2-0.jpg" m.get_moon(date="2020-02-02") time_before_second_load = datetime.datetime.now() m.get_moon(date="2020-02-02") time_after_second_load = datetime.datetime.now() assert time_before_second_load - time_after_second_load \ < datetime.timedelta(milliseconds=50)
def test_can_make_accurate_gradient(self): bot = MoonBot(cache_dir="cached_moons/") #make a gradient image to test with x = np.ones((10, 10, 3)) x[:, :, 0:3] = np.random.uniform(255, 255, (3,)) y = np.ones((10, 10, 3)) y[:,:,0:3] = np.random.uniform(0, 0, (3,)) c = np.linspace(0, 1, 10)[:, None, None] gradient = x + (y - x) * c #make a moon but replace it with the gradient bot.get_moon(date="2020-02-20") bot.moon.image = gradient bot.set_modes(gradient_symbols="numbers") bot.make_ascii_tweet() assert bot.ascii_list[0] == "99" and bot.ascii_list[-1] == "00"# and int(bot.ascii_list[4][0]) + (bot.ascii_list[5][0]) == 100
def test_can_get_current_moon_sign(self): bot = MoonBot(cache_dir="cached_moons/") bot.get_moon(date="2020-02-02") bot.set_astrology_info() assert bot.moon_sign == "Taurus"
def test_can_import_astrology_settings(self): bot = MoonBot(cache_dir="cached_moons/") bot.set_modes("moons2",astrology=True) bot.get_moon(date="2020-02-02") bot.make_ascii_tweet() assert bot.astrology_ascii_dict["element"] == "earth"
from moon_bot import MoonBot, TESS_CONFIG import cv2 import pytesseract from pytesseract import Output bot = MoonBot() bot.get_test_moon() bot.draw_contours() cv2.imwrite("contourmoon.jpg", bot.moon.image) bot.get_image_tiles(bot.moon.image, 5) bot.map_tiles_to_chars(bot.tiles) #bot.get_moon() #bot.get_random_image(url=URL) #cv2.imwrite("moon.png", bot.moon.image) #bot.get_text() #print(bot.text)
def test_errors_if_no_cached_img_dir(self): m = MoonBot(cache_dir="doesnt_exist/") self.assertRaises(OSError, m.get_moon)
def test_can_toggle_cache_moon_images(self): m = MoonBot(cache_dir="cached_moons/") assert m.cache_dir
def test_errors_if_json_file_empty(self): m = MoonBot(cache_dir="cached_moons/") with open("cached_moons/mooninfo_2021.json", 'w') as f: f.write("") self.assertRaises(ValueError, m.get_moon, date="2021-02-02")
def test_saves_json_if_cache_toggled_on(self): m = MoonBot(cache_dir="cached_moons/") m.get_moon(date="2020-02-02") json_file_exists = os.path.isfile("cached_moons/mooninfo_2020.json") assert json_file_exists
def test_gets_moon_datetime_info_json_if_cache_toggled_on(self): m = MoonBot(cache_dir="cached_moons/") m.get_moon(date="2020-02-02") m.set_moon_info_caption() assert m.moon.moon_datetime_info is not None