From patchwork Wed Jul 20 09:41:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Tunnicliffe X-Patchwork-Id: 2785 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 8AD5823F42 for ; Wed, 20 Jul 2011 09:41:33 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 2B81FA18694 for ; Wed, 20 Jul 2011 09:41:33 +0000 (UTC) Received: by qwb8 with SMTP id 8so27274qwb.11 for ; Wed, 20 Jul 2011 02:41:32 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr6892398qcc.148.1311154892587; Wed, 20 Jul 2011 02:41:32 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs109122qcb; Wed, 20 Jul 2011 02:41:31 -0700 (PDT) Received: by 10.216.60.144 with SMTP id u16mr16181wec.5.1311154891037; Wed, 20 Jul 2011 02:41:31 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id f58si73411wed.108.2011.07.20.02.41.30; Wed, 20 Jul 2011 02:41:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjTHV-00037P-SU for ; Wed, 20 Jul 2011 09:41:29 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id D5F292EA003 for ; Wed, 20 Jul 2011 09:41:29 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 380 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 380: Merge in branch where unit tests were moved out of fetch_image_ui.py into linaro_image_tools/test... Message-Id: <20110720094129.17419.24082.launchpad@loganberry.canonical.com> Date: Wed, 20 Jul 2011 09:41:29 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13468"; Instance="initZopeless config overlay" X-Launchpad-Hash: 5db6af2fe375db8d977745b92575c4d7e149f240 Merge authors: James Tunnicliffe (dooferlad) Related merge proposals: https://code.launchpad.net/~dooferlad/linaro-image-tools/fix_fetch_image_unit_tests/+merge/68416 proposed by: James Tunnicliffe (dooferlad) review: Approve - Guilherme Salgado (salgado) review: Resubmit - James Tunnicliffe (dooferlad) ------------------------------------------------------------ revno: 380 [merge] committer: James Tunnicliffe branch nick: linaro-image-tools timestamp: Wed 2011-07-20 10:40:02 +0100 message: Merge in branch where unit tests were moved out of fetch_image_ui.py into linaro_image_tools/tests/test_fetch_image.py. added: linaro_image_tools/tests/test_fetch_image.py modified: fetch_image_ui.py linaro_image_tools/FetchImage.py linaro_image_tools/tests/__init__.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'fetch_image_ui.py' --- fetch_image_ui.py 2011-07-14 12:50:56 +0000 +++ fetch_image_ui.py 2011-07-19 16:02:08 +0000 @@ -28,7 +28,6 @@ import os import linaro_image_tools.FetchImage as FetchImage import string -import unittest import operator import Queue import time @@ -1548,167 +1547,5 @@ w = TestDriveWizard('Simple Wizard') return w.go() - -class TestURLLookupFunctions(unittest.TestCase): - - def setUp(self): - self.file_handler = FetchImage.FileHandler() - self.file_handler.update_files_from_server() - self.config = FetchImage.FetchImageConfig() - self.config.settings["force_download"] = False - - # Load settings YAML, which defines the parameters we ask for and - # acceptable responses from the user - self.config.read_config(self.file_handler.settings_file) - - # Using the config we have, look up URLs to download data from in the - # server index - self.db = FetchImage.DB(self.file_handler.index_file) - - def test_url_lookup(self): - self.settings = self.config.settings - self.settings['release_or_snapshot'] = "snapshot" - - #--- Test first with a snapshot build lookup --- - # -- Fix a build date -- - # We only need to look up a single snapshot date. Start with today and - # go with the day in the DB, build 0 - today = wx.DateTime() - today.SetToCurrent() - - # -- Don't iterate through platforms for snapshot -- - - # -- Select hardware -- - for self.settings['hardware'] in ( - self.settings['choice']['hardware'].keys()): - - compatable_hwpacks = self.settings['choice']['hwpack'][ - self.settings['hardware']] - - future_date, past_date = self.db.get_next_prev_day_with_builds( - "linaro-alip", - today.FormatISODate().encode('ascii'), - compatable_hwpacks) - - if past_date == None: - # Some hardware packs are not available in the snapshot repo, - # so just skip if they aren't - continue - - builds = self.db.get_binary_builds_on_day_from_db( - "linaro-alip", - past_date, - compatable_hwpacks) - - self.assertTrue(len(builds)) - # If the above assert fails, either the DB is empty, or - # db.get_binary_builds_on_day_from_db failed - - small_date = re.sub('-', '', past_date) - self.settings['build'] = small_date + ":" + "0" - - # -- Iterate through hardware packs -- - for self.settings['hwpack'] in compatable_hwpacks: - - # If hardware pack is available... - if(self.settings['hwpack'] - in self.db.get_hwpacks('snapshot_hwpacks')): - - # -- Iterate through images - os_list = self.db.get_os_list_from('snapshot_binaries') - - for self.settings['image'] in os_list: - if re.search('old', self.settings['image']): - # Directories with old in the name are of no - # interest to us - continue - - # -- Check build which matches these parameters - # (builds that don't match are excluded in UI) -- - if( len(self.db.execute_return_list( - 'select * from snapshot_hwpacks ' - 'where hardware == ? ' - 'and date == ? ' - 'and build == ?', - (self.settings['hwpack'], - small_date, - "0"))) - and len(self.db.execute_return_list( - 'select * from snapshot_binaries ' - 'where image == ? ' - 'and date == ? ' - 'and build == ?', - (self.settings['image'], - small_date, - "0")))): - - # - Run the function under test! - - image_url, hwpack_url = ( - self.db.get_image_and_hwpack_urls(self.settings)) - - self.assertTrue(image_url) - self.assertTrue(hwpack_url) - - #--- Now test release build lookup --- - self.settings['release_or_snapshot'] = "release" - # -- Select hardware -- - for self.settings['hardware'] in ( - self.settings['choice']['hardware'].keys()): - compatable_hwpacks = ( - self.settings['choice']['hwpack'][self.settings['hardware']]) - - # -- Iterate through hardware packs -- - for self.settings['hwpack'] in compatable_hwpacks: - - # If hardware pack is available... - if(self.settings['hwpack'] - in self.db.get_hwpacks('release_hwpacks')): - - # -- Iterate through images - os_list = self.db.get_os_list_from('release_binaries') - - for self.settings['image'] in os_list: - if re.search('old', self.settings['image']): - # Directories with old in the name are of no - # interest to us - continue - - for platform, ignore in ( - self.settings['choice']['platform'].items()): - self.settings['platform'] = platform - - # -- Iterate through available builds -- - builds = self.db.get_builds( - self.settings['platform'], - self.settings['image']) - - for build in builds: - self.settings['build'] = build - - # -- Check build which matches these parameters - #(builds that don't match are excluded in UI)-- - if( len(self.db.execute_return_list( - 'select * from release_hwpacks ' - 'where platform == ? ' - 'and hardware == ? ' - 'and build == ?', - (self.settings['platform'], - self.settings['hwpack'], - self.settings['build']))) - and len(self.db.execute_return_list( - 'select * from release_binaries ' - 'where platform == ? ' - 'and image == ? ' - 'and build == ?', - (self.settings['platform'], - self.settings['image'], - self.settings['build'])))): - - # - Run the function under test! - - image_url, hwpack_url = ( - self.db.get_image_and_hwpack_urls(self.settings)) - self.assertTrue(image_url) - self.assertTrue(hwpack_url) - if __name__ == '__main__': run() === modified file 'linaro_image_tools/FetchImage.py' --- linaro_image_tools/FetchImage.py 2011-07-14 12:50:56 +0000 +++ linaro_image_tools/FetchImage.py 2011-07-19 16:02:08 +0000 @@ -1026,7 +1026,7 @@ test_date[in_the] = None break - if test_date[in_the] > max_search_date: + if test_date[in_the] and test_date[in_the] > max_search_date: test_date[in_the] = None if test_date[in_the]: === modified file 'linaro_image_tools/tests/__init__.py' --- linaro_image_tools/tests/__init__.py 2011-05-10 15:43:32 +0000 +++ linaro_image_tools/tests/__init__.py 2011-07-19 16:02:08 +0000 @@ -11,6 +11,7 @@ module_names = [ 'linaro_image_tools.tests.test_cmd_runner', 'linaro_image_tools.tests.test_utils', + 'linaro_image_tools.tests.test_fetch_image', ] # if pyflakes is installed and we're running from a bzr checkout... if has_command('pyflakes') and not os.path.isabs(__file__): === added file 'linaro_image_tools/tests/test_fetch_image.py' --- linaro_image_tools/tests/test_fetch_image.py 1970-01-01 00:00:00 +0000 +++ linaro_image_tools/tests/test_fetch_image.py 2011-07-19 18:01:18 +0000 @@ -0,0 +1,186 @@ +# Copyright (C) 2010, 2011 Linaro +# +# Author: James Tunnicliffe +# +# This file is part of Linaro Image Tools. +# +# Linaro Image Tools is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Linaro Image Tools is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import wx +import unittest +import re +import linaro_image_tools.FetchImage as FetchImage + + +class TestURLLookupFunctions(unittest.TestCase): + + def setUp(self): + self.file_handler = FetchImage.FileHandler() + self.file_handler.update_files_from_server() + self.config = FetchImage.FetchImageConfig() + self.config.settings["force_download"] = False + + # Load settings YAML, which defines the parameters we ask for and + # acceptable responses from the user + self.config.read_config(self.file_handler.settings_file) + + # Using the config we have, look up URLs to download data from in the + # server index + self.db = FetchImage.DB(self.file_handler.index_file) + + def test_url_lookup(self): + self.settings = self.config.settings + self.settings['release_or_snapshot'] = "snapshot" + + #--- Test first with a snapshot build lookup --- + # -- Fix a build date -- + # We only need to look up a single snapshot date. Start with today and + # go with the day in the DB, build 0 + today = wx.DateTime() + today.SetToCurrent() + + # -- Don't iterate through platforms for snapshot -- + + # -- Select hardware -- + for self.settings['hardware'] in ( + self.settings['choice']['hardware'].keys()): + + compatable_hwpacks = self.settings['choice']['hwpack'][ + self.settings['hardware']] + + future_date, past_date = self.db.get_next_prev_day_with_builds( + "linaro-alip", + today.FormatISODate().encode('ascii'), + compatable_hwpacks) + + if past_date == None: + # Some hardware packs are not available in the snapshot repo, + # so just skip if they aren't + continue + + builds = self.db.get_binary_builds_on_day_from_db( + "linaro-alip", + past_date, + compatable_hwpacks) + + self.assertTrue(len(builds)) + # If the above assert fails, either the DB is empty, or + # db.get_binary_builds_on_day_from_db failed + + small_date = re.sub('-', '', past_date) + self.settings['build'] = small_date + ":" + "0" + + # -- Iterate through hardware packs -- + for self.settings['hwpack'] in compatable_hwpacks: + + # If hardware pack is available... + if(self.settings['hwpack'] + in self.db.get_hwpacks('snapshot_hwpacks')): + + # -- Iterate through images + os_list = self.db.get_os_list_from('snapshot_binaries') + + for self.settings['image'] in os_list: + if re.search('old', self.settings['image']): + # Directories with old in the name are of no + # interest to us + continue + + # -- Check build which matches these parameters + # (builds that don't match are excluded in UI) -- + if( len(self.db.execute_return_list( + 'select * from snapshot_hwpacks ' + 'where hardware == ? ' + 'and date == ? ' + 'and build == ?', + (self.settings['hwpack'], + small_date, + "0"))) + and len(self.db.execute_return_list( + 'select * from snapshot_binaries ' + 'where image == ? ' + 'and date == ? ' + 'and build == ?', + (self.settings['image'], + small_date, + "0")))): + + # - Run the function under test! - + image_url, hwpack_url = ( + self.db.get_image_and_hwpack_urls(self.settings)) + + self.assertTrue(image_url) + self.assertTrue(hwpack_url) + + #--- Now test release build lookup --- + self.settings['release_or_snapshot'] = "release" + # -- Select hardware -- + for self.settings['hardware'] in ( + self.settings['choice']['hardware'].keys()): + compatable_hwpacks = ( + self.settings['choice']['hwpack'][self.settings['hardware']]) + + # -- Iterate through hardware packs -- + for self.settings['hwpack'] in compatable_hwpacks: + + # If hardware pack is available... + if(self.settings['hwpack'] + in self.db.get_hwpacks('release_hwpacks')): + + # -- Iterate through images + os_list = self.db.get_os_list_from('release_binaries') + + for self.settings['image'] in os_list: + if re.search('old', self.settings['image']): + # Directories with old in the name are of no + # interest to us + continue + + for platform, ignore in ( + self.settings['choice']['platform'].items()): + self.settings['platform'] = platform + + # -- Iterate through available builds -- + builds = self.db.get_builds( + self.settings['platform'], + self.settings['image']) + + for build in builds: + self.settings['build'] = build + + # -- Check build which matches these parameters + #(builds that don't match are excluded in UI)-- + if( len(self.db.execute_return_list( + 'select * from release_hwpacks ' + 'where platform == ? ' + 'and hardware == ? ' + 'and build == ?', + (self.settings['platform'], + self.settings['hwpack'], + self.settings['build']))) + and len(self.db.execute_return_list( + 'select * from release_binaries ' + 'where platform == ? ' + 'and image == ? ' + 'and build == ?', + (self.settings['platform'], + self.settings['image'], + self.settings['build'])))): + + # - Run the function under test! - + image_url, hwpack_url = ( + self.db.get_image_and_hwpack_urls( + self.settings)) + self.assertTrue(image_url) + self.assertTrue(hwpack_url)