Skip to content

Commit

Permalink
python3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Axadiw committed Jun 3, 2015
1 parent 6e4b501 commit 00af303
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
4 changes: 2 additions & 2 deletions basset/basset_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import coloredlogs
import sys

from helpers.configuration_manager import ConfigurationManager
from basset.helpers.configuration_manager import ConfigurationManager

from helpers.converter import Converter
from basset.helpers.converter import Converter
from basset.helpers.merger import Merger
from basset.exceptions import *

Expand Down
43 changes: 13 additions & 30 deletions basset/tests/test_merger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from _ast import operator

import os
import shutil
import tempfile
import json
from unittest import TestCase

from nose.tools import assert_raises

from basset.helpers.merger import Merger
from basset.exceptions import *

Expand All @@ -25,8 +25,9 @@ def tearDownClass(cls):

def setUp(self):
self.temp_dir_path = tempfile.mkdtemp()
shutil.copytree(os.path.join(TestMerger.script_root_dir_path, "basset/tests/Resources/tests_merger/SampleAssets"),
os.path.join(self.temp_dir_path, self.resources_path))
shutil.copytree(
os.path.join(TestMerger.script_root_dir_path, "basset/tests/Resources/tests_merger/SampleAssets"),
os.path.join(self.temp_dir_path, self.resources_path))
os.chdir(self.temp_dir_path)
pass

Expand All @@ -36,7 +37,8 @@ def tearDown(self):

def test_no_xcassets(self):
shutil.copytree(
os.path.join(TestMerger.script_root_dir_path, "basset/tests/Resources/tests_merger/NoXCAssetsTestResources"),
os.path.join(TestMerger.script_root_dir_path,
"basset/tests/Resources/tests_merger/NoXCAssetsTestResources"),
os.path.join(self.temp_dir_path, "Project"))

merger = Merger()
Expand All @@ -57,7 +59,8 @@ def test_multiple_xcassets_no_default(self):

def test_single_asset(self):
shutil.copytree(
os.path.join(TestMerger.script_root_dir_path, "basset/tests/Resources/tests_merger/SingleXCAssetTestResources"),
os.path.join(TestMerger.script_root_dir_path,
"basset/tests/Resources/tests_merger/SingleXCAssetTestResources"),
os.path.join(self.temp_dir_path, "Project"))
selected_asset_dir = "Project/SingleXCAssetsTest/Images.xcassets"

Expand Down Expand Up @@ -142,35 +145,15 @@ def test_multiple_assets_with_existing_asset(self):
with open(os.path.join(os.path.join(self.temp_dir_path, selected_asset_dir),
"test-01.imageset/Contents.json")) as data_file:
actual_dict = json.load(data_file)
actual_dict = self.deep_sort(actual_dict)
expected_dict = self.deep_sort(expected_dict)
actual_dict["images"] = sorted(actual_dict["images"], key=lambda k: k["filename"])
expected_dict["images"] = sorted(expected_dict["images"], key=lambda k: k["filename"])
self.assertDictEqual(expected_dict, actual_dict)

self.assertTrue(os.path.isdir(secondary_assets_dir))
self.assertTrue(os.listdir(secondary_assets_dir) == ['empty_xcassets_here'])

# Helpers-----------------------------------------------------------------------------------------------------------

def deep_sort(self, obj):
"""
Recursively sort list or dict nested lists
"""

if isinstance(obj, dict):
_sorted = {}
for key in sorted(obj):
_sorted[key] = self.deep_sort(obj[key])

elif isinstance(obj, list):
new_list = []
for val in obj:
new_list.append(self.deep_sort(val))
_sorted = sorted(new_list)

else:
_sorted = obj

return _sorted

def check_if_images_are_copied_and_jsons_are_valid(self, selected_asset_dir,
file_excluded_from_json_validation_index):
Expand Down Expand Up @@ -254,8 +237,8 @@ def validate_json_file(self, json_file_path, images_dictionary):

with open(json_file_path) as data_file:
actual_dict = json.load(data_file)
actual_dict = self.deep_sort(actual_dict)
expected_dict = self.deep_sort(expected_dict)
actual_dict["images"] = sorted(actual_dict["images"], key=lambda k: k["filename"])
expected_dict["images"] = sorted(expected_dict["images"], key=lambda k: k["filename"])
self.assertDictEqual(expected_dict, actual_dict)

def check_if_images_are_copied(self, source_images, destination_directory_path):
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ envlist = py27,py34
skipsdist=True
[testenv]
deps = -r{toxinidir}/requirements.txt
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}
commands=nosetests

0 comments on commit 00af303

Please sign in to comment.