Пример #1
0
    def test_wait_returns_automatically_when_empty(self):
        otto = Octopus(concurrency=1)
        otto.start()

        otto.wait(5)

        expect(otto.is_empty).to_be_true()
Пример #2
0
def main_octopus():
    from octopus import Octopus
    from ase.build import molecule
    system = molecule('H2')
    system.center(vacuum=1.5)
    system.pbc = 1
    calc = Octopus()
    system.set_calculator(calc)
    system.get_potential_energy()
    check_interface(calc)
Пример #3
0
    def test_can_get_with_auto_start(self):
        otto = Octopus(concurrency=1, auto_start=True)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue('http://www.twitter.com', handle_url_response)

        otto.wait(5)

        expect(self.response).not_to_be_null()
        expect(self.response.status_code).to_equal(200)
Пример #4
0
    def test_can_handle_cached_responses(self):
        response = Mock(status_code=200, body="whatever")

        url = 'http://www.google.com'
        otto = Octopus(concurrency=1, cache=True)
        otto.response_cache.put(url, response)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue(url, handle_url_response)

        expect(self.response).not_to_be_null()
        expect(self.response.status_code).to_equal(200)
        expect(self.response.body).to_equal("whatever")
Пример #5
0
    def test_can_handle_timeouts(self):
        url = 'http://baidu.com'
        otto = Octopus(concurrency=1, request_timeout_in_seconds=0.1)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue(url, handle_url_response)

        otto.start()

        otto.wait(5)

        expect(self.response.text).to_include('Connection to baidu.com timed out')
        expect(self.response.error).to_include('Connection to baidu.com timed out. (connect timeout=0.1)')
Пример #6
0
    def test_times_out_on_wait(self):
        otto = Octopus(concurrency=1)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue('http://www.google.com', handle_url_response)

        try:
            otto.wait(0.1)
        except TimeoutError:
            err = sys.exc_info()[1]
            expect(err).to_have_an_error_message_of("")
        else:
            assert False, "Should not have gotten this far"
Пример #7
0
def otto_cached_requests(repetitions, concurrency, urls_to_retrieve):
    message = "Retrieving URLs concurrently with Octopus with caching enabled..."
    print
    print("=" * len(message))
    print(message)
    print("=" * len(message))
    print

    otto = Octopus(concurrency=concurrency, cache=True, auto_start=True)

    for url in urls_to_retrieve:
        otto.enqueue(url, handle_url_response)

    start_time = time()
    otto.wait(0)

    return time() - start_time
def octopus_create_GET_request(urls):
    data = []
    otto = Octopus(concurrency=4,
                   auto_start=True,
                   cache=True,
                   expiration_in_seconds=10,
                   request_timeout_in_seconds=8)

    def handle_url_response(url, response):
        if "Not found" == response.text:
            print("URL Not Found: %s" % url)
        else:
            data.append(response.text)

    for url in urls:
        otto.enqueue(url, handle_url_response)
    otto.wait(25)
    return data
Пример #9
0
    def test_can_handle_cached_responses_when_not_cached(self):
        url = 'http://www.twitter.com'
        otto = Octopus(concurrency=1, cache=True)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue(url, handle_url_response)
        otto.enqueue(url, handle_url_response)
        otto.enqueue(url, handle_url_response)
        otto.enqueue(url, handle_url_response)

        otto.start()

        otto.wait(5)

        expect(self.response).not_to_be_null()
        expect(self.response.status_code).to_equal(200)
Пример #10
0
    def test_can_handle_invalid_urls(self):
        url = 'http://kagdjdkjgka.fk'
        otto = Octopus(concurrency=1)

        def handle_url_response(url, response):
            self.response = response

        otto.enqueue(url, handle_url_response)

        otto.start()

        otto.wait(5)

        expect(self.response).not_to_be_null()
        expect(self.response.status_code).to_equal(599)
        expect(self.response.text).to_include("HTTPConnectionPool(host='kagdjdkjgka.fk', port=80)")
        expect(self.response.text).to_include('Max retries exceeded with url: /')
        expect(self.response.error).to_equal(self.response.text)
Пример #11
0
def request(urls):
    data = []
    
    otto = Octopus(
            concurrency = 4, auto_start = True, cache = True, expiration_in_seconds=10
            )
    def handle_url_response(url, response):
        if "Not found" == response.text:
            print("URL Not Found: %s" %url)
        else:
            data.append(response.text)
            
    for url in urls:
        otto.enqueue(url, handle_url_response)
    otto.wait()
    
    json_data = json.JSONEncoder(indent = None,
                                 separators = (',', ':')).encode(data)
    return pprint(json_data)
Пример #12
0
    def __init__(self):
        pygame.init()
        self.settings = Settings()

        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        self.settings.screen_width = self.screen.get_rect().width
        self.settings.screen_height = self.screen.get_rect().height
        pygame.display.set_caption("Ocean Adventure")

        self.stats = GameStats(self)
        self.sb = Scoreboard(self)

        self.octopus = Octopus(self)
        self.bullets = pygame.sprite.Group()
        self.fishes = pygame.sprite.Group()

        self._create_fleet()

        self.play_button = Button(self, "Play")

        self.bg_color = (187, 230, 247)
Пример #13
0
def create_request(urls, method, kwargs):
    data = []
    otto = Octopus(
           concurrency=1, auto_start=True, cache=False, expiration_in_seconds=20
    )

    def handle_url_response(url, response):
        if "Not found" == response.text:
            print ("URL Not Found: %s" % url)
        else:
            data.append(response.text)

    for url in urls:
        otto.enqueue(url, handle_url_response, method, data=kwargs, headers={ "Content-type": "application/x-www-form-urlencoded" })

    otto.wait()

    json_data = json.JSONEncoder(indent=None,
                                 separators=(',', ': ')).encode(data)

    return json_data
Пример #14
0
def create_request(urls, buscar):
    data = []

    otto = Octopus(concurrency=10,
                   auto_start=True,
                   cache=True,
                   expiration_in_seconds=30)

    def handle_url_response(url, response):
        if "Not found" == response.text:
            print("URL Not Found: %s" % url)
        else:
            aux_dict = json.loads(response.text)
            if aux_dict["url"][-3] == '/':
                data.append((aux_dict[buscar], aux_dict["url"][-2]))
            else:
                data.append((aux_dict[buscar], aux_dict["url"][-3:-1]))

    for url in urls:
        otto.enqueue(url, handle_url_response)

    otto.wait()
    return data
Пример #15
0
    def test_can_handle_more_urls_concurrently(self):
        urls = [
            'http://www.twitter.com',
            'http://www.cnn.com',
            'http://www.bbc.com',
            'http://www.facebook.com'
        ]
        otto = Octopus(concurrency=4)

        def handle_url_response(url, response):
            self.responses[url] = response

        for url in urls:
            otto.enqueue(url, handle_url_response)

        otto.start()

        otto.wait(10)

        expect(self.responses).to_length(4)

        for url in urls:
            expect(self.responses).to_include(url)
            expect(self.responses[url].status_code).to_equal(200)
]  #categories to be tested and saved to file. These can be 'performance', 'seo', 'accessibility', 'best-practices'
threadsNumber = 15  #number of requests sent asynchronically at once

startTime = datetime.datetime.now()
print(f'Starting process - {startTime.strftime("%H:%M")}')
pathlib.Path('./results').mkdir(
    parents=True, exist_ok=True)  #create results fir if not exists
filePath = f'./results/{projectName}-{strategy} performance-{startTime.strftime("%d-%m-%Y_%H:%M:%S")}.csv'
resultsFile = open(filePath, 'w')
columnNames = "Number, URL, First Contentful Paint, First Interactive, Performance, SEO, Accessibility, Best-Practices\n"
resultsFile.write(columnNames)

# settings for octopus threads

otto = Octopus(concurrency=threadsNumber,
               auto_start=True,
               cache=True,
               request_timeout_in_seconds=30)


def handle_url_response(url, response):
    number = url.split('&num=')
    splitUrl = url.split('?url=')
    reqUrl = splitUrl[1].split('&strategy=')
    row = f'{number[1]}'
    try:
        parsedResponse = json.loads(response.text)
        contentfulPaint = parsedResponse['lighthouseResult']['audits'][
            'first-contentful-paint']['displayValue']
        firstInteractive = parsedResponse['lighthouseResult']['audits'][
            'interactive']['displayValue']
        performanceScore = parsedResponse['lighthouseResult']['categories'][
Пример #17
0
#!/usr/bin/env python3
'''
octo.py
sample octopus http for python3 training
at www.jasaplus.com
'''
from octopus import Octopus

otto = Octopus(concurrency=2, auto_start=True)


def handle_url_response(url, response):
    print(response.text)


otto.enqueue(
    'https://raw.githubusercontent.com/brandiqa/json-examples/master/src/google_markers.json',
    handle_url_response)
otto.enqueue(
    'https://raw.githubusercontent.com/brandiqa/json-examples/master/src/products.json',
    handle_url_response)
otto.wait()
Пример #18
0
    def test_can_enqueue_url(self):
        otto = Octopus()

        otto.enqueue('http://www.google.com', None)

        expect(otto.queue_size).to_equal(1)
Пример #19
0
 def test_queue_is_empty(self):
     otto = Octopus()
     expect(otto.is_empty).to_be_true()
Пример #20
0
 def test_has_default_concurrency(self):
     otto = Octopus()
     expect(otto.concurrency).to_equal(10)
Пример #21
0
 def test_can_create_octopus(self):
     otto = Octopus(concurrency=20)
     expect(otto.concurrency).to_equal(20)
     expect(otto.auto_start).to_be_false()
     expect(otto.cache).to_be_false()