Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
79 changes: 55 additions & 24 deletions StateCap.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 = {
Expand All @@ -29,7 +32,8 @@
'Hawaii' : 'Honolulu',
'Idaho' : 'Boise',
'Illinois' : 'Springfield',
'Indiana' : 'Indianapolis',
# 'Indiana' : 'Indianapolis',
'Indiana' : 'Boise',
'Iowa' : 'Des Moines',
'Kansas' : 'Topeka',
'Kentucky' : 'Frankfort',
Expand Down Expand Up @@ -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())
"""
Binary file added TestCommitProtection-OK.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions TestCommitProtection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test protection by added file + git commit on Master
60 changes: 60 additions & 0 deletions jenkinsfile
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
46 changes: 40 additions & 6 deletions strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
"""