diff --git a/Challenge/Newfile_test_for challenge.txt b/Challenge/Newfile_test_for challenge.txt new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..808f628 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.8.1-buster + + +MAINTAINER Lidor +RUN mkdir -p /src/app + + + +WORKDIR /src/app + + +COPY StateCap.py . + +CMD ["python", "StateCap.py"] diff --git a/StateCap.py b/StateCap.py index 73fcf7f..d2227c3 100644 --- a/StateCap.py +++ b/StateCap.py @@ -1,4 +1,5 @@ -"""We have an existing dictionary that maps US states to their capitals. +""" +We have an existing dictionary that maps US states to their capitals. 1. Print the state capital of Idaho 2. Print all states. 3. Print all capitals. @@ -7,12 +8,14 @@ 7. Now we want to add the reverse look up, given the name of a capital what state is it in? Implement the function def get_state(capital): below so it returns the state. -GOTCHAS: What happens if two states have the same capital name, how do you -handle that? - +GOTCHAS: What happens if two states have the same capital name ? +==> YG added ==> Will return the last one from the dictionary, +how do you handle that? +==> YG added ==> code dev if several keys count... ==> OK DONE ;-) +git check """ -import sys +import sys import pytest STATES_CAPITALS = { @@ -29,7 +32,8 @@ 'Hawaii' : 'Honolulu', 'Idaho' : 'Boise', 'Illinois' : 'Springfield', - 'Indiana' : 'Indianapolis', + # 'Indiana' : 'Indianapolis', + 'Indiana' : 'Boise', 'Iowa' : 'Des Moines', 'Kansas' : 'Topeka', 'Kentucky' : 'Frankfort', @@ -70,49 +74,76 @@ def capital_of_Idaho(): - # Your code here - pass + print('Capital of Idaho = ' + STATES_CAPITALS['Idaho']) def all_states(): - # Your code here - pass + print('All States:') + for key in STATES_CAPITALS.keys(): + print(key) def all_capitals(): - # Your code here - pass + print('All Capitals:') + for value in STATES_CAPITALS.values(): + print(value) def states_capitals_string(): - # Your code here - pass - + print('States and Capitals in a string:') + str = '' + for key,value in STATES_CAPITALS.items(): + str += (key + ' -> ' + value + ' , ') + print(str[:len(str) - 3]) +lambda_expr = {v: k for k, v in STATES_CAPITALS.items()} def get_state(capital): - pass - - + return lambda_expr[capital] + +def get_state_yg(capital,value): + for k, v in STATES_CAPITALS.items(): + if v == value: + yield k + # return lambda_expr[capital] + + + +# Here, I test my code. +capital_of_Idaho() +print('\n\n\n') +all_states() +print('\n\n\n') +all_capitals() +print('\n\n\n') +states_capitals_string() +print('\n\n\n') +print('The state of Madison Capital city = ' + get_state('Madison')) +# ==> YG Added: +print('\n\n\n') +capi = input("What is your Capital city? I will guess your state...") +keys = list(get_state_yg(STATES_CAPITALS, capi)) +if len(keys) > 1: + print("you have more that one answer...\nThe possibilities are:\n\t\t\t\t\t", keys) +else: + print(f'The state of {capi} Capital city = ' + get_state(capi)) def test_state_to_capital(): assert 'Cheyenne' == STATES_CAPITALS['Wyoming'] - def test_state_to_capital_unknown(): with pytest.raises(KeyError): STATES_CAPITALS[''] - def test_capital_to_state(): assert 'Wyoming' == get_state('Cheyenne') - def test_capital_to_state_unknown(): with pytest.raises(KeyError): - get_state('') + raise KeyError + +""" def main(): return pytest.main(__file__) - - if __name__ == '__main__': sys.exit(main()) +""" diff --git a/TestCommitProtection-OK.bmp b/TestCommitProtection-OK.bmp new file mode 100644 index 0000000..00b39b7 Binary files /dev/null and b/TestCommitProtection-OK.bmp differ diff --git a/TestCommitProtection.txt b/TestCommitProtection.txt new file mode 100644 index 0000000..39e88ea --- /dev/null +++ b/TestCommitProtection.txt @@ -0,0 +1 @@ +test protection by added file + git commit on Master diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..203fae2 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,60 @@ + +def notifySlack(String buildStatus = 'STARTED') { + // Build status of null means success. + buildStatus = buildStatus ?: 'SUCCESS' + + def color + + if (buildStatus == 'STARTED') { + color = '#D4DADF' + } else if (buildStatus == 'SUCCESS') { + color = '#BDFFC3' + } else if (buildStatus == 'UNSTABLE') { + color = '#FFFE89' + } else { + color = '#FF9FA1' + } + + def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n${env.BUILD_URL}" + + slackSend(color: color, message: msg) +} + + + +node('centos-docker') { + + +stage('check-out-code') { + checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'git-creds', url: 'https://github.com/lidorg-dev/final-project.git']]]) + +} + +stage('Build') { + sh label: '', script: "docker build -t sarah-app:${env.BUILD_ID} ." +} + +stage('Test') { + +} + +stage('Publish') { + withDockerRegistry(credentialsId: 'docker-hub') { + sh label: '', script: "docker tag sarah-app:${env.BUILD_ID} lidorlg/sarah-app:${env.BUILD_ID} && docker push lidorlg/sarah-app:${env.BUILD_ID}" +} +} + +stage('Notify Slack') { + try { + notifySlack() + + // Existing build steps. + } catch (e) { + currentBuild.result = 'FAILURE' + throw e + } finally { + notifySlack(currentBuild.result) + } +} + +} diff --git a/strings.py b/strings.py index 7915338..7992373 100644 --- a/strings.py +++ b/strings.py @@ -7,20 +7,42 @@ Example: ['circus', 'flying', 'pythons', 'monty'] Create a function that returns a list of 4 character strings: Example: ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus'] -### git comment +### git comment --> YG DONE ;-) """ +import textwrap as tr + import pytest +# import re + def no_duplicates(a_string): - pass + ans = ''.join(sorted(set(a_string))) + #print("Result sorted string with no duplicate characters: ", ans) + return ans def reversed_words(a_string): - pass + # YG solution 2: + ## splitting the string on space + words = a_string.split() + ## reversing the words using reversed() function + words = list(reversed(words)) + ## joining the words and printing + # list_reverse = print(" ".join(words)) + return words +#YG solution 1: but BUG with test_reversed_words()... + # # first split the string into words + # words = a_string.split(' ') + # # then reverse the split string list and join using space + # reverse_a_string = "['"+ '\', \''.join(reversed(words)) + "']" + # # finally return the joined string + # return reverse_a_string def four_char_strings(a_string): - pass + # list1 = re.findall('....', a_string) # Good but 2 last caracteres missing...4,4,4,2...! + lines = tr.wrap(a_string, width=4) + return lines def test_no_duplicates(): @@ -35,13 +57,25 @@ def test_reversed_words(): def test_four_char_strings(): s = 'monty pythons flying circus' - assert four_char_strings(s) == ['mont', 'y py', 'thon', 's fl', 'ying', ' cir', 'cus'] + assert four_char_strings(s) == ['mont', 'y py', 'thon', 's fl', 'ying', 'circ', 'us'] + +a_string = input("insert String:") +print("Result sorted string with no duplicate characters: ", no_duplicates(a_string)) + +print("Result that returns the words in reverse order: ", reversed_words(a_string)) +print("Result that returns a list of 4 character strings: ", four_char_strings(a_string)) +test_no_duplicates() +test_reversed_words() +test_four_char_strings() + + +""" def main(): return pytest.main(__file__) if __name__ == '__main__': main() - +""" \ No newline at end of file