Best Python code snippet using avocado_python
XcodeBuildIncrementer.py
Source: XcodeBuildIncrementer.py
1import os, plistlib2PROJECT_DIR, INFOPLIST_FILE = None, None3try:4 PROJECT_DIR = os.environ['PROJECT_DIR']5 INFOPLIST_FILE = os.environ['INFOPLIST_FILE']6 BUILD_CONFIGURATION = os.environ['CONFIGURATION']7 BUILD_CONFIGURATION_DIR = os.environ['CONFIGURATION_BUILD_DIR']8 IS_RELEASE = BUILD_CONFIGURATION == "Release"9 IS_ARCHIVE = "ArchiveIntermediates" in BUILD_CONFIGURATION_DIR10except:11 print "Could not find the required environment variables: PROJECT_DIR, INFOPLIST_FILE\nIf this is being run in Xcode, then this is an error! Trying command line args..."12 # TODO: Add command line option13def get_new_version(version, IS_ARCHIVE, IS_RELEASE):14 """15 Get a new bundle version using16 :param CFBundleShortVersionString: str - The current version of the app17 :param CFBundleVersion: - The current bundle version of the app18 >>> print get_new_version(version="1.3.2.5", IS_ARCHIVE=False, IS_RELEASE=False)19 1.3.2.520 >>> print get_new_version(version="1.3.2.5", IS_ARCHIVE=True, IS_RELEASE=False)21 1.3.222 >>> print get_new_version(version="1.3.2.5", IS_ARCHIVE=False, IS_RELEASE=True)23 1.3.2.624 >>> print get_new_version(version="1.3.2", IS_ARCHIVE=False, IS_RELEASE=False)25 1.3.226 >>> print get_new_version(version="1.3.2", IS_ARCHIVE=True, IS_RELEASE=False)27 1.328 >>> print get_new_version(version="1.3.2", IS_ARCHIVE=False, IS_RELEASE=True)29 1.3.330 >>> print get_new_version(version="1.3", IS_ARCHIVE=False, IS_RELEASE=False)31 1.332 >>> print get_new_version(version="1.3", IS_ARCHIVE=True, IS_RELEASE=False)33 1.034 >>> print get_new_version(version="1.3", IS_ARCHIVE=False, IS_RELEASE=True)35 1.436 """37 if not IS_ARCHIVE and not IS_RELEASE:38 return version39 version_split = version.split('.')40 version_split_sigfigs = len(version_split)41 # ARCHIVE42 if IS_ARCHIVE:43 if version_split_sigfigs == 2:44 version_split[1] = str(0)45 else:46 del version_split[-1]47 version = ".".join(version_split)48 return version49 # Release50 else:51 version_split[version_split_sigfigs-1] = str(int(version_split[version_split_sigfigs-1]) + 1)52 return ".".join(version_split)53def get_new_build(old_version, new_version, build):54 """55 Get a new bundle version using56 :param CFBundleShortVersionString: str - The current version of the app57 :param CFBundleVersion: - The current bundle version of the app58 >>> print get_new_build(old_version="1.3.2", new_version="1.3.2", build="4325")59 432660 >>> print get_new_build(old_version="1.3.2", new_version="1.3.3", build="4325")61 162 """63 # Version did not change, increment the current build number64 if old_version == new_version:65 return str(int(build) + 1)66 # Version changed, start over at 167 else:68 return str(1)69def run_and_change_build():70 plist_filename = "{project_dir}/{infoplist_file}".format(project_dir=PROJECT_DIR, infoplist_file=INFOPLIST_FILE)71 plist = plistlib.readPlist(plist_filename)72 new_short_version = get_new_version(version=plist["CFBundleShortVersionString"], IS_ARCHIVE=IS_ARCHIVE, IS_RELEASE=IS_RELEASE)73 new_bundle_version = get_new_build(old_version=plist["CFBundleShortVersionString"], new_version=new_short_version, build=plist["CFBundleVersion"])74 plist["CFBundleShortVersionString"] = new_short_version75 plist["CFBundleVersion"] = new_bundle_version76 plistlib.writePlist(plist, plist_filename)77if PROJECT_DIR and INFOPLIST_FILE:...
serializers.py
Source: serializers.py
1from rest_framework import serializers2from api.base_serializers import DecideResponseDataModelSerializer3from todos.models import Board, List, Card4class CardSerializer(DecideResponseDataModelSerializer):5 class Meta:6 model = Card7 fields = [8 'id',9 'list',10 'name',11 'order',12 'detail',13 'moved_at',14 'is_archive',15 ]16 extra_kwargs = {17 'moved_at': {'read_only': True}18 }19class ListSerializer(DecideResponseDataModelSerializer):20 cards = serializers.SerializerMethodField()21 next_list = serializers.SerializerMethodField()22 class Meta:23 model = List24 fields = [25 'id',26 'board',27 'name',28 'order',29 'next',30 'next_list',31 'auto_switch',32 'switch_time',33 'is_archive',34 'cards',35 ]36 def request_path_method(self):37 path = self._context['request'].path38 return path.split('/')[-2]39 def get_cards(self, instance):40 method = self.request_path_method()41 if method == 'all_cards':42 queryset = instance.cards.all().order_by('order')43 elif method == 'archive_cards':44 queryset = instance.cards.all().filter(is_archive=True).order_by('order')45 else:46 queryset = instance.cards.all().filter(is_archive=False).order_by('order')47 serializer = CardSerializer(queryset, many=True, context=self._context)48 return serializer.data49 def get_next_list(self, instance):50 if instance.next:51 return {'id': instance.next.id, 'name': instance.next.name}52 return None53class BoardSerializer(DecideResponseDataModelSerializer):54 username = serializers.SerializerMethodField()55 lists = serializers.SerializerMethodField()56 class Meta:57 model = Board58 fields = [59 'id',60 'user',61 'username',62 'name',63 'lists',64 ]65 extra_kwargs = {66 'user': {'write_only': True}67 }68 def request_path_method(self):69 path = self._context['request'].path70 return path.split('/')[-2]71 def get_lists(self, instance):72 method = self.request_path_method()73 if method == 'all_lists':74 queryset = instance.lists.all().order_by('order')75 elif method == 'archive_lists':76 queryset = instance.lists.all().filter(is_archive=True).order_by('order')77 else:78 queryset = instance.lists.all().filter(is_archive=False).order_by('order')79 serializer = ListSerializer(queryset, many=True, context=self._context)80 return serializer.data81 def get_username(self, instance):...
test_archive_handler.py
Source: test_archive_handler.py
...4sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'resources', 'lib', 'launcher'))5from archive_handler import ArchiveHandler6class TestArchiveHandler(unittest.TestCase):7 handler = ArchiveHandler()8 def test_check_is_archive(self):9 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.smc"), False)10 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.zip"), True)11 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.7z"), True)12 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.rar"), True)13 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.tar.gz"), True)14 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.tar.bz2"), True)15 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.tar.xz"), True)16 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.tgz"), True)17 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.tbz2"), True)18 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.xz"), True)19 self.assertEqual(self.handler.is_archive("C:\\Test\\MyRom.cbr"), True)20 def test_get_temp_dir_path(self):21 self.assertEqual(self.handler._ArchiveHandler__get_temp_dir_path('SNES'),22 'C:\\Users\\Malte\\AppData\\Roaming\\Kodi\\addons\\script.games.rom.collection.browser.git\\resources\\tests\\script.games.rom.collection.browser\\tmp\\extracted\\SNES')23 def test_delete_temp_files(self):24 temp_path = self.handler._ArchiveHandler__get_temp_dir_path('SNES')25 files = os.listdir(temp_path)26 if(len(files) == 0):27 open(os.path.join(temp_path, 'test'), 'a').close()28 self.handler._ArchiveHandler__delete_temp_files(temp_path)29 files = os.listdir(temp_path)30 self.assertEqual(len(files), 0)31 def test_7z(self):32 try:33 import py7zr...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!