code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def test_flip_to_json_with_datetimes(): """ Test that the json encoder correctly handles dates and datetimes """ tricky_data = """ a date: 2017-03-02 a datetime: 2017-03-02 19:52:00 """ actual = cfn_flip.to_json(tricky_data) parsed_actual = load_json(actual) assert parsed_actual == { "a date": "2017-03-02", "a datetime": "2017-03-02T19:52:00", }
Test that the json encoder correctly handles dates and datetimes
test_flip_to_json_with_datetimes
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_clean_getatt(): """ The clean flag should convert Fn::GetAtt to its short form """ data = """ { "Fn::GetAtt": ["Left", "Right"] } """ expected = "!GetAtt 'Left.Right'\n" assert cfn_flip.to_yaml(data, clean_up=False) == expected assert cfn_flip.to_yaml(data, clean_up=True) == expected
The clean flag should convert Fn::GetAtt to its short form
test_flip_to_yaml_with_clean_getatt
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_multi_level_getatt(): """ Test that we correctly convert multi-level Fn::GetAtt from JSON to YAML format """ data = """ { "Fn::GetAtt": ["First", "Second", "Third"] } """ expected = "!GetAtt 'First.Second.Third'\n" assert cfn_flip.to_yaml(data) == expected
Test that we correctly convert multi-level Fn::GetAtt from JSON to YAML format
test_flip_to_yaml_with_multi_level_getatt
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_dotted_getatt(): """ Even though documentation does not suggest Resource.Value is valid we should support it anyway as cloudformation allows it :) """ data = """ [ { "Fn::GetAtt": "One.Two" }, { "Fn::GetAtt": "Three.Four.Five" } ] """ expected = "- !GetAtt 'One.Two'\n- !GetAtt 'Three.Four.Five'\n" assert cfn_flip.to_yaml(data) == expected
Even though documentation does not suggest Resource.Value is valid we should support it anyway as cloudformation allows it :)
test_flip_to_yaml_with_dotted_getatt
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_json_with_multi_level_getatt(): """ Test that we correctly convert multi-level Fn::GetAtt from YAML to JSON format """ data = "!GetAtt 'First.Second.Third'\n" expected = { "Fn::GetAtt": ["First", "Second.Third"] } actual = cfn_flip.to_json(data, clean_up=True) assert load_json(actual) == expected
Test that we correctly convert multi-level Fn::GetAtt from YAML to JSON format
test_flip_to_json_with_multi_level_getatt
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_getatt_from_yaml(): """ Test that we correctly convert the short form of GetAtt into the correct JSON format from YAML """ source = """ - !GetAtt foo.bar - Fn::GetAtt: [foo, bar] """ expected = [ {"Fn::GetAtt": ["foo", "bar"]}, {"Fn::GetAtt": ["foo", "bar"]}, ] # No clean actual = cfn_flip.to_json(source, clean_up=False) assert load_json(actual) == expected # With clean actual = cfn_flip.to_json(source, clean_up=True) assert load_json(actual) == expected
Test that we correctly convert the short form of GetAtt into the correct JSON format from YAML
test_getatt_from_yaml
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_json_with_condition(): """ Test that the Condition key is correctly converted """ source = """ MyAndCondition: !And - !Equals ["sg-mysggroup", !Ref "ASecurityGroup"] - !Condition SomeOtherCondition """ expected = { "MyAndCondition": { "Fn::And": [ {"Fn::Equals": ["sg-mysggroup", {"Ref": "ASecurityGroup"}]}, {"Condition": "SomeOtherCondition"} ] } } actual = cfn_flip.to_json(source, clean_up=True) assert load_json(actual) == expected
Test that the Condition key is correctly converted
test_flip_to_json_with_condition
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_newlines(): """ Test that strings containing newlines are quoted """ source = r'["a", "b\n", "c\r\n", "d\r"]' expected = "".join([ '- a\n', '- "b\\n"\n', '- "c\\r\\n"\n', '- "d\\r"\n', ]) assert cfn_flip.to_yaml(source) == expected
Test that strings containing newlines are quoted
test_flip_to_yaml_with_newlines
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_clean_flip_to_yaml_with_newlines(): """ Test that strings containing newlines use blockquotes when using "clean" """ source = dump_json(ODict(( ("outer", ODict(( ("inner", "#!/bin/bash\nyum -y update\nyum install python"), ("subbed", ODict(( ("Fn::Sub", "The cake\nis\n${CakeType}"), ))), ))), ))) expected = """outer: inner: |- #!/bin/bash yum -y update yum install python subbed: !Sub |- The cake is ${CakeType} """ assert cfn_flip.to_yaml(source, clean_up=True) == expected
Test that strings containing newlines use blockquotes when using "clean"
test_clean_flip_to_yaml_with_newlines
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_with_json_output(input_yaml, parsed_json): """ We should be able to specify that the output is JSON """ actual = cfn_flip.flip(input_yaml, out_format="json") assert load_json(actual) == parsed_json
We should be able to specify that the output is JSON
test_flip_with_json_output
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_with_yaml_output(input_json, parsed_yaml): """ We should be able to specify that the output is YAML """ actual = cfn_flip.flip(input_json, out_format="yaml") parsed_actual = load_yaml(actual) assert parsed_actual == parsed_yaml
We should be able to specify that the output is YAML
test_flip_with_yaml_output
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_no_flip_with_json(input_json, parsed_json): """ We should be able to submit JSON and get JSON back """ actual = cfn_flip.flip(input_json, no_flip=True) assert load_json(actual) == parsed_json
We should be able to submit JSON and get JSON back
test_no_flip_with_json
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_no_flip_with_yaml(input_yaml, parsed_yaml): """ We should be able to submit YAML and get YAML back """ actual = cfn_flip.flip(input_yaml, no_flip=True) parsed_actual = load_yaml(actual) assert parsed_actual == parsed_yaml
We should be able to submit YAML and get YAML back
test_no_flip_with_yaml
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_no_flip_with_explicit_json(input_json, parsed_json): """ We should be able to submit JSON and get JSON back and specify the output format explicity """ actual = cfn_flip.flip(input_json, out_format="json", no_flip=True) assert load_json(actual) == parsed_json
We should be able to submit JSON and get JSON back and specify the output format explicity
test_no_flip_with_explicit_json
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_no_flip_with_explicit_yaml(input_yaml, parsed_yaml): """ We should be able to submit YAML and get YAML back and specify the output format explicity """ actual = cfn_flip.flip(input_yaml, out_format="yaml", no_flip=True) parsed_actual = load_yaml(actual) assert parsed_actual == parsed_yaml
We should be able to submit YAML and get YAML back and specify the output format explicity
test_no_flip_with_explicit_yaml
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_explicit_json_rejects_yaml(fail_message, input_yaml): """ Given an output format of YAML The input format should be assumed to be JSON and YAML input should be rejected """ with pytest.raises(JSONDecodeError, match=fail_message): cfn_flip.flip(input_yaml, out_format="yaml")
Given an output format of YAML The input format should be assumed to be JSON and YAML input should be rejected
test_explicit_json_rejects_yaml
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_explicit_yaml_rejects_bad_yaml(bad_data): """ Given an output format of YAML The input format should be assumed to be JSON and YAML input should be rejected """ with pytest.raises( yaml.scanner.ScannerError, match="while scanning for the next token\nfound character \'\\\\t\' that cannot start any token", ): cfn_flip.flip(bad_data, out_format="json")
Given an output format of YAML The input format should be assumed to be JSON and YAML input should be rejected
test_explicit_yaml_rejects_bad_yaml
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_longhand_functions(input_json, parsed_json): """ When converting to yaml, sometimes we'll want to keep the long form """ actual1 = cfn_flip.flip(input_json, long_form=True) actual2 = cfn_flip.to_yaml(input_json, long_form=True) # No custom loader as there should be no custom tags parsed_actual1 = yaml.load(actual1, Loader=yaml.SafeLoader) parsed_actual2 = yaml.load(actual2, Loader=yaml.SafeLoader) # We use the parsed JSON as it contains long form function calls assert parsed_actual1 == parsed_json assert parsed_actual2 == parsed_json
When converting to yaml, sometimes we'll want to keep the long form
test_flip_to_yaml_with_longhand_functions
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_unconverted_types(): """ When converting to yaml, we need to make sure all short-form types are tagged """ fns = { "Fn::GetAtt": "!GetAtt", "Fn::Sub": "!Sub", "Ref": "!Ref", "Condition": "!Condition", } for fn, tag in fns.items(): value = dump_json({ fn: "something" }) expected = "{} 'something'\n".format(tag) assert cfn_flip.to_yaml(value) == expected
When converting to yaml, we need to make sure all short-form types are tagged
test_unconverted_types
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_get_dumper(): """ When invoking get_dumper use clean_up & long_form :return: LongCleanDumper """ resp = cfn_flip.get_dumper(clean_up=True, long_form=True) assert resp == cfn_flip.yaml_dumper.LongCleanDumper
When invoking get_dumper use clean_up & long_form :return: LongCleanDumper
test_get_dumper
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_quoted_digits(): """ Any value that is composed entirely of digits should be quoted for safety. CloudFormation is happy for numbers to appear as strings. But the opposite (e.g. account numbers as numbers) can cause issues See https://github.com/awslabs/aws-cfn-template-flip/issues/41 """ value = dump_json(ODict(( ("int", 123456), ("float", 123.456), ("oct", "0123456"), ("bad-oct", "012345678"), ("safe-oct", "0o123456"), ("string", "abcdef"), ))) expected = "\n".join(( "int: 123456", "float: 123.456", "oct: '0123456'", "bad-oct: '012345678'", "safe-oct: '0o123456'", "string: abcdef", "" )) actual = cfn_flip.to_yaml(value) assert actual == expected
Any value that is composed entirely of digits should be quoted for safety. CloudFormation is happy for numbers to appear as strings. But the opposite (e.g. account numbers as numbers) can cause issues See https://github.com/awslabs/aws-cfn-template-flip/issues/41
test_quoted_digits
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_json_literal(input_json_with_literal, parsed_yaml_with_json_literal): """ Test that load json with json payload that must stay json when converted to yaml """ actual = cfn_flip.to_yaml(input_json_with_literal) assert load_yaml(actual) == parsed_yaml_with_json_literal
Test that load json with json payload that must stay json when converted to yaml
test_flip_to_yaml_with_json_literal
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_flip_to_yaml_with_json_long_line(input_json_with_long_line, parsed_yaml_with_long_line): """ Test that load json with long line will translate to yaml without break line. The configuration settings is 120 columns """ actual = cfn_flip.to_yaml(input_json_with_long_line) assert load_yaml(actual) == parsed_yaml_with_long_line
Test that load json with long line will translate to yaml without break line. The configuration settings is 120 columns
test_flip_to_yaml_with_json_long_line
python
awslabs/aws-cfn-template-flip
tests/test_flip.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_flip.py
Apache-2.0
def test_get_set(): """ It should at least work the same as a dict """ case = ODict() case["one"] = 1 case["two"] = 2 assert len(case.keys()) == 2 assert case["one"] == 1
It should at least work the same as a dict
test_get_set
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_list_constructor(): """ We should be able to construct one from a tuple of pairs """ case = ODict(( ("one", 1), ("two", 2), )) assert len(case.keys()) == 2 assert case["one"] == 1 assert case["two"] == 2 assert case["two"] == 2
We should be able to construct one from a tuple of pairs
test_list_constructor
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_ordering(): """ Ordering should be left intact """ case = ODict() case["z"] = 1 case["a"] = 2 assert list(case.keys()) == ["z", "a"]
Ordering should be left intact
test_ordering
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_ordering_from_constructor(): """ Ordering should be left intact """ case = ODict([ ("z", 1), ("a", 2), ]) assert list(case.keys()) == ["z", "a"]
Ordering should be left intact
test_ordering_from_constructor
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_constructor_disallows_dict(): """ For the sake of python<3.6, don't accept dicts as ordering will be lost """ with pytest.raises(Exception, match="ODict does not allow construction from a dict"): ODict({ "z": 1, "a": 2, })
For the sake of python<3.6, don't accept dicts as ordering will be lost
test_constructor_disallows_dict
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_explicit_sorting(): """ Even an explicit sort should result in no change """ case = ODict(( ("z", 1), ("a", 2), )).items() actual = sorted(case) assert actual == case
Even an explicit sort should result in no change
test_explicit_sorting
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_post_deepcopy_repr(): """ Repr should behave normally after deepcopy """ dct = ODict([("a", 1)]) dct2 = deepcopy(dct) assert repr(dct) == repr(dct2) dct2["b"] = 2 assert repr(dct) != repr(dct2)
Repr should behave normally after deepcopy
test_post_deepcopy_repr
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_pickle(): """ Should be able to pickle and unpickle """ dct = ODict([ ("c", 3), ("d", 4), ]) data = pickle.dumps(dct) dct2 = pickle.loads(data) assert dct == dct2
Should be able to pickle and unpickle
test_pickle
python
awslabs/aws-cfn-template-flip
tests/test_odict.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_odict.py
Apache-2.0
def test_yaml_no_ordered_dict(): """ cfn-flip patches yaml to use ODict by default Check that we don't do this for folks who import cfn_flip and yaml """ yaml_string = "key: value" data = yaml.load(yaml_string, Loader=yaml.SafeLoader) assert type(data) == dict
cfn-flip patches yaml to use ODict by default Check that we don't do this for folks who import cfn_flip and yaml
test_yaml_no_ordered_dict
python
awslabs/aws-cfn-template-flip
tests/test_yaml_patching.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_yaml_patching.py
Apache-2.0
def test_yaml_no_ordered_dict_with_custom_loader(): """ cfn-flip patches yaml to use ODict by default Check that we do this for normal cfn_flip use cases """ yaml_string = "key: value" data = load_yaml(yaml_string) assert type(data) == ODict
cfn-flip patches yaml to use ODict by default Check that we do this for normal cfn_flip use cases
test_yaml_no_ordered_dict_with_custom_loader
python
awslabs/aws-cfn-template-flip
tests/test_yaml_patching.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_yaml_patching.py
Apache-2.0
def test_load_json(): """ Should map to an ordered dict """ source = """ { "z": "first", "m": "middle", "a": "last" } """ actual = load_json(source) assert type(actual) == ODict assert list(actual.keys()) == ["z", "m", "a"] assert actual["z"] == "first" assert actual["m"] == "middle" assert actual["a"] == "last"
Should map to an ordered dict
test_load_json
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_load_yaml(): """ Should map to an ordered dict """ source = """z: first m: !Sub - The cake is a ${CakeType} - CakeType: lie a: !Ref last """ actual = load_yaml(source) assert type(actual) == ODict assert list(actual.keys()) == ["z", "m", "a"] assert actual["z"] == "first" assert actual["m"] == { "Fn::Sub": [ "The cake is a ${CakeType}", { "CakeType": "lie", }, ], } assert actual["a"] == {"Ref": "last"}
Should map to an ordered dict
test_load_yaml
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_dump_json(): """ JSON dumping just needs to know about datetimes, provide a nice indent, and preserve order """ import sys source = ODict(( ("z", datetime.time(3, 45)), ("m", datetime.date(2012, 5, 2)), ("a", datetime.datetime(2012, 5, 2, 3, 45)), )) actual = dump_json(source) assert load_json(actual) == { "z": "03:45:00", "m": "2012-05-02", "a": "2012-05-02T03:45:00", } if sys.version_info < (3, 6): fail_message = r"\(1\+1j\) is not JSON serializable" elif sys.version_info < (3, 7): fail_message = "Object of type 'complex' is not JSON serializable" else: fail_message = "Object of type complex is not JSON serializable" with pytest.raises(TypeError, match=fail_message): dump_json({ "c": 1 + 1j, })
JSON dumping just needs to know about datetimes, provide a nice indent, and preserve order
test_dump_json
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_dump_yaml(): """ YAML dumping needs to use quoted style for strings with newlines, use a standard indenting style, and preserve order """ source = ODict(( ("z", "short string",), ("m", {"Ref": "embedded string"},), ("a", "A\nmulti-line\nstring",), )) actual = dump_yaml(source) assert actual == """z: short string m: Ref: embedded string a: "A\\nmulti-line\\nstring" """
YAML dumping needs to use quoted style for strings with newlines, use a standard indenting style, and preserve order
test_dump_yaml
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_odict_items_sort(): """ Simple test to validate sort method. TODO: implement sort method :return: None """ items = ['B', 'A', 'C'] odict = OdictItems(items) assert not odict.sort()
Simple test to validate sort method. TODO: implement sort method :return: None
test_odict_items_sort
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_odict_fail_with_dict(): """ Raise exception if we pass dict when initializing the class with dict :return: Exception """ items = {'key1': 'value1'} with pytest.raises(Exception) as e: ODict(items) assert 'ODict does not allow construction from a dict' == str(e.value)
Raise exception if we pass dict when initializing the class with dict :return: Exception
test_odict_fail_with_dict
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_represent_scalar(): """ When invoking represent_scalar apply style if value has \n :return: ScalarNode """ source = """z: first m: !Sub - The cake is a ${CakeType} - CakeType: lie a: !Ref last """ yaml_dumper = CfnYamlDumper(six.StringIO(source)) resp = yaml_dumper.represent_scalar('Key', 'value\n') print(resp) assert isinstance(resp, ScalarNode)
When invoking represent_scalar apply style if value has \n :return: ScalarNode
test_represent_scalar
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_multi_constructor_with_invalid_node_type(): """ When invoking multi_constructor with invalid node type must raise Exception :return: """ with pytest.raises(Exception) as e: multi_constructor(None, None, None) assert 'Bad tag: !Fn::None' in str(e.value)
When invoking multi_constructor with invalid node type must raise Exception :return:
test_multi_constructor_with_invalid_node_type
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_construct_getattr_with_invalid_node_type(): """ When invoking multi_constructor with invalid node type must raise Exception :return: """ node = MockNode() with pytest.raises(ValueError) as e: construct_getatt(node) assert 'Unexpected node type:' in str(e.value)
When invoking multi_constructor with invalid node type must raise Exception :return:
test_construct_getattr_with_invalid_node_type
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def test_construct_getattr_with_list(): """ When invoking multi_constructor with invalid node type must raise Exception :return: """ node = MockNode() node.value = [MockNode('A'), MockNode('B'), MockNode('C')] resp = construct_getatt(node) assert resp == ['A', 'B', 'C']
When invoking multi_constructor with invalid node type must raise Exception :return:
test_construct_getattr_with_list
python
awslabs/aws-cfn-template-flip
tests/test_tools.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/tests/test_tools.py
Apache-2.0
def main(ctx, **kwargs): """ AWS CloudFormation Template Flip is a tool that converts AWS CloudFormation templates between JSON and YAML formats, making use of the YAML format's short function syntax where possible. """ in_format = kwargs.pop('in_format') out_format = kwargs.pop('out_format') or kwargs.pop('out_flag') no_flip = kwargs.pop('no_flip') clean = kwargs.pop('clean') long_form = kwargs.pop('long') input_file = kwargs.pop('input') output_file = kwargs.pop('output') if not in_format: if input_file.name.endswith(".json"): in_format = "json" elif input_file.name.endswith(".yaml") or input_file.name.endswith(".yml"): in_format = "yaml" if input_file.name == "<stdin>" and sys.stdin.isatty(): click.echo(ctx.get_help()) ctx.exit() try: flipped = flip( input_file.read(), in_format=in_format, out_format=out_format, clean_up=clean, no_flip=no_flip, long_form=long_form ) output_file.write(flipped) except Exception as e: raise click.ClickException("{}".format(e))
AWS CloudFormation Template Flip is a tool that converts AWS CloudFormation templates between JSON and YAML formats, making use of the YAML format's short function syntax where possible.
main
python
awslabs/aws-cfn-template-flip
cfn_flip/main.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/main.py
Apache-2.0
def map_representer(dumper, value): """ Deal with !Ref style function format and OrderedDict """ value = ODict(value.items()) if len(value.keys()) == 1: key = list(value.keys())[0] if key in CONVERTED_SUFFIXES: return fn_representer(dumper, key, value[key]) if key.startswith(FN_PREFIX): return fn_representer(dumper, key[4:], value[key]) return dumper.represent_mapping(TAG_MAP, value, flow_style=False)
Deal with !Ref style function format and OrderedDict
map_representer
python
awslabs/aws-cfn-template-flip
cfn_flip/yaml_dumper.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/yaml_dumper.py
Apache-2.0
def load(template): """ Try to guess the input format """ try: data = load_json(template) return data, "json" except ValueError as e: try: data = load_yaml(template) return data, "yaml" except Exception: raise e
Try to guess the input format
load
python
awslabs/aws-cfn-template-flip
cfn_flip/__init__.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py
Apache-2.0
def dump_yaml(data, clean_up=False, long_form=False): """ Output some YAML """ return yaml.dump( data, Dumper=get_dumper(clean_up, long_form), default_flow_style=False, allow_unicode=True, width=config.max_col_width )
Output some YAML
dump_yaml
python
awslabs/aws-cfn-template-flip
cfn_flip/__init__.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py
Apache-2.0
def to_json(template, clean_up=False): """ Assume the input is YAML and convert to JSON """ data, _ = load(template) if clean_up: data = clean(data) return dump_json(data)
Assume the input is YAML and convert to JSON
to_json
python
awslabs/aws-cfn-template-flip
cfn_flip/__init__.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py
Apache-2.0
def to_yaml(template, clean_up=False, long_form=False, literal=True): """ Assume the input is JSON and convert to YAML """ data, _ = load(template) if clean_up: data = clean(data) if literal: data = cfn_literal_parser(data) return dump_yaml(data, clean_up, long_form)
Assume the input is JSON and convert to YAML
to_yaml
python
awslabs/aws-cfn-template-flip
cfn_flip/__init__.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py
Apache-2.0
def flip(template, in_format=None, out_format=None, clean_up=False, no_flip=False, long_form=False): """ Figure out the input format and convert the data to the opposing output format """ # Do we need to figure out the input format? if not in_format: # Load the template as JSON? if (out_format == "json" and no_flip) or (out_format == "yaml" and not no_flip): in_format = "json" elif (out_format == "yaml" and no_flip) or (out_format == "json" and not no_flip): in_format = "yaml" # Load the data if in_format == "json": data = load_json(template) elif in_format == "yaml": data = load_yaml(template) else: data, in_format = load(template) # Clean up? if clean_up: data = clean(data) # Figure out the output format if not out_format: if (in_format == "json" and no_flip) or (in_format == "yaml" and not no_flip): out_format = "json" else: out_format = "yaml" # Finished! if out_format == "json": return dump_json(data) return dump_yaml(data, clean_up, long_form)
Figure out the input format and convert the data to the opposing output format
flip
python
awslabs/aws-cfn-template-flip
cfn_flip/__init__.py
https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py
Apache-2.0
def test_sort_none(self): """Test list is returned a is""" a = [(3, 3), (3, 1), (3, 2), (1, 2), (2, 1)] ordered = packer.SORT_NONE(a) self.assertEqual(a, ordered) # Test empty list self.assertEqual(packer.SORT_NONE([]), [])
Test list is returned a is
test_sort_none
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_area(self): """Test rectangles are sorted by descending area""" a = [(5, 5), (7, 7), (3, 4), (100, 1)] ordered = packer.SORT_AREA(a) self.assertEqual(ordered, [(100, 1), (7, 7), (5, 5), (3, 4)]) # Test empty list self.assertEqual(packer.SORT_AREA([]), [])
Test rectangles are sorted by descending area
test_sort_area
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_peri(self): """Test rectangles are sorted by perimeter""" a = [(5, 5), (7, 7), (3, 4), (40, 1)] ordered = packer.SORT_PERI(a) self.assertEqual(ordered, [(40, 1), (7, 7), (5, 5), (3, 4)]) # Test empty list self.assertEqual(packer.SORT_PERI([]), [])
Test rectangles are sorted by perimeter
test_sort_peri
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_diff(self): """Test rectangles are sorted by the difference in side lengths""" a = [(7, 1), (1, 9), (2, 11), (5, 1)] ordered = packer.SORT_DIFF(a) self.assertEqual(ordered, [(2, 11), (1, 9), (7, 1), (5, 1)]) # Test empty list self.assertEqual(packer.SORT_DIFF([]), [])
Test rectangles are sorted by the difference in side lengths
test_sort_diff
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_sside(self): """Test rectangles are sorted by short side descending""" a = [(2, 9), (7, 3), (4, 5), (11, 3)] ordered = packer.SORT_SSIDE(a) self.assertEqual(ordered, [(4, 5), (11, 3), (7, 3), (2, 9)]) # Test empty list self.assertEqual(packer.SORT_SSIDE([]), [])
Test rectangles are sorted by short side descending
test_sort_sside
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_lside(self): """Test rectangles are sorted by long side descending""" a = [(19, 5), (32, 5), (6, 19), (9, 11)] ordered = packer.SORT_LSIDE(a) self.assertEqual(ordered, [(32, 5), (6, 19), (19, 5), (9, 11)]) # Test empty list self.assertEqual(packer.SORT_LSIDE([]), [])
Test rectangles are sorted by long side descending
test_sort_lside
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_sort_ratio(self): """Test rectangles are sorted by width/height descending""" a = [(12, 5), (15, 4), (4, 1), (1, 2)] ordered = packer.SORT_RATIO(a) self.assertEqual(ordered, [(4, 1), (15, 4), (12, 5), (1, 2)]) # Test empty list self.assertEqual(packer.SORT_RATIO([]), [])
Test rectangles are sorted by width/height descending
test_sort_ratio
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_bin_seelection(self): """Test bins are closed after one failed packing attempt""" p = packer.PackerBNF(pack_algo=guillotine.GuillotineBafSas, sort_algo=packer.SORT_NONE, rotation=False) p.add_bin(50, 50, count=100) p.add_bin(100, 100) p.add_bin(300, 300, count=100) p.add_rect(40, 40) p.add_rect(90, 90) p.add_rect(5, 5) p.add_rect(20, 20) p.add_rect(10, 10) p.pack() self.assertTrue((0, 0, 0, 40, 40, None) in p.rect_list()) self.assertTrue((1, 0, 0, 90, 90, None) in p.rect_list()) self.assertTrue((1, 0, 90, 5, 5, None) in p.rect_list()) self.assertTrue((2, 0, 0, 20, 20, None) in p.rect_list()) self.assertTrue((2, 0, 20, 10, 10, None) in p.rect_list()) self.assertEqual(len(p), 3) self.assertEqual(p[0].width, 50) self.assertEqual(p[1].width, 100) self.assertEqual(p[2].width, 50)
Test bins are closed after one failed packing attempt
test_bin_seelection
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_repack(self): """Test can be packed a second time""" p = packer.PackerGlobal(pack_algo=guillotine.GuillotineBafSas, rotation=False) p.add_bin(100, 100, count=float("inf")) p.add_rect(60, 60) p.add_rect(55, 55) p.pack() self.assertEqual(len(p), 2) self.assertEqual(len(p.rect_list()), 2) self.assertTrue((0, 0, 0, 60, 60, None) in p.rect_list()) self.assertTrue((1, 0, 0, 55, 55, None) in p.rect_list()) # Add more rectangles and repack p.add_rect(80, 10) p.add_rect(80, 80) p.pack() self.assertEqual(len(p.rect_list()), 4) self.assertTrue((0, 0, 0, 80, 80, None) in p.rect_list()) self.assertTrue((0, 0, 80, 80, 10, None) in p.rect_list()) self.assertTrue((1, 0, 0, 60, 60, None) in p.rect_list()) self.assertTrue((2, 0, 0, 55, 55, None) in p.rect_list())
Test can be packed a second time
test_repack
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_default_options(self): """Test newPacker default options""" # Test default options p = packer.newPacker() # Default mode Online BBF self.assertIsInstance(p, packer.PackerBBF) # Default rotations True self.assertEqual(p._rotation, True) # Default packing algorithm SkylineBlWm p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertIsInstance(p[0], maxrects.MaxRectsBssf) self.assertEqual(len(p[0]), 1) # Default sortin algorithm SORT_LSIDE self.assertEqual(p._sort_algo, packer.SORT_AREA)
Test newPacker default options
test_default_options
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_rotation(self): """Test newPacker rotation argument""" p = packer.newPacker(rotation=False) p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertEqual(len(p.rect_list()), 0) p = packer.newPacker(rotation=True) p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertEqual(len(p.rect_list()), 1)
Test newPacker rotation argument
test_rotation
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_pack_algo(self): """Test NewPacker use correct PackingAlgorithm""" p = packer.newPacker(pack_algo=skyline.SkylineMwfl) p.add_rect(10, 10) p.add_bin(100, 100) p.pack() self.assertIsInstance(p[0], skyline.SkylineMwfl)
Test NewPacker use correct PackingAlgorithm
test_pack_algo
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_mode_offline(self): """Test newPacker returns correct Packer when in offline mode""" p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BNF) self.assertIsInstance(p, packer.PackerBNF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) self.assertIsInstance(p, packer.PackerBFF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BBF) self.assertIsInstance(p, packer.PackerBBF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.Global) self.assertIsInstance(p, packer.PackerGlobal)
Test newPacker returns correct Packer when in offline mode
test_mode_offline
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_mode_online(self): """Test newPacker return correct Packer when in online mode""" p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BNF) self.assertIsInstance(p, packer.PackerOnlineBNF) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BFF) self.assertIsInstance(p, packer.PackerOnlineBFF) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BBF) self.assertIsInstance(p, packer.PackerOnlineBBF) with self.assertRaises(AttributeError): p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.Global)
Test newPacker return correct Packer when in online mode
test_mode_online
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_offline_sorting(self): """Test newPacker uses provided sort algorithm""" p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF, sort_algo=packer.SORT_RATIO) self.assertEqual(p._sort_algo, packer.SORT_RATIO) # Test sort_algo is ignored when not applicable p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.Global, sort_algo=packer.SORT_RATIO) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BFF, sort_algo=packer.SORT_RATIO)
Test newPacker uses provided sort algorithm
test_offline_sorting
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_bin_id(self): """Test correct bin id is assigned to each bin""" # width, height, count, bid bins = [(100, 50, 1, "first"), (50, 50, 1, "second"), (200, 200, 10, "many")] binIdx = {(b[0], b[1]): b[3] for b in bins} rects = [(199, 199), (100, 40), (40, 40), (20, 20), (180, 179)] p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) for b in bins: p.add_bin(b[0], b[1], count=b[2], bid=b[3]) for r in rects: p.add_rect(r[0], r[1]) p.pack() # verify bin ids correctly assigned for abin in p: self.assertEqual(binIdx[(abin.width, abin.height)], abin.bid)
Test correct bin id is assigned to each bin
test_bin_id
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_bin_default_id(self): """Test default bin id is None""" bins = [(100, 50, 1), (50, 50, 1), (200, 200, 10)] rects = [(199, 199), (100, 40), (40, 40), (20, 20), (180, 179)] p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) for b in bins: p.add_bin(b[0], b[1], count=b[2]) for r in rects: p.add_rect(r[0], r[1]) p.pack() # verify bin ids correctly assigned for abin in p: self.assertEqual(abin.bid, None)
Test default bin id is None
test_bin_default_id
python
secnot/rectpack
tests/test_packer.py
https://github.com/secnot/rectpack/blob/master/tests/test_packer.py
Apache-2.0
def test_skyline1(self): """Test skyline for complex positions is generated correctly +---------------------------+ | | +---------------------+ | | 4 | | +----------------+----+ | | 3 | | +----------+-----+ +-----+ | | | | | | | 5 | | 1 | | | | | | | | +----------+-----+ | | 2 | +----------+----------------+ """ s = skyline.SkylineMwf(100, 100, rot=False) rect1 = s.add_rect(40, 60) rect2 = s.add_rect(60, 10) rect3 = s.add_rect(70, 20) rect4 = s.add_rect(80, 20) rect5 = s.add_rect(20, 40) self.assertEqual(rect1, Rectangle(0, 0, 40, 60)) self.assertEqual(rect2, Rectangle(40, 0, 60, 10)) self.assertEqual(rect3, Rectangle(0, 60, 70, 20)) self.assertEqual(rect4, Rectangle(0, 80, 80, 20)) self.assertEqual(rect5, Rectangle(80, 10, 20, 40))
Test skyline for complex positions is generated correctly +---------------------------+ | | +---------------------+ | | 4 | | +----------------+----+ | | 3 | | +----------+-----+ +-----+ | | | | | | | 5 | | 1 | | | | | | | | +----------+-----+ | | 2 | +----------+----------------+
test_skyline1
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline2(self): """ +---------------------------+ | | | | | +--------------------+ | | 4 | | | | +----+ +-----------+--------+ | | | | | | | | | | | | | | | | | 1 | | 3 | | | | | | | | | | +-------------+ | | | 2 | | +----+-------------+--------+ """ s = skyline.SkylineMwfl(100, 100, rot=False) rect1 = s.add_rect(20, 60) rect2 = s.add_rect(50, 10) rect3 = s.add_rect(30, 60) rect4 = s.add_rect(70, 20) self.assertEqual(rect1, Rectangle(0, 0, 20, 60)) self.assertEqual(rect2, Rectangle(20, 0, 50, 10)) self.assertEqual(rect3, Rectangle(70, 0, 30, 60)) self.assertEqual(rect4, Rectangle(30, 60, 70, 20))
+---------------------------+ | | | | | +--------------------+ | | 4 | | | | +----+ +-----------+--------+ | | | | | | | | | | | | | | | | | 1 | | 3 | | | | | | | | | | +-------------+ | | | 2 | | +----+-------------+--------+
test_skyline2
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline3(self): """ +-------------------+-------+ | 10 | | +----+----+---------+ | | | | | 9 | | | w2 | 8 | | | 6 | | | | | | +---------+-------+ | +----+ | +----+ | 5 | | | 7 +---+-------------+ | | |w1 | | | +--------+ 4 | | 1 | | | | | 2 +----------+--+ | | | 3 | | +----+--------+----------+--+ """ s = skyline.SkylineMwf(100, 100, rot=False) rect1 = s.add_rect(20, 50) rect2 = s.add_rect(30, 30) rect3 = s.add_rect(40, 10) rect4 = s.add_rect(50, 40) rect5 = s.add_rect(70, 20) rect6 = s.add_rect(20, 40) rect7 = s.add_rect(10, 30) rect8 = s.add_rect(40, 20) rect9 = s.add_rect(30, 30) rect10 = s.add_rect(70, 10) w1 = s.add_rect(20, 20) w2 = s.add_rect(10, 30) self.assertEqual(rect1, Rectangle(0, 0, 20, 50)) self.assertEqual(rect2, Rectangle(20, 0, 30, 30)) self.assertEqual(rect3, Rectangle(50, 0, 40, 10)) self.assertEqual(rect4, Rectangle(50, 10, 50, 40)) self.assertEqual(rect5, Rectangle(30, 50, 70, 20)) self.assertEqual(rect6, Rectangle(0, 50, 20, 40)) self.assertEqual(rect7, Rectangle(20, 30, 10, 30)) self.assertEqual(rect8, Rectangle(30, 70, 40, 20)) self.assertEqual(rect9, Rectangle(70, 70, 30, 30)) self.assertEqual(rect10, Rectangle(0, 90, 70, 10)) self.assertEqual(w1, None) self.assertEqual(w2, None) # With Waste management enabled s = skyline.SkylineMwfWm(100, 100, rot=False) rect1 = s.add_rect(20, 50) rect2 = s.add_rect(30, 30) rect3 = s.add_rect(40, 10) rect4 = s.add_rect(50, 40) rect5 = s.add_rect(70, 20) rect6 = s.add_rect(20, 40) rect7 = s.add_rect(10, 30) rect8 = s.add_rect(40, 20) rect9 = s.add_rect(30, 30) rect10 = s.add_rect(70, 10) w1 = s.add_rect(20, 20) w2 = s.add_rect(10, 30) self.assertEqual(rect1, Rectangle(0, 0, 20, 50)) self.assertEqual(rect2, Rectangle(20, 0, 30, 30)) self.assertEqual(rect3, Rectangle(50, 0, 40, 10)) self.assertEqual(rect4, Rectangle(50, 10, 50, 40)) self.assertEqual(rect5, Rectangle(30, 50, 70, 20)) self.assertEqual(rect6, Rectangle(0, 50, 20, 40)) self.assertEqual(rect7, Rectangle(20, 30, 10, 30)) self.assertEqual(rect8, Rectangle(30, 70, 40, 20)) self.assertEqual(rect9, Rectangle(70, 70, 30, 30)) self.assertEqual(rect10, Rectangle(0, 90, 70, 10)) self.assertEqual(w1, Rectangle(30, 30, 20, 20)) self.assertEqual(w2, Rectangle(20, 60, 10, 30))
+-------------------+-------+ | 10 | | +----+----+---------+ | | | | | 9 | | | w2 | 8 | | | 6 | | | | | | +---------+-------+ | +----+ | +----+ | 5 | | | 7 +---+-------------+ | | |w1 | | | +--------+ 4 | | 1 | | | | | 2 +----------+--+ | | | 3 | | +----+--------+----------+--+
test_skyline3
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline4(self): """ +---------------------+-----+ | 4 | 5 | | | | +----+----------------------+ | | | | | | | | | | | | | | w1 | | | 1 | | 3 | | | | | | | | | | | | | | +----------------+ | | | | | | | 2 | | | | | | +----+----------------+-----+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(20, 80) rect2 = s.add_rect(60, 20) rect3 = s.add_rect(20, 80) rect4 = s.add_rect(80, 20) w1 = s.add_rect(60, 50) rect5 = s.add_rect(20, 20) self.assertEqual(rect1, Rectangle(0, 0, 20, 80)) self.assertEqual(rect2, Rectangle(20, 0, 60, 20)) self.assertEqual(rect3, Rectangle(80, 0, 20, 80)) self.assertEqual(rect4, Rectangle(0, 80, 80, 20)) self.assertEqual(rect5, Rectangle(80, 80, 20, 20)) self.assertEqual(w1, Rectangle(20, 20, 60, 50))
+---------------------+-----+ | 4 | 5 | | | | +----+----------------------+ | | | | | | | | | | | | | | w1 | | | 1 | | 3 | | | | | | | | | | | | | | +----------------+ | | | | | | | 2 | | | | | | +----+----------------+-----+
test_skyline4
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline5(self): """ +------+--------------+-----+ | | | | | 8 | 5 | | | | | | | +--------------------+ +------+ | | | | | | | | 4 | 7 | | | | | | | +-----+ | 1 +---------+----+ | | | | w1 | | | | | | 6 | | | 2 +----+ | | | | 3 | | | | | | | +------+---------+----+-----+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(20, 70) rect2 = s.add_rect(30, 40) rect3 = s.add_rect(20, 20) rect4 = s.add_rect(50, 40) rect5 = s.add_rect(50, 20) rect6 = s.add_rect(30, 50) rect7 = s.add_rect(20, 30) rect8 = s.add_rect(20, 30) w1 = s.add_rect(20, 20) self.assertEqual(rect1, Rectangle(0, 0, 20, 70)) self.assertEqual(rect2, Rectangle(20, 0, 30, 40)) self.assertEqual(rect3, Rectangle(50, 0, 20, 20)) self.assertEqual(rect4, Rectangle(20, 40, 50, 40)) self.assertEqual(rect5, Rectangle(20, 80, 50, 20)) self.assertEqual(rect6, Rectangle(70, 0, 30, 50)) self.assertEqual(rect7, Rectangle(70, 50, 20, 30)) self.assertEqual(rect8, Rectangle(0, 70, 20, 30)) self.assertEqual(w1, Rectangle(50, 20, 20, 20))
+------+--------------+-----+ | | | | | 8 | 5 | | | | | | | +--------------------+ +------+ | | | | | | | | 4 | 7 | | | | | | | +-----+ | 1 +---------+----+ | | | | w1 | | | | | | 6 | | | 2 +----+ | | | | 3 | | | | | | | +------+---------+----+-----+
test_skyline5
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline6(self): """ +-------------+-------------+ | | | | 4 | | | +-------------+ | | | +-------------* 5 | | 3 | | | | | +-------------+--+----------+ | | | | 2 | | | | | +----------------+----+ | | | | | 1 | | | | | +---------------------+-----+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(80, 30) rect2 = s.add_rect(60, 20) rect3 = s.add_rect(50, 20) rect4 = s.add_rect(50, 30) rect5 = s.add_rect(50, 30) self.assertEqual(rect1, Rectangle(0, 0, 80, 30)) self.assertEqual(rect2, Rectangle(0, 30, 60, 20)) self.assertEqual(rect3, Rectangle(0, 50, 50, 20)) self.assertEqual(rect4, Rectangle(0, 70, 50, 30)) self.assertEqual(rect5, Rectangle(50, 50, 50, 30))
+-------------+-------------+ | | | | 4 | | | +-------------+ | | | +-------------* 5 | | 3 | | | | | +-------------+--+----------+ | | | | 2 | | | | | +----------------+----+ | | | | | 1 | | | | | +---------------------+-----+
test_skyline6
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline7(self): """ +-----------------+---------+ +-----------------+ | | | | | 4 | | | | | +-----------+-----+ | | | | 5 | | | | | | w1 | | | | | | | | | 2 | | | | | | +-----------+ +---------+ | | | | | 1 | | 3 | | | | | +-----------+-----+---------+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(40, 20) rect2 = s.add_rect(20, 60) rect3 = s.add_rect(40, 20) rect4 = s.add_rect(60, 20) rect5 = s.add_rect(40, 80) w1 = s.add_rect(40, 40) self.assertEqual(rect1, Rectangle(0, 0, 40, 20)) self.assertEqual(rect2, Rectangle(40, 0, 20, 60)) self.assertEqual(rect3, Rectangle(60, 0, 40, 20)) self.assertEqual(rect4, Rectangle(0, 60, 60, 20)) self.assertEqual(rect5, Rectangle(60, 20, 40, 80)) self.assertEqual(w1, Rectangle(0, 20, 40, 40))
+-----------------+---------+ +-----------------+ | | | | | 4 | | | | | +-----------+-----+ | | | | 5 | | | | | | w1 | | | | | | | | | 2 | | | | | | +-----------+ +---------+ | | | | | 1 | | 3 | | | | | +-----------+-----+---------+
test_skyline7
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline8(self): """ +---------------------------+ | | +----------------------+ | | 4 | | | | | +-----------+-----+----+ | | | | | | | | | | w1 | | | | | | | | | 2 | | | | | | +-----------+ | | | | +---------+ | 1 | | 3 | | | | | +-----------+-----+---------+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(40, 20) rect2 = s.add_rect(20, 60) rect3 = s.add_rect(40, 10) rect4 = s.add_rect(80, 20) w1 = s.add_rect(40, 40) self.assertEqual(rect1, Rectangle(0, 0, 40, 20)) self.assertEqual(rect2, Rectangle(40, 0, 20, 60)) self.assertEqual(rect3, Rectangle(60, 0, 40, 10)) self.assertEqual(rect4, Rectangle(0, 60, 80, 20)) self.assertEqual(w1, Rectangle(0, 20, 40, 40))
+---------------------------+ | | +----------------------+ | | 4 | | | | | +-----------+-----+----+ | | | | | | | | | | w1 | | | | | | | | | 2 | | | | | | +-----------+ | | | | +---------+ | 1 | | 3 | | | | | +-----------+-----+---------+
test_skyline8
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline9(self): """ +---------------------------+ | | | +---------------------+ | | 4 | | | | | +-----+-----+---------+ | | | | | | | | | | | w1 | | | | | | | 2 | | | | | | | | +---------+ | | | | +-----------+ | 3 | | 1 | | | +-----------+-----+---------+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(40, 20) rect2 = s.add_rect(20, 60) rect3 = s.add_rect(40, 30) rect4 = s.add_rect(80, 20) w1 = s.add_rect(40, 30) self.assertEqual(rect1, Rectangle(0, 0, 40, 20)) self.assertEqual(rect2, Rectangle(40, 0, 20, 60)) self.assertEqual(rect3, Rectangle(60, 0, 40, 30)) self.assertEqual(rect4, Rectangle(20, 60, 80, 20)) self.assertEqual(w1, Rectangle(60, 30, 40, 30))
+---------------------------+ | | | +---------------------+ | | 4 | | | | | +-----+-----+---------+ | | | | | | | | | | | w1 | | | | | | | 2 | | | | | | | | +---------+ | | | | +-----------+ | 3 | | 1 | | | +-----------+-----+---------+
test_skyline9
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline10(self): """ +---------------------------+ | | | | | | | | | +----+ | | | | | | | | | +----------------+ | | | | | | | +-----+ 3 | | 1 | | | | | 2 | | | | | | | | | | +----------------+-----+----+ With rotation """ s = skyline.SkylineMwfl(100, 100, rot=True) rect1 = s.add_rect(50, 40) rect2 = s.add_rect(30, 30) rect3 = s.add_rect(70, 20) self.assertEqual(rect1, Rectangle(0, 0, 50, 40)) self.assertEqual(rect2, Rectangle(50, 0, 30, 30)) self.assertEqual(rect3, Rectangle(80, 0, 20, 70))
+---------------------------+ | | | | | | | | | +----+ | | | | | | | | | +----------------+ | | | | | | | +-----+ 3 | | 1 | | | | | 2 | | | | | | | | | | +----------------+-----+----+ With rotation
test_skyline10
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_getitem(self): """ Test __getitem__ works with all rectangles included waste. +---------------------------+ | | | +---------------------+ | | 4 | | | | | +-----+-----+---------+ | | | | | | | | | | | w1 | | | | | | | 2 | | | | | | | | +---------+ | | | | +-----------+ | 3 | | 1 | | | +-----------+-----+---------+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(40, 20) rect2 = s.add_rect(20, 60) rect3 = s.add_rect(40, 30) rect4 = s.add_rect(80, 20) w1 = s.add_rect(40, 30) self.assertEqual(s[0], Rectangle(0, 0, 40, 20)) self.assertEqual(s[1], Rectangle(40, 0, 20, 60)) self.assertEqual(s[2], Rectangle(60, 0, 40, 30)) self.assertEqual(s[3], Rectangle(20, 60, 80, 20)) self.assertEqual(s[4], Rectangle(60, 30, 40, 30)) self.assertEqual(s[-1], Rectangle(60, 30, 40, 30)) self.assertEqual(s[3:], [Rectangle(20, 60, 80, 20), Rectangle(60, 30, 40, 30)])
Test __getitem__ works with all rectangles included waste. +---------------------------+ | | | +---------------------+ | | 4 | | | | | +-----+-----+---------+ | | | | | | | | | | | w1 | | | | | | | 2 | | | | | | | | +---------+ | | | | +-----------+ | 3 | | 1 | | | +-----------+-----+---------+
test_getitem
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_fitness(self): """Test position wasting less space has better fitness""" p = skyline.SkylineMwf(100, 100, rot=False) p.add_rect(20, 20) self.assertTrue(p.fitness(90, 10) < p.fitness(100, 10))
Test position wasting less space has better fitness
test_fitness
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline(self): """ +---------------------------+ | | | | +----+ +------------------+ | | | 5 | | | +---+--+-----------+ | | | | | | | | | | | | | | | | 1 | | | | | | | +-----------+ | +-------+ 3| | | | | | | | | | | 4 | | | 2 | | | | | | | | +----+-------+--+-----------+ """ s = skyline.SkylineMwf(100, 100, rot=False) rect1 = s.add_rect(20, 80) rect2 = s.add_rect(20, 40) rect3 = s.add_rect(20, 70) rect4 = s.add_rect(40, 50) rect5 = s.add_rect(70, 10) self.assertEqual(rect1, Rectangle(0, 0, 20, 80)) self.assertEqual(rect2, Rectangle(20, 0, 20, 40)) self.assertEqual(rect3, Rectangle(40, 0, 20, 70)) self.assertEqual(rect4, Rectangle(60, 0, 40, 50)) self.assertEqual(rect5, Rectangle(30, 70, 70, 10))
+---------------------------+ | | | | +----+ +------------------+ | | | 5 | | | +---+--+-----------+ | | | | | | | | | | | | | | | | 1 | | | | | | | +-----------+ | +-------+ 3| | | | | | | | | | | 4 | | | 2 | | | | | | | | +----+-------+--+-----------+
test_skyline
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_init(self): """Test Waste management is enabled""" p = skyline.SkylineMwfWm(100, 100) self.assertTrue(p._waste_management)
Test Waste management is enabled
test_init
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline(self): """ +---------------------------+ | | | | +----+ +------------------+ | | | 5 | | | +---+--+-----------+ | | | | | | | | | | | | | | w1 | | 1 | | | | | | | +-----------+ | +-------+ 3| | | | | | | | | | | 4 | | | 2 | | | | | | | | +----+-------+--+-----------+ """ s = skyline.SkylineMwfWm(100, 100, rot=False) rect1 = s.add_rect(20, 80) rect2 = s.add_rect(20, 40) rect3 = s.add_rect(20, 70) rect4 = s.add_rect(40, 50) rect5 = s.add_rect(70, 10) w1 = s.add_rect(40, 20) self.assertEqual(rect1, Rectangle(0, 0, 20, 80)) self.assertEqual(rect2, Rectangle(20, 0, 20, 40)) self.assertEqual(rect3, Rectangle(40, 0, 20, 70)) self.assertEqual(rect4, Rectangle(60, 0, 40, 50)) self.assertEqual(rect5, Rectangle(30, 70, 70, 10)) self.assertEqual(w1, Rectangle(60, 50, 40, 20))
+---------------------------+ | | | | +----+ +------------------+ | | | 5 | | | +---+--+-----------+ | | | | | | | | | | | | | | w1 | | 1 | | | | | | | +-----------+ | +-------+ 3| | | | | | | | | | | 4 | | | 2 | | | | | | | | +----+-------+--+-----------+
test_skyline
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_fitness(self): """Test lower one has best fitness""" p = skyline.SkylineMwfl(100, 100, rot=False) p.add_rect(20, 20) self.assertTrue(p.fitness(90, 10) < p.fitness(90, 20))
Test lower one has best fitness
test_fitness
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline1(self): """ +---------------------------+ | | | | | | | | | | | | | +--------+ +------------------+ 3 | | | | | +--------+ | | | | 1 | | | | 2 | | | | | | | +------------------+--------+ """ s = skyline.SkylineMwfl(100, 100, rot=True) rect1 = s.add_rect(70, 50) rect2 = s.add_rect(40, 30) rect3 = s.add_rect(20, 30) self.assertEqual(rect1, Rectangle(0, 0, 70, 50)) self.assertEqual(rect2, Rectangle(70, 0, 30, 40)) self.assertEqual(rect3, Rectangle(70, 40, 30, 20))
+---------------------------+ | | | | | | | | | | | | | +--------+ +------------------+ 3 | | | | | +--------+ | | | | 1 | | | | 2 | | | | | | | +------------------+--------+
test_skyline1
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline2(self): """ +---------------------------+ | | | | | | | | | | | | | | | | | | +-----------+---------------+ | | 3 | | | | | 1 +---------+-----+ | | 2 | | | | | | +-----------+---------+-----+ """ s = skyline.SkylineMwfl(100, 100, rot=False) rect1 = s.add_rect(40, 40) rect2 = s.add_rect(40, 20) rect3 = s.add_rect(60, 20) self.assertEqual(rect1, Rectangle(0, 0, 40, 40)) self.assertEqual(rect2, Rectangle(40, 0, 40, 20)) self.assertEqual(rect3, Rectangle(40, 20, 60, 20))
+---------------------------+ | | | | | | | | | | | | | | | | | | +-----------+---------------+ | | 3 | | | | | 1 +---------+-----+ | | 2 | | | | | | +-----------+---------+-----+
test_skyline2
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_init(self): """Test Waste management is enabled""" p = skyline.SkylineMwflWm(100, 100) self.assertTrue(p._waste_management)
Test Waste management is enabled
test_init
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline(self): """ +---------------------------+ | | | | | | | | | | | | | | | | | | +-----------+---------------+ | | 3 | | | | | 1 +---------+-----+ | | 2 | w1 | | | | | +-----------+---------+-----+ """ s = skyline.SkylineMwflWm(100, 100, rot=False) rect1 = s.add_rect(40, 40) rect2 = s.add_rect(40, 20) rect3 = s.add_rect(60, 20) w1 = s.add_rect(20, 20) self.assertEqual(rect1, Rectangle(0, 0, 40, 40)) self.assertEqual(rect2, Rectangle(40, 0, 40, 20)) self.assertEqual(rect3, Rectangle(40, 20, 60, 20)) self.assertEqual(w1, Rectangle(80, 0, 20, 20))
+---------------------------+ | | | | | | | | | | | | | | | | | | +-----------+---------------+ | | 3 | | | | | 1 +---------+-----+ | | 2 | w1 | | | | | +-----------+---------+-----+
test_skyline
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_init(self): """Test Waste management is disabled""" p = skyline.SkylineBl(100, 100) self.assertFalse(p._waste_management)
Test Waste management is disabled
test_init
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_fitness(self): """Test lower is better""" p = skyline.SkylineBl(100, 100, rot=False) self.assertEqual(p.fitness(100, 20), p.fitness(10, 20)) self.assertTrue(p.fitness(100, 10) < p.fitness(100, 11)) # The same but with wasted space p = skyline.SkylineBl(100, 100, rot=False) p.add_rect(80, 50) self.assertEqual(p.fitness(100, 10), p.fitness(80, 10)) self.assertTrue(p.fitness(100, 10) < p.fitness(40, 20))
Test lower is better
test_fitness
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline1(self): """ +---------------------------+ | | | | | | | | | | | | +-------------+-------------+ | 4 | | | | | +---------+---+ | | | | 3 | | | | | | 1 +---+ | | | 2 | | | | | | +---------+---+-------------+ Test lower positions is better than one not losing space """ s = skyline.SkylineBl(100, 100, rot=False) rect1 = s.add_rect(40, 30) rect2 = s.add_rect(10, 20) rect3 = s.add_rect(50, 50) rect4 = s.add_rect(50, 20) self.assertEqual(rect1, Rectangle(0, 0, 40, 30)) self.assertEqual(rect2, Rectangle(40, 0, 10, 20)) self.assertEqual(rect3, Rectangle(50, 0, 50, 50)) self.assertEqual(rect4, Rectangle(0, 30, 50, 20))
+---------------------------+ | | | | | | | | | | | | +-------------+-------------+ | 4 | | | | | +---------+---+ | | | | 3 | | | | | | 1 +---+ | | | 2 | | | | | | +---------+---+-------------+ Test lower positions is better than one not losing space
test_skyline1
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline2(self): """ +---------------------------+ | | | | | | +--------------------+ | | | | | 4 +------+ | | 5 | | | | +----------------+---+------+ | | 3 | | | | | 1 +-----+----+ | | 2 | | | | | | +----------------+-----+----+ """ s = skyline.SkylineBl(100, 100, rot=False) rect1 = s.add_rect(50, 40) rect2 = s.add_rect(30, 20) rect3 = s.add_rect(50, 20) rect4 = s.add_rect(70, 30) rect5 = s.add_rect(20, 20) self.assertEqual(rect1, Rectangle(0, 0, 50, 40)) self.assertEqual(rect2, Rectangle(50, 0, 30, 20)) self.assertEqual(rect3, Rectangle(50, 20, 50, 20)) self.assertEqual(rect4, Rectangle(0, 40, 70, 30)) self.assertEqual(rect5, Rectangle(70, 40, 20, 20))
+---------------------------+ | | | | | | +--------------------+ | | | | | 4 +------+ | | 5 | | | | +----------------+---+------+ | | 3 | | | | | 1 +-----+----+ | | 2 | | | | | | +----------------+-----+----+
test_skyline2
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_init(self): """Test Waste management is enabled""" p = skyline.SkylineBlWm(100, 100) self.assertTrue(p._waste_management)
Test Waste management is enabled
test_init
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def test_skyline1(self): """ +---------------------------+ | | | | | | | | +--------------------+ | | | | | 4 | | | | | | | | +----------------+---+------+ | | 3 | | | | | 1 +-----+----+ | | 2 | w1 | | | | | +----------------+-----+----+ """ s = skyline.SkylineBlWm(100, 100, rot=False) rect1 = s.add_rect(50, 40) rect2 = s.add_rect(30, 20) rect3 = s.add_rect(50, 20) rect4 = s.add_rect(70, 30) w1 = s.add_rect(20, 20) self.assertEqual(rect1, Rectangle(0, 0, 50, 40)) self.assertEqual(rect2, Rectangle(50, 0, 30, 20)) self.assertEqual(rect3, Rectangle(50, 20, 50, 20)) self.assertEqual(rect4, Rectangle(0, 40, 70, 30)) self.assertEqual(w1, Rectangle(80, 0, 20, 20))
+---------------------------+ | | | | | | | | +--------------------+ | | | | | 4 | | | | | | | | +----------------+---+------+ | | 3 | | | | | 1 +-----+----+ | | 2 | w1 | | | | | +----------------+-----+----+
test_skyline1
python
secnot/rectpack
tests/test_skyline.py
https://github.com/secnot/rectpack/blob/master/tests/test_skyline.py
Apache-2.0
def helper(): """create a bunch of tests to copy and paste into TestFactory""" for mode in PackingMode: for bin_algo in PackingBin: for size, w, h in ('big_enough', 50, 50), ('too_small', 5, 5): name = '_'.join(('test', mode, bin_algo, size)) print("""\ def %s(self): # create bins that are %s to hold the rectangles p = self._common(PackingMode.%s, PackingBin.%s, %s, %s)""" % (name, size.replace('_', ' '), mode, bin_algo, w, h)) if size == 'big_enough': print("""\ # check that bins were created self.assertGreater(len(p.bin_list()), 0) # check that all of the rectangles made it in self.assertEqual(len(p.rect_list()), len(self.rectangles)) """) else: print("""\ # check that none of the rectangles made it in self.assertEqual(len(p.rect_list()), 0) """)
create a bunch of tests to copy and paste into TestFactory
helper
python
secnot/rectpack
tests/test_factory.py
https://github.com/secnot/rectpack/blob/master/tests/test_factory.py
Apache-2.0
def test_getitem(self): """Test __getitem__ returns requested element or slice""" g = guillotine.GuillotineBafSas(100, 100) g.add_rect(10, 10) g.add_rect(5, 5) g.add_rect(1, 1) self.assertEqual(g[0], Rectangle(0, 0, 10, 10)) self.assertEqual(g[1], Rectangle(0, 10, 5, 5)) self.assertEqual(g[2], Rectangle(5, 10, 1, 1)) self.assertEqual(g[-1], Rectangle(5, 10, 1, 1)) self.assertEqual(g[-2], Rectangle(0, 10, 5, 5)) self.assertEqual(g[1:], [Rectangle(0, 10, 5, 5), Rectangle(5, 10, 1, 1)]) self.assertEqual(g[0:2], [Rectangle(0, 0, 10, 10), Rectangle(0, 10, 5, 5)])
Test __getitem__ returns requested element or slice
test_getitem
python
secnot/rectpack
tests/test_guillotine.py
https://github.com/secnot/rectpack/blob/master/tests/test_guillotine.py
Apache-2.0
def random_rectangle_generator(num, max_side=30, min_side=8): """ Generate a random rectangle list with dimensions within specified parameters. Arguments: max_dim (number): Max rectangle side length min_side (number): Min rectangle side length max_ratio (number): Returns: Rectangle list """ return (random_rectangle(max_side, min_side) for i in range(0, num))
Generate a random rectangle list with dimensions within specified parameters. Arguments: max_dim (number): Max rectangle side length min_side (number): Min rectangle side length max_ratio (number): Returns: Rectangle list
random_rectangle_generator
python
secnot/rectpack
tests/test_enclose.py
https://github.com/secnot/rectpack/blob/master/tests/test_enclose.py
Apache-2.0
def test_containment(self): """ Test all rectangles are inside the container area """ en = enclose.Enclose(self.rectangles, self.max_width, self.max_height, True) packer = en.generate() # Check all rectangles are inside container packer.validate_packing()
Test all rectangles are inside the container area
test_containment
python
secnot/rectpack
tests/test_enclose.py
https://github.com/secnot/rectpack/blob/master/tests/test_enclose.py
Apache-2.0
def test_failed_envelope(self): """ Test container not found """ en = enclose.Enclose(self.rectangles, max_width=50, max_height=50) packer = en.generate() self.assertEqual(packer, None) en = enclose.Enclose(max_width=50, max_height=50) packer = en.generate() self.assertEqual(packer, None)
Test container not found
test_failed_envelope
python
secnot/rectpack
tests/test_enclose.py
https://github.com/secnot/rectpack/blob/master/tests/test_enclose.py
Apache-2.0
def random_rectangle_generator(num, max_side=30, min_side=8): """ Generate a random rectangle list with dimensions within specified parameters. Arguments: max_dim (number): Max rectangle side length min_side (number): Min rectangle side length max_ratio (number): Returns: Rectangle list """ return (random_rectangle(max_side, min_side) for i in range(0, num))
Generate a random rectangle list with dimensions within specified parameters. Arguments: max_dim (number): Max rectangle side length min_side (number): Min rectangle side length max_ratio (number): Returns: Rectangle list
random_rectangle_generator
python
secnot/rectpack
tests/test_collisions.py
https://github.com/secnot/rectpack/blob/master/tests/test_collisions.py
Apache-2.0
def test_bool(self): """Test rectangles evaluates a True""" r = Rectangle(1, 2, 3, 4) self.assertTrue(r)
Test rectangles evaluates a True
test_bool
python
secnot/rectpack
tests/test_geometry.py
https://github.com/secnot/rectpack/blob/master/tests/test_geometry.py
Apache-2.0