def testproposedChangeStarCompare(self):
     comparator = Comparator(self.Star3, self.Star2, "eu")
     result = comparator.proposedChangeStarCompare()
     resultNames = [
         result[0].get_object_name(), result[1].get_object_name()
     ]
     answer = [self.planet1.name, self.planet3.name]
     print(resultNames, answer)
     self.assertTrue(
         len(resultNames) == len(answer) and all(
             resultNames.count(i) == answer.count(i) for i in resultNames))
 def testSQLjoin(self):
     comparator = Comparator(self.planet2, self.planet1, "eu")
     result = comparator.sqlJoin(True)
     a = result["data"]
     b = ["mass", "temperature"]
     self.assertTrue(
         len(a) == len(b) and all(a.count(i) == b.count(i) for i in a))
     c = result["left"]
     d = [12, 145]
     self.assertTrue(
         len(c) == len(d) and all(c.count(i) == d.count(i) for i in c))
     e = result["right"]
     f = [10, "N/A"]
     self.assertTrue(
         len(e) == len(f) and all(e.count(i) == f.count(i) for i in e))
 def testStarCompareEmptyStarsPlanetN(self):
     comparator = Comparator(self.EStar1, self.EStar2, "eu")
     result = comparator.starCompare()
     self.assertEqual(result["planetN"]["left"], [])
     self.assertEqual(result["planetN"]["right"], [])
 def testStarCompareEmptyStarsStarC(self):
     comparator = Comparator(self.EStar1, self.EStar2, "eu")
     result = comparator.starCompare()
     self.assertEqual(result["starC"], {})
 def testStarCompareWithNonStarObjects(self):
     comparator = Comparator(self.planet1, self.planet2, "eu")
     try:
         comparator.starCompare()
     except ObjectTypeIncompatibleException:
         self.assertTrue(True)
 def testInnerJoinDiffFieldDiff(self):
     comparator = Comparator(self.planet1, self.planet3, "eu")
     inner = comparator.innerJoinDiff()
     self.assertEqual(inner, {})
 def testInnerJoinDiffFieldMatch(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     inner = comparator.innerJoinDiff()
     self.assertEqual(inner, {'mass': (100, 112)})
 def testCreateComparatorWithDifferentPlanetaryObjects(self):
     try:
         rip = Comparator(self.planet1, self.Star1, "eu")
     except ObjectTypeMismatchException:
         self.assertTrue(True)
 def testCreateComparatorWithNonPlanetaryObjects(self):
     try:
         rip = Comparator("egg", 1, "eu")
     except ObjectTypeMismatchException:
         self.assertTrue(True)
 def testStarCompareStarWithOneFieldPlanetA(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     result = comparator.starCompare()
     planetA = result["planetA"]
     answer = {"planet1": self.planet1, "planet3": self.planet3}
     self.assertEqual(planetA, answer)
 def testStarCompareStarWithOneFieldPlanetDC(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     result = comparator.starCompare()
     planetDC = result["planetDC"]
     answer = {}
     self.assertEqual(planetDC, answer)
 def testStarCompareStarWithOneFieldStarN2(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     result = comparator.starCompare()
     planetN = result["planetN"]
     answer = {"left": [], "right": [self.planet4]}
     self.assertEqual(planetN, answer)
 def testStarCompareStarWithOneFieldStarN(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     result = comparator.starCompare()
     starN = result["starN"]
     answer = {"data": ["mass"], "left": [100.0], "right": [112.0]}
     self.assertEqual(starN, answer)
 def testStarCompareStarWithOneFieldStarC(self):
     comparator = Comparator(self.Star1, self.Star2, "eu")
     result = comparator.starCompare()
     starC = result["starC"]
     answer = {"mass": (100.0, 112.0)}
     self.assertEqual(starC, answer)
def update():
    '''() -> NoneType
    Method for updating system from remote databases and generating
    proposed changes. Network connection required.
    Returns NoneType
    '''
    # postpone all currently pending changes
    STORAGE.write_changes_to_memory([])
    # open exoplanet catalogue
    global CHANGES
    CHANGES = []
    try:
        XML.downloadXML(XML_path)
    except urllib.error.URLError:
        print("No internet connection\n")
        return
    OEC_lists = XML.buildSystemFromXML(XML_path)
    OEC_systems = OEC_lists[0]
    OEC_stars = OEC_lists[1]
    OEC_planets = OEC_lists[2]

    # delete text files from previous update
    clean_files()

    # targets:
    # Saves nasa database into a text file named nasa_file
    NASA_getter = API.apiGet(NASA_link, nasa_file)
    try:
        NASA_getter.getFromAPI("&table=planets")
    # NASA_getter.getFromAPI("")
    except (TimeoutError, API.CannotRetrieveDataException) as e:
        print("NASA archive is unreacheable.\n")
    except (urllib.error.URLError):
        print("No internet connection.\n")

    # Saves exoplanetEU database into a text file named exo_file
    exoplanetEU_getter = API.apiGet(exoplanetEU_link, EU_file)
    try:
        exoplanetEU_getter.getFromAPI("")
    except (TimeoutError, API.CannotRetrieveDataException) as e:
        print("exoplanet.eu is unreacheable.\n")
    except (urllib.error.URLError):
        print("No internet connection.\n")

    # build the dict of stars from exoplanet.eu
    EU_stars = CSV.buildDictStarExistingField(EU_file, "eu")
    # build the dict of stars from NASA
    NASA_stars = CSV.buildDictStarExistingField(nasa_file, "nasa")
    # build the dictionary of stars from Open Exoplanet Catalogue
    OEC_stars = XML.buildSystemFromXML(XML_path)[4]

    # clean both dictionaries
    for d in [EU_stars, NASA_stars]:
        for key in d:
            if d.get(key).__class__.__name__ != "Star":
                d.pop(key)
    # retrieve the blacklist from memory
    black_list = STORAGE.config_get("black_list")
    # add chages from EU to the list (if they are not blacklisted by the user)
    for key in EU_stars.keys():
        if key in OEC_stars.keys():
            Comp_object = COMP.Comparator(EU_stars.get(key),
                                          OEC_stars.get(key), "eu")
            LIST = Comp_object.proposedChangeStarCompare()
            for C in LIST:
                if (not C in black_list) and (not C in CHANGES):
                    CHANGES.append(C)

    # add chages from NASA to the list
    for key in NASA_stars.keys():
        if key in OEC_stars.keys():
            Comp_object = COMP.Comparator(NASA_stars.get(key),
                                          OEC_stars.get(key), "nasa")
            LIST = Comp_object.proposedChangeStarCompare()
            for C in LIST:
                if (not C in black_list) and (not C in CHANGES):
                    CHANGES.append(C)

    # sort the list of proposed changes
    CHANGES = PC.merge_sort_changes(CHANGES)
    # write the list of proposed changes to memory using storage_manager
    STORAGE.write_changes_to_memory(CHANGES)
    # calculate current time
    curr_time = datetime.datetime.strftime(datetime.datetime.now(),
                                           '%Y-%m-%d %H:%M:%S')
    STORAGE.config_set("last_update", curr_time)
    print("\nNumber of differences discovered : " + str(len(CHANGES)))
    print("Current time : " + curr_time)
    print("Update complete.\n")