示例#1
0
def check_args():
    """
    Checks the arguments passed into the program from terminal. It will exit
    the program and display the appropriate message if not enough arguments
    were passed in or an unsupported language name was queried.

    Returns:
        None.
    """
    error_msg = ""
    if len(sys.argv) < 3:
        error_msg = ("WRONG FORMAT. You should pass in the programming" +
                     " langauge name as the first argument, a class as" +
                     " the second argument, and an optional method name" +
                     " in the third argument.")
    else:
        language, _ = get_query(sys.argv)
        if language not in app.doc_websites.websites:
            error_msg = ("Unfortunately, " +
                         Text.magenta_text(Text.magenta_text(language)) +
                         " is not a programming language that is currently" +
                         " supported by DoCLine. :(")
    if error_msg:
        print_doc(error_msg)
        exit(0)
示例#2
0
 def test_assess_coding_neutral(self):
     j1 = Text("irrelevant words")
     self.assertFalse(j1.masculine_word_count)
     self.assertFalse(j1.feminine_word_count)
     self.assertEqual(j1.coding, "neutral")
     j2 = Text("sharing versus aggression")
     self.assertEqual(j2.masculine_word_count, j2.feminine_word_count)
     self.assertEqual(j2.coding, "neutral")
示例#3
0
def main():
    """
    Main logic of the program.

    Returns:
        None.
    """
    colorama.init()
    check_args()
    language, query = get_query(sys.argv)
    doc_url = app.doc_websites.websites[language]
    google_search_url = app.web_scraper.query_to_google_url(query, doc_url)
    google_html = app.web_scraper.get_website_html(google_search_url)
    soup = BeautifulSoup(google_html, 'html.parser')
    first_res = soup.find_all('div', class_='g')[0]
    url = first_res.find('a')['href']  # May return URL with some header.
    url = app.web_scraper.fix_href_url(url)  # Fix the URL.
    # Check if the website allows us to scrape it for information.
    if not app.web_scraper.website_allows_scraping(url):
        text = ("Unfortunately, the documentation website for " +
                Text.magenta_text(language) + " does not allow scraping." +
                "The program will now exit.")
        print text
        exit(0)
    doc_html = app.web_scraper.get_website_html(url)
示例#4
0
 def test_extract_coded_words(self):
     j1 = Text(u"Ambition:competition-decisiveness, empathy&kindness")
     self.assertEqual(j1.masculine_coded_words,
                      "ambition,competition,decisiveness")
     self.assertEqual(j1.masculine_word_count, 3)
     self.assertEqual(j1.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j1.feminine_word_count, 2)
     j2 = Text(u"empathy&kindness")
     self.assertEqual(j2.masculine_coded_words, "")
     self.assertEqual(j2.masculine_word_count, 0)
     self.assertEqual(j2.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j2.feminine_word_count, 2)
     j3 = Text(u"empathy irrelevant words kindness")
     self.assertEqual(j3.masculine_coded_words, "")
     self.assertEqual(j3.masculine_word_count, 0)
     self.assertEqual(j3.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j3.feminine_word_count, 2)
示例#5
0
    def test_list_words(self):
        text = Text(u"leader leader leader, ambition, ambition, competition")
        j1 = JobAd(text, "", "", "")

        masc_words, fem_words = j1.list_words()
        self.assertEqual(
            masc_words,
            ['leader (3 times)', 'ambition (2 times)', 'competition'])
示例#6
0
    def test_results_view(self):
        j1 = JobAd(Text(u"analytical, empathy, sharing"), "fritz", "fritz AG",
                   "*****@*****.**")

        data = self.client.get('/results/' + j1.hash)
        self.assert200(data)
        self.assert_template_used('results.html')
        self.assert_context("feminine_coded_words", ['empathy', 'sharing'])
        self.assert_context("masculine_coded_words", ['analytical'])
示例#7
0
 def test_assess_coding_feminine(self):
     j1 = Text(u"Ambition:competition, empathy&kindness, co-operation")
     self.assertEqual(j1.masculine_word_count, 2)
     self.assertEqual(j1.feminine_word_count, 3)
     self.assertEqual(j1.coding, "feminine-coded")
     j2 = Text(u"empathy&kindness, co-operation and some other words")
     self.assertEqual(j2.masculine_word_count, 0)
     self.assertEqual(j2.feminine_word_count, 3)
     self.assertEqual(j2.coding, "feminine-coded")
     j3 = Text(u"empathy&kindness, co-operation, trust and other words")
     self.assertEqual(j3.masculine_word_count, 0)
     self.assertEqual(j3.feminine_word_count, 4)
     self.assertEqual(j3.coding, "strongly feminine-coded")
     j4 = Text(
         u"Ambition:competition, empathy&kindness and"
         " responsibility, co-operation, honesty, trust and other words")
     self.assertEqual(j4.masculine_word_count, 2)
     self.assertEqual(j4.feminine_word_count, 6)
     self.assertEqual(j4.coding, "strongly feminine-coded")
示例#8
0
 def test_assess_coding_masculine(self):
     j1 = Text(u"Ambition:competition-decisiveness, empathy&kindness")
     self.assertEqual(j1.masculine_word_count, 3)
     self.assertEqual(j1.feminine_word_count, 2)
     self.assertEqual(j1.coding, "masculine-coded")
     j2 = Text(u"Ambition:competition-decisiveness, other words")
     self.assertEqual(j2.masculine_word_count, 3)
     self.assertEqual(j2.feminine_word_count, 0)
     self.assertEqual(j2.coding, "masculine-coded")
     j3 = Text(u"Ambition:competition-decisiveness&leadership, other words")
     self.assertEqual(j3.masculine_word_count, 4)
     self.assertEqual(j3.feminine_word_count, 0)
     self.assertEqual(j3.coding, "strongly masculine-coded")
     # NB: repeated "decisiveness" in j4
     j4 = Text(u"Ambition:competition-decisiveness&leadership,"
               " decisiveness, stubborness, sharing and empathy")
     self.assertEqual(j4.masculine_word_count, 6)
     self.assertEqual(j4.feminine_word_count, 2)
     self.assertEqual(j4.coding, "strongly masculine-coded")
示例#9
0
def print_doc(doc):
    """
    Args:
        doc: A string representation of documentation.

    Returns:
        None. Prints out the documentation in a readable and colored format.
    """
    doc_text = Text(doc)
    print doc_text
示例#10
0
 def test_analyse(self):
     j1 = Text(u"Ambition:competition-decisiveness&leadership,"
               " decisiveness, stubborness, sharing and empathy")
     self.assertEqual(
         j1.ad_text, u"Ambition:competition-decisiveness"
         "&leadership, decisiveness, stubborness, sharing and empathy")
     self.assertTrue(j1.coding == "strongly masculine-coded")
     self.assertEqual(j1.masculine_word_count, 6)
     self.assertEqual(
         j1.masculine_coded_words, "ambition,competition,"
         "decisiveness,leadership,decisiveness,stubborness")
     self.assertEqual(j1.feminine_word_count, 2)
     self.assertEqual(j1.feminine_coded_words, "sharing,empathy")
    def __gameOver(self):
        """
        Desenha uma tela de fim de jogo.
        """

        # Cria os textos.
        game_over_text = Text(self.__window, self.FONT, 60)
        game_over_text_size = game_over_text.size("GAME OVER")

        score_text = Text(self.__window, self.FONT, 100)
        score_text_size = score_text.size(self.__score)

        self.__play = False

        # Permanece na tela de fim de jogo enquanto o usuário não pedir
        # para sair ou para iniciar um novo jogo.
        while not self.__stop and not self.__play:

            self.draw()

            h_width = self.WINDOW_GEOMETRY[0] // 2
            h_height = self.WINDOW_GEOMETRY[1] // 2

            # Desenha os textos na tela.
            game_over_text.draw(h_width - game_over_text_size[0] // 2,
                                10,
                                "GAME OVER", (255, 0, 0),
                                outline=1)

            score_text.draw(h_width - score_text_size[0] // 2,
                            h_height - score_text_size[1] // 2,
                            self.__score, (255, 255, 0),
                            outline=2)

            self.update()

        # Verifica se o jogador pediu para sair.
        if not self.close():
            self.start()
示例#12
0
def home():
    form = JobAdForm()
    if request.method == "POST" and form.validate_on_submit():
        text = Text(form.texttotest.data)
        ad = JobAd(text, form.name.data, form.company.data, form.email.data)

        send_email(
            app.config['EMAIL_TO_NOTIFY'],
            dict(text=ad.ad_text,
                 name=ad.name,
                 company=ad.company,
                 email=ad.email,
                 hash=ad.hash))

        return redirect('results/{0}'.format(ad.hash))
    return render_template('home.html', form=form)
示例#13
0
    def test_job_ad_saved(self):
        j1 = JobAd(Text(u"analytical, empathy, sharing"), "fritz", "fritz AG",
                   "*****@*****.**")

        self.assertEqual(1, JobAd.query.count())
        dbjobad = JobAd.query.first()

        self.assertEqual("analytical, empathy, sharing", dbjobad.ad_text)
        self.assertEqual(1, dbjobad.masculine_word_count)
        self.assertEqual(2, dbjobad.feminine_word_count)
        self.assertEqual("empathy,sharing", dbjobad.feminine_coded_words)
        self.assertEqual("analytical", dbjobad.masculine_coded_words)
        self.assertEqual("fritz", dbjobad.name)
        self.assertEqual("fritz AG", dbjobad.company)
        self.assertEqual("*****@*****.**", dbjobad.email)
        self.assertIsNotNone(dbjobad.hash)
        self.assertIsNotNone(dbjobad.date)
示例#14
0
 def test_clean_up_word_list(self):
     caps = Text("Sharing is as important as ambition")
     self.assertEqual(
         caps.clean_up_word_list(),
         ['sharing', 'is', 'as', 'important', 'as', 'ambition'])
     tab = Text("Qualities: sharing\tambition")
     self.assertEqual(tab.clean_up_word_list(),
                      ['qualities', 'sharing', 'ambition'])
     semicolon = Text("Sharing;ambitious")
     self.assertEqual(semicolon.clean_up_word_list(),
                      ['sharing', 'ambitious'])
     slash = Text(u"Sharing/ambitious")
     self.assertEqual(slash.clean_up_word_list(), ['sharing', 'ambitious'])
     hyphen = Text(u"Sharing, co-operative, 'servant-leader'")
     self.assertEqual(hyphen.clean_up_word_list(),
                      ['sharing', 'co-operative', 'servant', 'leader'])
     mdash = Text(u"Sharing—ambitious")
     self.assertEqual(mdash.clean_up_word_list(), ['sharing', 'ambitious'])
     bracket = Text(u"Sharing(ambitious) and (leader)")
     self.assertEqual(bracket.clean_up_word_list(),
                      ['sharing', 'ambitious', 'and', 'leader'])
     sqbracket = Text(u"Sharing[ambitious] and [leader]")
     self.assertEqual(sqbracket.clean_up_word_list(),
                      ['sharing', 'ambitious', 'and', 'leader'])
     abracket = Text(u"Sharing<ambitious> and <leader>")
     self.assertEqual(abracket.clean_up_word_list(),
                      ['sharing', 'ambitious', 'and', 'leader'])
     space = Text(u"Sharing ambitious ")
     self.assertEqual(space.clean_up_word_list(), ['sharing', 'ambitious'])
     amp = Text(u"Sharing&ambitious, empathy&kindness,")
     self.assertEqual(amp.clean_up_word_list(),
                      ['sharing', 'ambitious', 'empathy', 'kindness'])
     asterisk = Text(u"Sharing&ambitious*, empathy*kindness,")
     self.assertEqual(asterisk.clean_up_word_list(),
                      ['sharing', 'ambitious', 'empathy', 'kindness'])
     atandquestion = Text(u"Lead \"Developer\" Who is Connect@HBS? We ")
     self.assertEqual(
         atandquestion.clean_up_word_list(),
         ['lead', 'developer', 'who', 'is', 'connect', 'hbs', 'we'])
     exclaim = Text(u"Lead Developer v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
                      ['lead', 'developer', 'v', 'good'])
     curls = Text(u"“Lead” ‘Developer’ v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
                      ['lead', 'developer', 'v', 'good'])