How to use clique method in SeleniumBase

Best Python code snippet using SeleniumBase

clique_unittest.py

Source:clique_unittest.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (c) 2012 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5'''Unit tests for grit.clique'''6import os7import sys8if __name__ == '__main__':9 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))10import re11import StringIO12import unittest13from grit import clique14from grit import exception15from grit import pseudo16from grit import tclib17from grit import grd_reader18from grit import util19class MessageCliqueUnittest(unittest.TestCase):20 def testClique(self):21 factory = clique.UberClique()22 msg = tclib.Message(text='Hello USERNAME, how are you?',23 placeholders=[24 tclib.Placeholder('USERNAME', '%s', 'Joi')])25 c = factory.MakeClique(msg)26 self.failUnless(c.GetMessage() == msg)27 self.failUnless(c.GetId() == msg.GetId())28 msg_fr = tclib.Translation(text='Bonjour USERNAME, comment ca va?',29 id=msg.GetId(), placeholders=[30 tclib.Placeholder('USERNAME', '%s', 'Joi')])31 msg_de = tclib.Translation(text='Guten tag USERNAME, wie geht es dir?',32 id=msg.GetId(), placeholders=[33 tclib.Placeholder('USERNAME', '%s', 'Joi')])34 c.AddTranslation(msg_fr, 'fr')35 factory.FindCliqueAndAddTranslation(msg_de, 'de')36 # sort() sorts lists in-place and does not return them37 for lang in ('en', 'fr', 'de'):38 self.failUnless(lang in c.clique)39 self.failUnless(c.MessageForLanguage('fr').GetRealContent() ==40 msg_fr.GetRealContent())41 try:42 c.MessageForLanguage('zh-CN', False)43 self.fail('Should have gotten exception')44 except:45 pass46 self.failUnless(c.MessageForLanguage('zh-CN', True) != None)47 rex = re.compile('fr|de|bingo')48 self.failUnless(len(c.AllMessagesThatMatch(rex, False)) == 2)49 self.failUnless(c.AllMessagesThatMatch(rex, True)[pseudo.PSEUDO_LANG] != None)50 def testBestClique(self):51 factory = clique.UberClique()52 factory.MakeClique(tclib.Message(text='Alfur', description='alfaholl'))53 factory.MakeClique(tclib.Message(text='Alfur', description=''))54 factory.MakeClique(tclib.Message(text='Vaettur', description=''))55 factory.MakeClique(tclib.Message(text='Vaettur', description=''))56 factory.MakeClique(tclib.Message(text='Troll', description=''))57 factory.MakeClique(tclib.Message(text='Gryla', description='ID: IDS_GRYLA'))58 factory.MakeClique(tclib.Message(text='Gryla', description='vondakerling'))59 factory.MakeClique(tclib.Message(text='Leppaludi', description='ID: IDS_LL'))60 factory.MakeClique(tclib.Message(text='Leppaludi', description=''))61 count_best_cliques = 062 for c in factory.BestCliquePerId():63 count_best_cliques += 164 msg = c.GetMessage()65 text = msg.GetRealContent()66 description = msg.GetDescription()67 if text == 'Alfur':68 self.failUnless(description == 'alfaholl')69 elif text == 'Gryla':70 self.failUnless(description == 'vondakerling')71 elif text == 'Leppaludi':72 self.failUnless(description == 'ID: IDS_LL')73 self.failUnless(count_best_cliques == 5)74 def testAllInUberClique(self):75 resources = grd_reader.Parse(76 StringIO.StringIO(u'''<?xml version="1.0" encoding="UTF-8"?>77<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">78 <release seq="3">79 <messages>80 <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">81 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?82 </message>83 </messages>84 <structures>85 <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="grit/testdata/klonk.rc" />86 <structure type="tr_html" name="ID_HTML" file="grit/testdata/simple.html" />87 </structures>88 </release>89</grit>'''), util.PathFromRoot('.'))90 resources.SetOutputLanguage('en')91 resources.RunGatherers()92 content_list = []93 for clique_list in resources.UberClique().cliques_.values():94 for clique in clique_list:95 content_list.append(clique.GetMessage().GetRealContent())96 self.failUnless('Hello %s, how are you doing today?' in content_list)97 self.failUnless('Jack "Black" Daniels' in content_list)98 self.failUnless('Hello!' in content_list)99 def testCorrectExceptionIfWrongEncodingOnResourceFile(self):100 '''This doesn't really belong in this unittest file, but what the heck.'''101 resources = grd_reader.Parse(102 StringIO.StringIO(u'''<?xml version="1.0" encoding="UTF-8"?>103<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">104 <release seq="3">105 <structures>106 <structure type="dialog" name="IDD_ABOUTBOX" file="grit/testdata/klonk.rc" />107 </structures>108 </release>109</grit>'''), util.PathFromRoot('.'))110 self.assertRaises(exception.SectionNotFound, resources.RunGatherers)111 def testSemiIdenticalCliques(self):112 messages = [113 tclib.Message(text='Hello USERNAME',114 placeholders=[tclib.Placeholder('USERNAME', '$1', 'Joi')]),115 tclib.Message(text='Hello USERNAME',116 placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')]),117 ]118 self.failUnless(messages[0].GetId() == messages[1].GetId())119 # Both of the above would share a translation.120 translation = tclib.Translation(id=messages[0].GetId(),121 text='Bonjour USERNAME',122 placeholders=[tclib.Placeholder(123 'USERNAME', '$1', 'Joi')])124 factory = clique.UberClique()125 cliques = [factory.MakeClique(msg) for msg in messages]126 for clq in cliques:127 clq.AddTranslation(translation, 'fr')128 self.failUnless(cliques[0].MessageForLanguage('fr').GetRealContent() ==129 'Bonjour $1')130 self.failUnless(cliques[1].MessageForLanguage('fr').GetRealContent() ==131 'Bonjour %s')132 def testMissingTranslations(self):133 messages = [ tclib.Message(text='Hello'), tclib.Message(text='Goodbye') ]134 factory = clique.UberClique()135 cliques = [factory.MakeClique(msg) for msg in messages]136 cliques[1].MessageForLanguage('fr', False, True)137 self.failUnless(not factory.HasMissingTranslations())138 cliques[0].MessageForLanguage('de', False, False)139 self.failUnless(factory.HasMissingTranslations())140 report = factory.MissingTranslationsReport()141 self.failUnless(report.count('WARNING') == 1)142 self.failUnless(report.count('8053599568341804890 "Goodbye" fr') == 1)143 self.failUnless(report.count('ERROR') == 1)144 self.failUnless(report.count('800120468867715734 "Hello" de') == 1)145 def testCustomTypes(self):146 factory = clique.UberClique()147 message = tclib.Message(text='Bingo bongo')148 c = factory.MakeClique(message)149 try:150 c.SetCustomType(DummyCustomType())151 self.fail()152 except:153 pass # expected case - 'Bingo bongo' does not start with 'jjj'154 message = tclib.Message(text='jjjBingo bongo')155 c = factory.MakeClique(message)156 c.SetCustomType(util.NewClassInstance(157 'grit.clique_unittest.DummyCustomType', clique.CustomType))158 translation = tclib.Translation(id=message.GetId(), text='Bilingo bolongo')159 c.AddTranslation(translation, 'fr')160 self.failUnless(c.MessageForLanguage('fr').GetRealContent().startswith('jjj'))161 def testWhitespaceMessagesAreNontranslateable(self):162 factory = clique.UberClique()163 message = tclib.Message(text=' \t')164 c = factory.MakeClique(message, translateable=True)165 self.failIf(c.IsTranslateable())166 message = tclib.Message(text='\n \n ')167 c = factory.MakeClique(message, translateable=True)168 self.failIf(c.IsTranslateable())169 message = tclib.Message(text='\n hello')170 c = factory.MakeClique(message, translateable=True)171 self.failUnless(c.IsTranslateable())172 def testEachCliqueKeptSorted(self):173 factory = clique.UberClique()174 msg_a = tclib.Message(text='hello', description='a')175 msg_b = tclib.Message(text='hello', description='b')176 msg_c = tclib.Message(text='hello', description='c')177 # Insert out of order178 clique_b = factory.MakeClique(msg_b, translateable=True)179 clique_a = factory.MakeClique(msg_a, translateable=True)180 clique_c = factory.MakeClique(msg_c, translateable=True)181 clique_list = factory.cliques_[clique_a.GetId()]182 self.failUnless(len(clique_list) == 3)183 self.failUnless(clique_list[0] == clique_a)184 self.failUnless(clique_list[1] == clique_b)185 self.failUnless(clique_list[2] == clique_c)186 def testBestCliqueSortIsStable(self):187 factory = clique.UberClique()188 text = 'hello'189 msg_no_description = tclib.Message(text=text)190 msg_id_description_a = tclib.Message(text=text, description='ID: a')191 msg_id_description_b = tclib.Message(text=text, description='ID: b')192 msg_description_x = tclib.Message(text=text, description='x')193 msg_description_y = tclib.Message(text=text, description='y')194 clique_id = msg_no_description.GetId()195 # Insert in an order that tests all outcomes.196 clique_no_description = factory.MakeClique(msg_no_description,197 translateable=True)198 self.failUnless(factory.BestClique(clique_id) == clique_no_description)199 clique_id_description_b = factory.MakeClique(msg_id_description_b,200 translateable=True)201 self.failUnless(factory.BestClique(clique_id) == clique_id_description_b)202 clique_id_description_a = factory.MakeClique(msg_id_description_a,203 translateable=True)204 self.failUnless(factory.BestClique(clique_id) == clique_id_description_a)205 clique_description_y = factory.MakeClique(msg_description_y,206 translateable=True)207 self.failUnless(factory.BestClique(clique_id) == clique_description_y)208 clique_description_x = factory.MakeClique(msg_description_x,209 translateable=True)210 self.failUnless(factory.BestClique(clique_id) == clique_description_x)211class DummyCustomType(clique.CustomType):212 def Validate(self, message):213 return message.GetRealContent().startswith('jjj')214 def ValidateAndModify(self, lang, translation):215 is_ok = self.Validate(translation)216 self.ModifyEachTextPart(lang, translation)217 def ModifyTextPart(self, lang, text):218 return 'jjj%s' % text219if __name__ == '__main__':...

Full Screen

Full Screen

test_clique.py

Source:test_clique.py Github

copy

Full Screen

...21 `G` is a NetworkX graph. `nodes` is an iterable of nodes in22 `G`.23 """24 return G.subgraph(nodes).number_of_edges() == 025def is_clique(G, nodes):26 """Returns True if and only if `nodes` is an independent set27 in `G`.28 `G` is an undirected simple graph. `nodes` is an iterable of29 nodes in `G`.30 """31 H = G.subgraph(nodes)32 n = len(H)33 return H.number_of_edges() == n * (n - 1) // 234class TestCliqueRemoval(object):35 """Unit tests for the36 :func:`~networkx.algorithms.approximation.clique_removal` function.37 """38 def test_trivial_graph(self):39 G = nx.trivial_graph()40 independent_set, cliques = clique_removal(G)41 assert_true(is_independent_set(G, independent_set))42 assert_true(all(is_clique(G, clique) for clique in cliques))43 # In fact, we should only have 1-cliques, that is, singleton nodes.44 assert_true(all(len(clique) == 1 for clique in cliques))45 def test_complete_graph(self):46 G = nx.complete_graph(10)47 independent_set, cliques = clique_removal(G)48 assert_true(is_independent_set(G, independent_set))49 assert_true(all(is_clique(G, clique) for clique in cliques))50 def test_barbell_graph(self):51 G = nx.barbell_graph(10, 5)52 independent_set, cliques = clique_removal(G)53 assert_true(is_independent_set(G, independent_set))54 assert_true(all(is_clique(G, clique) for clique in cliques))55class TestMaxClique(object):56 """Unit tests for the :func:`networkx.algorithms.approximation.max_clique`57 function.58 """59 def test_null_graph(self):60 G = nx.null_graph()61 eq_(len(max_clique(G)), 0)62 def test_complete_graph(self):63 graph = nx.complete_graph(30)64 # this should return the entire graph65 mc = max_clique(graph)66 eq_(30, len(mc))67 def test_maximal_by_cardinality(self):68 """Tests that the maximal clique is computed according to maximum69 cardinality of the sets.70 For more information, see pull request #1531.71 """72 G = nx.complete_graph(5)73 G.add_edge(4, 5)74 clique = max_clique(G)75 assert_greater(len(clique), 1)76 G = nx.lollipop_graph(30, 2)77 clique = max_clique(G)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful